Skip to content

Commit

Permalink
Pass authenticated user to cylc-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
datamel committed Dec 15, 2021
1 parent 0fef3c4 commit d989bbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cylc/uiserver/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def __init__(self, data, log, **kwargs):
# Mutations
async def mutator(self, info, *m_args):
"""Mutate workflow."""
_, w_args, _ = m_args
_, w_args, _, _ = m_args
auth_user = info.context.get('current_user', 'unknown user')
w_ids = [
flow[WORKFLOW].id
for flow in await self.get_workflows_data(w_args)]
Expand All @@ -209,7 +210,7 @@ async def mutator(self, info, *m_args):
'variables': variables,
}
return await self.workflows_mgr.multi_request(
'graphql', w_ids, graphql_args
'graphql', w_ids, graphql_args, auth_user=auth_user
)

async def service(self, info, *m_args):
Expand All @@ -229,6 +230,8 @@ async def nodes_mutator(self, info, *m_args):
if not w_ids:
return [{
'response': (False, 'No matching workflows')}]
auth_user = info.context.get('current_user', 'unknown user')

# Pass the multi-node request to the workflow GraphQL endpoints
_, variables, _, _ = info.context.get('graphql_params')

Expand All @@ -243,5 +246,5 @@ async def nodes_mutator(self, info, *m_args):
}
multi_args = {w_id: graphql_args for w_id in w_ids}
return await self.workflows_mgr.multi_request(
'graphql', w_ids, multi_args=multi_args
'graphql', w_ids, multi_args=multi_args, auth_user=auth_user
)
4 changes: 3 additions & 1 deletion cylc/uiserver/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def __init__(self):
def will_return(self, returns):
self.returns = returns

async def async_request(self, command, args=None, timeout=None):
async def async_request(
self, command, args=None, timeout=None, auth_user=None
):
if (
inspect.isclass(self.returns)
and issubclass(self.returns, Exception)
Expand Down
14 changes: 11 additions & 3 deletions cylc/uiserver/workflows_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async def workflow_request(
req_context=None,
*,
log=None,
auth_user=None
):
"""Workflow request command.
Expand All @@ -70,7 +71,8 @@ async def workflow_request(
if req_context is None:
req_context = command
try:
result = await client.async_request(command, args, timeout)
result = await client.async_request(
command, args, timeout, auth_user=auth_user)
return (req_context, result)
except ClientTimeout as exc:
if log:
Expand Down Expand Up @@ -271,7 +273,8 @@ async def multi_request(
workflows,
args=None,
multi_args=None,
timeout=None
timeout=None,
auth_user=None
):
"""Send requests to multiple workflows."""
if args is None:
Expand All @@ -288,7 +291,12 @@ async def multi_request(
if w_id in self.active
}
gathers = [
workflow_request(req_context=info, *request_args, log=self.log)
workflow_request(
req_context=info,
*request_args,
log=self.log,
auth_user=auth_user
)
for info, request_args in req_args.items()
]
results = await asyncio.gather(*gathers, return_exceptions=True)
Expand Down

0 comments on commit d989bbf

Please sign in to comment.