From 436dd86b4ff05dc046de9cc21f36d5a65a0282fc Mon Sep 17 00:00:00 2001 From: Mel Hall <37735232+datamel@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:54:41 +0000 Subject: [PATCH] Add req-meta --- cylc/uiserver/resolvers.py | 6 ++++-- cylc/uiserver/workflows_mgr.py | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cylc/uiserver/resolvers.py b/cylc/uiserver/resolvers.py index 9a145c44..013f5bfc 100644 --- a/cylc/uiserver/resolvers.py +++ b/cylc/uiserver/resolvers.py @@ -189,8 +189,10 @@ def __init__(self, data, log, **kwargs): # Mutations async def mutator(self, info, *m_args): """Mutate workflow.""" + req_meta = {} _, w_args, _, _ = m_args - auth_user = info.context.get('current_user', 'unknown user') + req_meta['auth_user'] = info.context.get( + 'current_user', 'unknown user') w_ids = [ flow[WORKFLOW].id for flow in await self.get_workflows_data(w_args)] @@ -210,7 +212,7 @@ async def mutator(self, info, *m_args): 'variables': variables, } return await self.workflows_mgr.multi_request( - 'graphql', w_ids, graphql_args, auth_user=auth_user + 'graphql', w_ids, graphql_args, req_meta=req_meta ) async def service(self, info, *m_args): diff --git a/cylc/uiserver/workflows_mgr.py b/cylc/uiserver/workflows_mgr.py index de2823b8..59adaf3c 100644 --- a/cylc/uiserver/workflows_mgr.py +++ b/cylc/uiserver/workflows_mgr.py @@ -53,7 +53,7 @@ async def workflow_request( req_context=None, *, log=None, - auth_user=None + req_meta=None ): """Workflow request command. @@ -63,6 +63,7 @@ async def workflow_request( args (dict): Endpoint arguments. timeout (float): Client request timeout (secs). req_context (str): A string to identifier. + req_meta (dict): Meta data related to request, e.g. auth_user Returns: tuple: (req_context, result) @@ -72,7 +73,7 @@ async def workflow_request( req_context = command try: result = await client.async_request( - command, args, timeout, auth_user=auth_user) + command, args, timeout, req_meta=req_meta) return (req_context, result) except ClientTimeout as exc: if log: @@ -274,13 +275,15 @@ async def multi_request( args=None, multi_args=None, timeout=None, - auth_user=None + req_meta=None ): """Send requests to multiple workflows.""" if args is None: args = {} if multi_args is None: multi_args = {} + if req_meta is None: + req_meta = {} req_args = { w_id: ( self.active[w_id]['req_client'], @@ -295,7 +298,7 @@ async def multi_request( req_context=info, *request_args, log=self.log, - auth_user=auth_user + req_meta=req_meta ) for info, request_args in req_args.items() ]