modernize create-user-add-to-vre

This commit is contained in:
Marco Lettere 2023-10-12 18:00:15 +02:00
parent 4e046ad847
commit 6599eca219
3 changed files with 35 additions and 29 deletions

View File

@ -1,6 +1,6 @@
--- ---
workflows: workflows:
# - create-user-add-to-vre - create-user-add-to-vre
# - group_deleted # - group_deleted
# - user-group_created # - user-group_created
# - user-group-role_created # - user-group-role_created
@ -9,9 +9,9 @@ workflows:
# - user-group_deleted # - user-group_deleted
# - user-group-role_deleted # - user-group-role_deleted
# - delete-user-account # - delete-user-account
- role_deleted # - role_deleted
- role_created # - role_created
- add_role_policy_permission # - add_role_policy_permission
# - add_all_member_roles # - add_all_member_roles
# - create_system_service # - create_system_service
# - delete_system_service # - delete_system_service

View File

@ -15,7 +15,7 @@
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"evaluatorType" : "javascript", "evaluatorType" : "javascript",
"scriptExpression": "1 == 1" "expression": "1 == 1"
} }
}, },
{ {

View File

@ -8,14 +8,15 @@
"inputParameters" : ["user", "first-name", "last-name", "email", "password", "group"], "inputParameters" : ["user", "first-name", "last-name", "email", "password", "group"],
"tasks" : [ "tasks" : [
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "init", "taskReferenceName": "init",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"group" : "${workflow.input.group}", "group" : "${workflow.input.group}",
"scriptExpression": "var path = $.group.split('%2F').slice(1); return { 'tree' : Java.to(path, 'java.lang.Object[]'), 'name' : path.slice(path.length-1)[0]}" "evaluatorType" : "javascript",
"expression": "function f(){var path = $.group.split('%2F').slice(1); return { 'tree' : Java.to(path, 'java.lang.Object[]'), 'name' : path.slice(path.length-1)[0]}} f()"
} }
}, },
{ {
@ -79,15 +80,16 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "select_user", "taskReferenceName": "select_user",
"inputParameters": { "inputParameters": {
"foundusers": "${lookup_user.output.body}", "foundusers": "${lookup_user.output.body}",
"username": "${workflow.input.user}", "username": "${workflow.input.user}",
"scriptExpression": "for(var i=0; i < $.foundusers.length;i++){if($.foundusers[i]['username'] == $.username) return Java.to([$.foundusers[i]], 'java.lang.Object[]')}" "evaluatorType" : "javascript",
}, "scriptExpression": "function f(){for(var i=0; i < $.foundusers.length;i++){if($.foundusers[i]['username'] == $.username) return $.foundusers[i]}} f()"
"type": "LAMBDA" },
}, "type": "INLINE"
},
{ {
"name" : "pyrest", "name" : "pyrest",
"taskReferenceName" : "lookup_client", "taskReferenceName" : "lookup_client",
@ -119,21 +121,23 @@
{ {
"name" : "check_role_existance", "name" : "check_role_existance",
"taskReferenceName" : "check_role_existance", "taskReferenceName" : "check_role_existance",
"type" : "DECISION", "type" : "SWITCH",
"inputParameters" :{ "inputParameters" :{
"previous_outcome" : "${get_client_roles.output.status}" "previous_outcome" : "${get_client_roles.output.status}"
}, },
"caseValueParam" : "previous_outcome", "evaluatorType" : "value-param",
"expression" : "previous_outcome",
"decisionCases" : { "decisionCases" : {
"200" : [ "200" : [
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "select_role", "taskReferenceName": "select_role",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"evaluatorType" : "javascript",
"role": "${workflow.input.role}", "role": "${workflow.input.role}",
"roles" : "${get_client_roles.output.body}", "roles" : "${get_client_roles.output.body}",
"scriptExpression": "for(var i=0; i < $.roles.length;i++){if($.roles[i]['name'] == 'Member') return Java.to([$.roles[i]], 'java.lang.Object[]')}" "expression": "function f(){for(var i=0; i < $.roles.length;i++){if($.roles[i]['name'] == 'Member') return $.roles[i]}} f()"
} }
}, },
{ {
@ -149,24 +153,26 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "extract_groups", "taskReferenceName": "extract_groups",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"evaluatorType" : "javascript",
"tree" : "${init.output.result.tree}", "tree" : "${init.output.result.tree}",
"groups" : "${look_up_groups.output.body}", "groups" : "${look_up_groups.output.body}",
"scriptExpression": "function selectByPath(groups, path, level, acc){ for (var i=0; i < groups.length; i++) {if (groups[i].name === path[level]) {acc.push(groups[i]); if (level === path.length - 1) return acc;return selectByPath(groups[i].subGroups, path, level+1, acc)}} return []; } return { 'groups' : Java.to(selectByPath($.groups, $.tree, 0, []),'java.util.Map[]')}" "expression": "function selectByPath(groups, path, level, acc){ for (var i=0; i < groups.length; i++) {if (groups[i].name === path[level]) {acc.push(groups[i]); if (level === path.length - 1) return acc;return selectByPath(groups[i].subGroups, path, level+1, acc)}} return []; } function f(){ return { 'groups' : Java.to(selectByPath($.groups, $.tree, 0, []),'java.util.Map[]')}} f()"
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "build_add_to_all_groups_tasks", "taskReferenceName": "build_add_to_all_groups_tasks",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"evaluatorType" : "javascript",
"groups" : "${extract_groups.output.result.groups}", "groups" : "${extract_groups.output.result.groups}",
"auth" : "Bearer ${authorize.output.body.access_token}", "auth" : "Bearer ${authorize.output.body.access_token}",
"kc_user_url" : "${init.input.keycloak_admin}/users/${select_user.output.result[0].id}/groups/", "kc_user_url" : "${init.input.keycloak_admin}/users/${select_user.output.result[0].id}/groups/",
"scriptExpression": "inputs={};tasks=[];for(var i=0;i<$.groups.length;i++)group=$.groups[i],tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'user_to_group_'+i}),inputs['user_to_group_'+i]={ url : $.kc_user_url + group.id, method : 'PUT', headers: { Authorization : $.auth} };return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};" "expression": "inputs={};tasks=[];function f(){for(var i=0;i<$.groups.length;i++)group=$.groups[i],tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'user_to_group_'+i}),inputs['user_to_group_'+i]={ url : $.kc_user_url + group.id, method : 'PUT', headers: { Authorization : $.auth} };return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f();"
} }
}, },
{ {