sequenzialed to complete group creation asap

This commit is contained in:
Marco Lettere 2023-01-12 15:00:03 +01:00
parent 51be38cd57
commit cea8698929
1 changed files with 266 additions and 285 deletions

View File

@ -7,7 +7,7 @@
"ownerEmail" : "marco.lettere@nubisware.com", "ownerEmail" : "marco.lettere@nubisware.com",
"inputParameters" : ["user", "group"], "inputParameters" : ["user", "group"],
"tasks" : [ "tasks" : [
{ {
"name": "LAMBDA_TASK", "name": "LAMBDA_TASK",
"taskReferenceName": "init", "taskReferenceName": "init",
"type": "LAMBDA", "type": "LAMBDA",
@ -225,299 +225,280 @@
"taskReferenceName" : "preliminary_fork_join", "taskReferenceName" : "preliminary_fork_join",
"joinOn": [ "create_permission", "get_rootvo_roles"] "joinOn": [ "create_permission", "get_rootvo_roles"]
}, },
{ {
"name" : "fork_join", "name" : "pyrest",
"taskReferenceName" : "fork_role_creation", "taskReferenceName" : "create_role_member",
"type" : "FORK_JOIN", "type" : "SIMPLE",
"forkTasks" : [ "inputParameters" : {
[{ "url" : "${create_client.output.headers.location}/roles",
"name" : "pyrest", "body" : {
"taskReferenceName" : "create_role_member", "clientRole" : true, "name" : "Member", "description" : "Simple membership for ${init.output.result.name}"
"type" : "SIMPLE", },
"inputParameters" : { "method" : "POST",
"url" : "${create_client.output.headers.location}/roles", "headers" : {
"body" : { "Authorization" : "Bearer ${authorize.output.body.access_token}",
"clientRole" : true, "name" : "Member", "description" : "Simple membership for ${init.output.result.name}" "Content-Type" : "application/json"
}, }
"method" : "POST", }
"headers" : { },
"Authorization" : "Bearer ${authorize.output.body.access_token}", {
"Content-Type" : "application/json" "name" : "pyrest",
} "taskReferenceName" : "get_back_role_member",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${create_role_member.output.headers.location}",
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
"name": "jq_1",
"taskReferenceName": "to_array",
"type": "JSON_JQ_TRANSFORM",
"inputParameters": {
"role": "${get_back_role_member.output.body}",
"queryExpression" : ".role"
}
},
{
"name" : "pyrest",
"taskReferenceName" : "add_role_member_as_component_of_infrastructure_member",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/roles/Infrastructure-Member/composites",
"method" : "POST",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Content-Type" : "application/json"
},
"body" : "${to_array.output.resultList}"
}
},
{
"name" : "pyrest",
"taskReferenceName" : "create_role_policy_member",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients/${extract_client_id.output.result.client_id}/authz/resource-server/policy/role",
"body" : {
"name": "Member_policy",
"description": "",
"type" : "role",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"roles" : [
{
"id" : "${get_back_role_member.output.body.id}",
"required" : true
} }
}, ]
{ },
"name" : "pyrest", "method" : "POST",
"taskReferenceName" : "get_back_role_member", "headers" : {
"type" : "SIMPLE", "Authorization" : "Bearer ${authorize.output.body.access_token}",
"inputParameters" : { "Content-Type" : "application/json",
"url" : "${create_role_member.output.headers.location}", "Accept" : "application/json"
"method" : "GET", }
"headers" : { }
"Authorization" : "Bearer ${authorize.output.body.access_token}", },
"Accept" : "application/json" {
} "name" : "pyrest",
} "taskReferenceName" : "list_kc_groups",
}, "type" : "SIMPLE",
{ "inputParameters" : {
"name": "jq_1", "url" : "${init.input.keycloak_admin}/groups",
"taskReferenceName": "to_array", "method" : "GET",
"type": "JSON_JQ_TRANSFORM", "headers" : {
"inputParameters": { "Authorization" : "Bearer ${authorize.output.body.access_token}",
"role": "${get_back_role_member.output.body}", "Accept" : "application/json"
"queryExpression" : ".role" }
} }
}, },
{ {
"name" : "pyrest", "name": "LAMBDA_TASK",
"taskReferenceName" : "add_role_member_as_component_of_infrastructure_member", "taskReferenceName": "prepare",
"type" : "SIMPLE", "type": "LAMBDA",
"inputParameters" : { "inputParameters": {
"url" : "${init.input.keycloak_admin}/roles/Infrastructure-Member/composites", "append": "${init.output.result.append}",
"method" : "POST", "groups": "${list_kc_groups.output.body}",
"headers" : { "scriptExpression": "function recurse(inp){for(var i=0;i<inp.length;i++){if(inp[i]['path'] === $.append) return inp[i]; else{var subr = recurse(inp[i].subGroups); if(subr != null) return subr;}} return null}; return {'group' : $.append == '' ? '' : recurse($.groups)}"
"Authorization" : "Bearer ${authorize.output.body.access_token}", }
"Content-Type" : "application/json" },
}, {
"body" : "${to_array.output.resultList}" "name": "decide_task",
} "taskReferenceName": "decide1",
}, "inputParameters": {
{ "groupid": "${prepare.output.result.group}"
"name" : "pyrest", },
"taskReferenceName" : "create_role_policy_member", "type": "DECISION",
"type" : "SIMPLE", "caseValueParam": "groupid",
"inputParameters" : { "decisionCases": {
"url" : "${init.input.keycloak_admin}/clients/${extract_client_id.output.result.client_id}/authz/resource-server/policy/role", "": [
"body" : {
"name": "Member_policy",
"description": "",
"type" : "role",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"roles" : [
{
"id" : "${get_back_role_member.output.body.id}",
"required" : true
}
]
},
"method" : "POST",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Content-Type" : "application/json",
"Accept" : "application/json"
}
}
},
{
"name" : "pyrest",
"taskReferenceName" : "list_kc_groups",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/groups",
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{ {
"name": "LAMBDA_TASK", "name": "LAMBDA_TASK",
"taskReferenceName": "prepare", "taskReferenceName": "dummy",
"type": "LAMBDA", "type": "LAMBDA",
"inputParameters": { "inputParameters": {
"append": "${init.output.result.append}", "scriptExpression": "1"
"groups": "${list_kc_groups.output.body}",
"scriptExpression": "function recurse(inp){for(var i=0;i<inp.length;i++){if(inp[i]['path'] === $.append) return inp[i]; else{var subr = recurse(inp[i].subGroups); if(subr != null) return subr;}} return null}; return {'group' : $.append == '' ? '' : recurse($.groups)}"
} }
},
{
"name": "decide_task",
"taskReferenceName": "decide1",
"inputParameters": {
"groupid": "${prepare.output.result.group}"
},
"type": "DECISION",
"caseValueParam": "groupid",
"decisionCases": {
"": [
{
"name": "LAMBDA_TASK",
"taskReferenceName": "dummy",
"type": "LAMBDA",
"inputParameters": {
"scriptExpression": "1"
}
}
]
},
"defaultCase": [
{
"name": "pyrest",
"taskReferenceName": "create_kc_group",
"inputParameters": {
"url": "${init.input.keycloak_admin}/groups/${prepare.output.result.group.id}/children",
"body": {
"name": "${init.output.result.child}"
},
"method": "POST",
"headers": {
"Authorization": "Bearer ${authorize.output.body.access_token}",
"Content-Type": "application/json"
}
},
"type": "SIMPLE"
},
{
"name": "LAMBDA_TASK",
"taskReferenceName": "prepare2",
"inputParameters": {
"location": "${create_kc_group.output.headers.location}",
"client_location": "${create_client.output.headers.location}",
"scriptExpression": "var newid=$.location.split('/').pop(); var client_id = $.client_location.split('/').pop(); return {'newid' : newid, 'client_id' : client_id}"
},
"type": "LAMBDA"
},
{
"name" : "pyrest",
"taskReferenceName" : "assign_client_member_role_to_kc_group",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/groups/${prepare2.output.result.newid}/role-mappings/clients/${prepare2.output.result.client_id}",
"method" : "POST",
"body" : ["${get_back_role_member.output.body}"],
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json",
"Content-Type" : "application/json"
}
}
}
]
} }
],
[
{
"name": "LAMBDA_TASK",
"taskReferenceName": "build_add_role_tasks",
"type": "LAMBDA",
"inputParameters": {
"roles" : "${get_rootvo_roles.output.body[?(@.name != \"uma_protection\" && @.name != \"Member\")]}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.roles.length;i++)r=$.roles[i],k='add-'+r.name,tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'create_'+k}),inputs['create_'+k]={url:'${create_client.output.headers.location}/roles',body:{clientRole:true,name:r.name,description:r.description},method:'POST',headers:{Authorization:'Bearer ${authorize.output.body.access_token}','Content-Type':'application/json'}};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
}
},
{
"name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_add_role",
"inputParameters" : {
"tasks" : "${build_add_role_tasks.output.result.tasks}",
"inputs" : "${build_add_role_tasks.output.result.inputs}"
},
"dynamicForkTasksParam": "tasks",
"dynamicForkTasksInputParamName": "inputs"
},
{
"name" : "join",
"type" : "JOIN",
"taskReferenceName" : "join_parallel_role_addition"
},
{
"name": "LAMBDA_TASK",
"taskReferenceName": "build_get_back_role_tasks",
"type": "LAMBDA",
"inputParameters": {
"roleurls" : "${join_parallel_role_addition.output[*]..location}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.roleurls.length;i++)u=$.roleurls[i],k='add-'+i,tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'get_back_'+k}),inputs['get_back_'+k]={url:u,method:'GET',headers:{Authorization:'Bearer ${authorize.output.body.access_token}',Accept:'application/json'}};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
}
},
{
"name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_get_back_role",
"inputParameters" : {
"tasks" : "${build_get_back_role_tasks.output.result.tasks}",
"inputs" : "${build_get_back_role_tasks.output.result.inputs}"
},
"dynamicForkTasksParam": "tasks",
"dynamicForkTasksInputParamName": "inputs"
},
{
"name" : "join",
"type" : "JOIN",
"taskReferenceName" : "join_parallel_getting_back"
},
{
"name": "LAMBDA_TASK",
"taskReferenceName": "build_add_policy_tasks",
"type": "LAMBDA",
"inputParameters": {
"roles" : "${join_parallel_getting_back.output[*].body}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.roles.length;i++)r=$.roles[i],k='add-'+r.name,tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'create_role_policy_'+k}),inputs['create_role_policy_'+k]={url:'${init.input.keycloak_admin}/clients/${extract_client_id.output.result.client_id}/authz/resource-server/policy/role',body:{name:r.name+'_policy',description:'',type:'role',logic:'POSITIVE',decisionStrategy:'UNANIMOUS',roles:Java.to([{id:r.id,required:true}], 'java.util.Map[]')},method:'POST',headers:{Authorization:'Bearer ${authorize.output.body.access_token}', Accept: 'application/json', 'Content-Type':'application/json'}};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
}
},
{
"name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_add_policy_role",
"inputParameters" : {
"tasks" : "${build_add_policy_tasks.output.result.tasks}",
"inputs" : "${build_add_policy_tasks.output.result.inputs}"
},
"dynamicForkTasksParam": "tasks",
"dynamicForkTasksInputParamName": "inputs"
},
{
"name" : "join",
"type" : "JOIN",
"taskReferenceName" : "join_parallel_policy_addition"
}
]
] ]
}, },
{ "defaultCase": [
"name" : "join", {
"taskReferenceName" : "join_role_creation", "name": "pyrest",
"type" : "JOIN", "taskReferenceName": "create_kc_group",
"joinOn" : [ "inputParameters": {
"join_parallel_policy_addition", "url": "${init.input.keycloak_admin}/groups/${prepare.output.result.group.id}/children",
"decide1" "body": {
] "name": "${init.output.result.child}"
},
"method": "POST",
"headers": {
"Authorization": "Bearer ${authorize.output.body.access_token}",
"Content-Type": "application/json"
}
},
"type": "SIMPLE"
},
{
"name": "LAMBDA_TASK",
"taskReferenceName": "prepare2",
"inputParameters": {
"location": "${create_kc_group.output.headers.location}",
"client_location": "${create_client.output.headers.location}",
"scriptExpression": "var newid=$.location.split('/').pop(); var client_id = $.client_location.split('/').pop(); return {'newid' : newid, 'client_id' : client_id}"
},
"type": "LAMBDA"
},
{
"name" : "pyrest",
"taskReferenceName" : "assign_client_member_role_to_kc_group",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/groups/${prepare2.output.result.newid}/role-mappings/clients/${prepare2.output.result.client_id}",
"method" : "POST",
"body" : ["${get_back_role_member.output.body}"],
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json",
"Content-Type" : "application/json"
}
}
}
]
},
{
"name": "LAMBDA_TASK",
"taskReferenceName": "build_add_role_tasks",
"type": "LAMBDA",
"inputParameters": {
"roles" : "${get_rootvo_roles.output.body[?(@.name != \"uma_protection\" && @.name != \"Member\")]}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.roles.length;i++)r=$.roles[i],k='add-'+r.name,tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'create_'+k}),inputs['create_'+k]={url:'${create_client.output.headers.location}/roles',body:{clientRole:true,name:r.name,description:r.description},method:'POST',headers:{Authorization:'Bearer ${authorize.output.body.access_token}','Content-Type':'application/json'}};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
}
},
{
"name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_add_role",
"inputParameters" : {
"tasks" : "${build_add_role_tasks.output.result.tasks}",
"inputs" : "${build_add_role_tasks.output.result.inputs}"
}, },
{ "dynamicForkTasksParam": "tasks",
"name": "LAMBDA_TASK", "dynamicForkTasksInputParamName": "inputs"
"taskReferenceName": "policy_list", },
"type": "LAMBDA", {
"inputParameters": { "name" : "join",
"memberpolicy" : "${create_role_policy_member.output.body.id}", "type" : "JOIN",
"otherpolicies" : "${join_parallel_policy_addition.output[*].body.id}", "taskReferenceName" : "join_parallel_role_addition"
"scriptExpression": "return Java.to(Java.from($.otherpolicies).concat($.memberpolicy), 'java.lang.String[]')" },
} {
"name": "LAMBDA_TASK",
"taskReferenceName": "build_get_back_role_tasks",
"type": "LAMBDA",
"inputParameters": {
"roleurls" : "${join_parallel_role_addition.output[*]..location}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.roleurls.length;i++)u=$.roleurls[i],k='add-'+i,tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'get_back_'+k}),inputs['get_back_'+k]={url:u,method:'GET',headers:{Authorization:'Bearer ${authorize.output.body.access_token}',Accept:'application/json'}};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
}
},
{
"name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_get_back_role",
"inputParameters" : {
"tasks" : "${build_get_back_role_tasks.output.result.tasks}",
"inputs" : "${build_get_back_role_tasks.output.result.inputs}"
}, },
{ "dynamicForkTasksParam": "tasks",
"name" : "pyrest", "dynamicForkTasksInputParamName": "inputs"
"taskReferenceName" : "finalize_permission", },
"type" : "SIMPLE", {
"inputParameters" : { "name" : "join",
"url" : "${init.input.keycloak_admin}/clients/${extract_client_id.output.result.client_id}/authz/resource-server/permission/resource/${create_permission.output.body.id}", "type" : "JOIN",
"body" : { "taskReferenceName" : "join_parallel_getting_back"
"name": "Default Permission", },
"description": "", {
"type" : "resource", "name": "LAMBDA_TASK",
"logic": "POSITIVE", "taskReferenceName": "build_add_policy_tasks",
"decisionStrategy": "AFFIRMATIVE", "type": "LAMBDA",
"policies" : "${policy_list.output.result}" "inputParameters": {
}, "roles" : "${join_parallel_getting_back.output[*].body}",
"method" : "PUT", "scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.roles.length;i++)r=$.roles[i],k='add-'+r.name,tasks.push({name:'pyrest',type:'SIMPLE',taskReferenceName:'create_role_policy_'+k}),inputs['create_role_policy_'+k]={url:'${init.input.keycloak_admin}/clients/${extract_client_id.output.result.client_id}/authz/resource-server/policy/role',body:{name:r.name+'_policy',description:'',type:'role',logic:'POSITIVE',decisionStrategy:'UNANIMOUS',roles:Java.to([{id:r.id,required:true}], 'java.util.Map[]')},method:'POST',headers:{Authorization:'Bearer ${authorize.output.body.access_token}', Accept: 'application/json', 'Content-Type':'application/json'}};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
"headers" : { }
"Authorization" : "Bearer ${authorize.output.body.access_token}", },
"Content-Type" : "application/json" {
} "name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_add_policy_role",
"inputParameters" : {
"tasks" : "${build_add_policy_tasks.output.result.tasks}",
"inputs" : "${build_add_policy_tasks.output.result.inputs}"
},
"dynamicForkTasksParam": "tasks",
"dynamicForkTasksInputParamName": "inputs"
},
{
"name" : "join",
"type" : "JOIN",
"taskReferenceName" : "join_parallel_policy_addition"
},
{
"name": "LAMBDA_TASK",
"taskReferenceName": "policy_list",
"type": "LAMBDA",
"inputParameters": {
"memberpolicy" : "${create_role_policy_member.output.body.id}",
"otherpolicies" : "${join_parallel_policy_addition.output[*].body.id}",
"scriptExpression": "return Java.to(Java.from($.otherpolicies).concat($.memberpolicy), 'java.lang.String[]')"
} }
}, },
{ {
"name" : "pyrest",
"taskReferenceName" : "finalize_permission",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients/${extract_client_id.output.result.client_id}/authz/resource-server/permission/resource/${create_permission.output.body.id}",
"body" : {
"name": "Default Permission",
"description": "",
"type" : "resource",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"policies" : "${policy_list.output.result}"
},
"method" : "PUT",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Content-Type" : "application/json"
}
}
},
{
"name" : "fork_subworkflows", "name" : "fork_subworkflows",
"type" : "FORK_JOIN", "type" : "FORK_JOIN",
"taskReferenceName" : "parallel_call_subworkflows", "taskReferenceName" : "parallel_call_subworkflows",
@ -549,8 +530,8 @@
} }
] ]
] ]
}, },
{ {
"name" : "join", "name" : "join",
"type" : "JOIN", "type" : "JOIN",
"taskReferenceName" : "join_parallel_call_subworkflows", "taskReferenceName" : "join_parallel_call_subworkflows",
@ -558,6 +539,6 @@
"call_enable_workspace_clients_for_context", "call_enable_workspace_clients_for_context",
"call_jupyterhub_add_serveroptions_to_context" "call_jupyterhub_add_serveroptions_to_context"
] ]
} }
] ]
} }