From 2d8c57616027971887a0edd754de15d02840b904 Mon Sep 17 00:00:00 2001 From: "m.lettere" Date: Fri, 22 Jul 2022 14:55:55 +0200 Subject: [PATCH] added scope link to Member role of context --- defaults/main.yaml | 4 +- ...erhub_add_serveroptions_to_context.json.j2 | 70 ++++++++++++++++++- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index 74e799e..f05ae0f 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -4,7 +4,7 @@ workflows: # - group_deleted # - user-group_created # - user-group-role_created - - group_created +# - group_created # - invitation-accepted # - user-group_deleted # - user-group-role_deleted @@ -26,7 +26,7 @@ workflows: # - ghn_client_delete # - ghn_client_remove_from_contexts # - ghn_client_remove_from_context -# - jupyterhub_add_serveroptions_to_context + - jupyterhub_add_serveroptions_to_context keycloak_host: "https://accounts.dev.d4science.org/auth" keycloak: "{{ keycloak_host }}/realms" diff --git a/templates/jupyterhub_add_serveroptions_to_context.json.j2 b/templates/jupyterhub_add_serveroptions_to_context.json.j2 index 4f6045a..eb2acc3 100644 --- a/templates/jupyterhub_add_serveroptions_to_context.json.j2 +++ b/templates/jupyterhub_add_serveroptions_to_context.json.j2 @@ -60,6 +60,46 @@ "decisionCases": {}, "defaultCase": [], "forkTasks": [ + [ + { + "name": "pyrest", + "taskReferenceName": "lookup_client", + "inputParameters": { + "url": "${init.input.keycloak_admin}/clients", + "params": { + "clientId": "${init.output.result.encoded_context}" + }, + "method": "GET", + "headers": { + "Authorization": "Bearer ${authorize.output.body.access_token}", + "Accept": "application/json" + } + }, + "type": "SIMPLE" + }, + { + "name": "pyrest", + "taskReferenceName": "get_client_member_role", + "inputParameters": { + "url": "${init.input.keycloak_admin}/clients/${lookup_client.output.body[0].id}/roles/Member", + "method": "GET", + "headers": { + "Authorization": "Bearer ${authorize.output.body.access_token}", + "Accept": "application/json" + } + }, + "type": "SIMPLE" + }, + { + "name": "jq_1", + "taskReferenceName": "role_to_array", + "type": "JSON_JQ_TRANSFORM", + "inputParameters": { + "role": "${get_client_member_role.output.body}", + "queryExpression" : ".role" + } + } + ], [ { "name": "pyrest", @@ -287,8 +327,34 @@ "name": "join", "taskReferenceName": "join_parallel_tasks", "inputParameters": {}, - "type": "JOIN", - "decisionCases": {}, + "type": "JOIN" + }, + { + "name": "check_at_least_one", + "taskReferenceName": "check_at_least_one", + "inputParameters": { + "tasks": "${join_parallel_tasks.input.*}" + }, + "type": "DECISION", + "caseExpression": "($.tasks.length > 0 ? 'true' : 'false')", + "decisionCases": { + "true": [ + { + "name": "pyrest", + "taskReferenceName": "enable_jupyterhub_scope_for_context", + "inputParameters": { + "url": "${init.input.keycloak_admin}/clients/${lookup_jupyterhub.output.body[0].id}/scope-mappings/clients/${lookup_client.output.body[0].id}", + "method": "POST", + "headers": { + "Authorization": "Bearer ${authorize.output.body.access_token}", + "Content-Type": "application/json" + }, + "body": "${role_to_array.output.resultList}" + }, + "type": "SIMPLE" + } + ] + }, "defaultCase": [], "forkTasks": [], "startDelay": 0,