Flamenco: get JWT token from Flamenco Server when sending files to Shaman

This commit is contained in:
Sybren A. Stüvel 2019-03-13 15:09:24 +01:00
parent 5a61a7a6c4
commit cb0393868e
2 changed files with 32 additions and 1 deletions

View File

@ -567,6 +567,7 @@ class FLAMENCO_OT_render(async_loop.AsyncModalOperatorMixin,
relative_only=relative_only, relative_only=relative_only,
endpoint=endpoint, endpoint=endpoint,
checkout_id=job_id, checkout_id=job_id,
manager_id=prefs.flamenco_manager.manager,
) )
except bat_interface.FileTransferError as ex: except bat_interface.FileTransferError as ex:
self.log.error('Could not transfer %d files, starting with %s', self.log.error('Could not transfer %d files, starting with %s',

View File

@ -6,6 +6,7 @@ import pathlib
import re import re
import threading import threading
import typing import typing
import urllib.parse
import bpy import bpy
from blender_asset_tracer import pack from blender_asset_tracer import pack
@ -19,7 +20,6 @@ _packer_lock = threading.RLock()
# For using in other parts of the add-on, so only this file imports BAT. # For using in other parts of the add-on, so only this file imports BAT.
Aborted = pack.Aborted Aborted = pack.Aborted
FileTransferError = transfer.FileTransferError FileTransferError = transfer.FileTransferError
ShamanPacker = shaman.ShamanPacker
parse_shaman_endpoint = shaman.parse_endpoint parse_shaman_endpoint = shaman.parse_endpoint
@ -95,6 +95,36 @@ class BatProgress(progress.Callback):
pass pass
class ShamanPacker(shaman.ShamanPacker):
"""Packer with support for getting an auth token from Flamenco Server."""
def __init__(self,
bfile: pathlib.Path,
project: pathlib.Path,
target: str,
endpoint: str,
checkout_id: str,
*,
manager_id: str,
**kwargs) -> None:
self.manager_id = manager_id
super().__init__(bfile, project, target, endpoint, checkout_id, **kwargs)
def _get_auth_token(self) -> str:
"""get a token from Flamenco Server"""
from ..blender import PILLAR_SERVER_URL
from ..pillar import blender_id_subclient, uncached_session, SUBCLIENT_ID
url = urllib.parse.urljoin(PILLAR_SERVER_URL,
'flamenco/jwt/generate-token/%s' % self.manager_id)
auth_token = blender_id_subclient()['token']
resp = uncached_session.get(url, auth=(auth_token, SUBCLIENT_ID))
resp.raise_for_status()
return resp.text
async def copy(context, async def copy(context,
base_blendfile: pathlib.Path, base_blendfile: pathlib.Path,
project: pathlib.Path, project: pathlib.Path,