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:
# - create-user-add-to-vre
- create-user-add-to-vre
# - group_deleted
# - user-group_created
# - user-group-role_created
@ -9,9 +9,9 @@ workflows:
# - user-group_deleted
# - user-group-role_deleted
# - delete-user-account
- role_deleted
- role_created
- add_role_policy_permission
# - role_deleted
# - role_created
# - add_role_policy_permission
# - add_all_member_roles
# - create_system_service
# - delete_system_service

View File

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

View File

@ -8,14 +8,15 @@
"inputParameters" : ["user", "first-name", "last-name", "email", "password", "group"],
"tasks" : [
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "init",
"type": "LAMBDA",
"type": "INLINE",
"inputParameters": {
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"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]}"
"group" : "${workflow.input.group}",
"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",
"taskReferenceName": "select_user",
"inputParameters": {
"foundusers": "${lookup_user.output.body}",
"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[]')}"
},
"type": "LAMBDA"
},
"name": "INLINE_TASK",
"taskReferenceName": "select_user",
"inputParameters": {
"foundusers": "${lookup_user.output.body}",
"username": "${workflow.input.user}",
"evaluatorType" : "javascript",
"scriptExpression": "function f(){for(var i=0; i < $.foundusers.length;i++){if($.foundusers[i]['username'] == $.username) return $.foundusers[i]}} f()"
},
"type": "INLINE"
},
{
"name" : "pyrest",
"taskReferenceName" : "lookup_client",
@ -119,21 +121,23 @@
{
"name" : "check_role_existance",
"taskReferenceName" : "check_role_existance",
"type" : "DECISION",
"type" : "SWITCH",
"inputParameters" :{
"previous_outcome" : "${get_client_roles.output.status}"
},
"caseValueParam" : "previous_outcome",
"evaluatorType" : "value-param",
"expression" : "previous_outcome",
"decisionCases" : {
"200" : [
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "select_role",
"type": "LAMBDA",
"type": "INLINE",
"inputParameters": {
"evaluatorType" : "javascript",
"role": "${workflow.input.role}",
"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",
"type": "LAMBDA",
"type": "INLINE",
"inputParameters": {
"evaluatorType" : "javascript",
"tree" : "${init.output.result.tree}",
"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",
"type": "LAMBDA",
"type": "INLINE",
"inputParameters": {
"evaluatorType" : "javascript",
"groups" : "${extract_groups.output.result.groups}",
"auth" : "Bearer ${authorize.output.body.access_token}",
"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();"
}
},
{