ansible-role-conductor-work.../templates/create-user-add-to-vre.json.j2

199 lines
6.8 KiB
Plaintext
Raw Normal View History

2020-11-18 19:01:40 +01:00
{
"ownerApp" : "Orchestrator",
"name" : "create-user-add-to-vre",
"createBy" : "Marco Lettere",
"description": "Batch create a user with a membership in a specific group",
"version" : 1,
"ownerEmail" : "m.lettere@gmail.com",
"inputParameters" : ["user", "first-name", "last-name", "email", "password", "group"],
"tasks" : [
{
2023-10-12 18:00:15 +02:00
"name": "INLINE_TASK",
2020-11-18 19:01:40 +01:00
"taskReferenceName": "init",
2023-10-12 18:00:15 +02:00
"type": "INLINE",
2020-11-18 19:01:40 +01:00
"inputParameters": {
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
2023-10-12 18:00:15 +02:00
"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()"
2020-11-18 19:01:40 +01:00
}
},
{
"name" : "pyrest",
"taskReferenceName" : "authorize",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak}/protocol/openid-connect/token",
"method" : "POST",
"headers" : {
"Accept" : "application/json"
},
"body" : {
"client_id" : "orchestrator",
"client_secret" : "{{ keycloak_auth }}",
"grant_type" : "client_credentials"
}
}
},
{
"name" : "pyrest",
"taskReferenceName" : "create_user",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/users",
"expect" : 201,
"method" : "POST",
"body" : {
"username": "${workflow.input.user}",
"firstName": "${workflow.input.first-name}",
"lastName": "${workflow.input.last-name}",
"email": "${workflow.input.email}",
"credentials": [
{
"temporary": true,
"type": "password",
"value": "${workflow.input.password}"
}
],
"requiredActions": ["UPDATE_PASSWORD"],
"emailVerified": true,
"enabled": true
},
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Content-Type" : "application/json"
}
}
},
{
"name" : "pyrest",
"taskReferenceName" : "lookup_user",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/users?username=${workflow.input.user}",
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
2021-02-17 18:08:52 +01:00
{
2023-10-12 18:00:15 +02:00
"name": "INLINE_TASK",
"taskReferenceName": "select_user",
"inputParameters": {
"foundusers": "${lookup_user.output.body}",
"username": "${workflow.input.user}",
"evaluatorType" : "javascript",
2023-10-12 18:07:10 +02:00
"expression": "function f(){for(var i=0; i < $.foundusers.length;i++){if($.foundusers[i]['username'] == $.username) return $.foundusers[i]}} f()"
2023-10-12 18:00:15 +02:00
},
"type": "INLINE"
},
2020-11-18 19:01:40 +01:00
{
"name" : "pyrest",
"taskReferenceName" : "lookup_client",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients",
"params" : { "clientId" : "${workflow.input.group}"},
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
"name" : "pyrest",
"taskReferenceName" : "get_client_roles",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients/${lookup_client.output.body[0].id}/roles",
"expect" : [200, 404],
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
"name" : "check_role_existance",
"taskReferenceName" : "check_role_existance",
2023-10-12 18:00:15 +02:00
"type" : "SWITCH",
2020-11-18 19:01:40 +01:00
"inputParameters" :{
"previous_outcome" : "${get_client_roles.output.status}"
},
2023-10-12 18:00:15 +02:00
"evaluatorType" : "value-param",
"expression" : "previous_outcome",
2020-11-18 19:01:40 +01:00
"decisionCases" : {
"200" : [
{
2023-10-12 18:00:15 +02:00
"name": "INLINE_TASK",
2020-11-18 19:01:40 +01:00
"taskReferenceName": "select_role",
2023-10-12 18:00:15 +02:00
"type": "INLINE",
2020-11-18 19:01:40 +01:00
"inputParameters": {
2023-10-12 18:00:15 +02:00
"evaluatorType" : "javascript",
2020-11-18 19:01:40 +01:00
"role": "${workflow.input.role}",
"roles" : "${get_client_roles.output.body}",
2023-10-12 18:00:15 +02:00
"expression": "function f(){for(var i=0; i < $.roles.length;i++){if($.roles[i]['name'] == 'Member') return $.roles[i]}} f()"
2020-11-18 19:01:40 +01:00
}
},
{
"name" : "pyrest",
"taskReferenceName" : "look_up_groups",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/groups?search=${init.output.result.name}",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
2023-10-12 18:00:15 +02:00
"name": "INLINE_TASK",
"taskReferenceName": "extract_groups",
2023-10-12 18:00:15 +02:00
"type": "INLINE",
2020-11-18 19:01:40 +01:00
"inputParameters": {
2023-10-12 18:00:15 +02:00
"evaluatorType" : "javascript",
2020-11-18 19:01:40 +01:00
"tree" : "${init.output.result.tree}",
"groups" : "${look_up_groups.output.body}",
2023-10-12 18:00:15 +02:00
"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()"
2020-11-18 19:01:40 +01:00
}
},
{
2023-10-12 18:00:15 +02:00
"name": "INLINE_TASK",
"taskReferenceName": "build_add_to_all_groups_tasks",
2023-10-12 18:00:15 +02:00
"type": "INLINE",
"inputParameters": {
2023-10-12 18:00:15 +02:00
"evaluatorType" : "javascript",
"groups" : "${extract_groups.output.result.groups}",
"auth" : "Bearer ${authorize.output.body.access_token}",
2023-10-12 18:10:44 +02:00
"kc_user_url" : "${init.input.keycloak_admin}/users/${select_user.output.result.id}/groups/",
2023-10-12 18:00:15 +02:00
"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();"
2020-11-18 19:01:40 +01:00
}
},
{
"name" : "fork_dynamic",
"type" : "FORK_JOIN_DYNAMIC",
"taskReferenceName" : "parallel_user_to_groups",
"inputParameters" : {
"tasks" : "${build_add_to_all_groups_tasks.output.result.tasks}",
"inputs" : "${build_add_to_all_groups_tasks.output.result.inputs}"
},
"dynamicForkTasksParam": "tasks",
"dynamicForkTasksInputParamName": "inputs"
},
{
"name" : "join",
"type" : "JOIN",
"taskReferenceName" : "join_parallel_user_to_groups"
2020-11-18 19:01:40 +01:00
}
]
}
}
]
}