fix(matrix-uia-login): pick correct stage when multiple stages are available.

ref: https://gitlab.com/famedly/company/devops/collections/matrix/-/issues/18
This commit is contained in:
Jadyn Emma Jaeger 2022-01-19 13:32:29 +01:00
parent 4c15534323
commit 14752e23c7
No known key found for this signature in database
GPG key ID: 632410170049FDDA

View file

@ -111,15 +111,7 @@ uia_stages = {
def pick_flow(flows): def pick_flow(flows):
supported_stages = uia_stages.keys() supported_stages = uia_stages.keys()
# reduces each flow to a boolean telling filter if the flow consists only out of compatible stages # reduces each flow to a boolean telling filter if the flow consists only out of compatible stages
compatible_flows = list( compatible_flows = [flow for flow in flows if all([stage in supported_stages for stage in flow['stages']])]
filter(
lambda flow: reduce(
(lambda compatible, stage: compatible and (stage in supported_stages)),
flow['stages']
),
flows
)
)
# the best flow is the one with the fewest stages, key= takes a function telling min() the weight of an entry # the best flow is the one with the fewest stages, key= takes a function telling min() the weight of an entry
best = min(compatible_flows, key=(lambda flow: len(flow['stages']))) best = min(compatible_flows, key=(lambda flow: len(flow['stages'])))
return best return best
@ -160,6 +152,7 @@ async def run_module():
log.append("DEBUG: begin UIA for session=" + uia_session) log.append("DEBUG: begin UIA for session=" + uia_session)
# Figure out best compatible UIA login flow # Figure out best compatible UIA login flow
log.append("INFO: available flows: " + str(res['flows']))
flow_to_attempt = pick_flow(res['flows']) flow_to_attempt = pick_flow(res['flows'])
log.append("INFO: picking flow: " + (" -> ".join(flow_to_attempt['stages']))) log.append("INFO: picking flow: " + (" -> ".join(flow_to_attempt['stages'])))