modernized create_workspace_client and add_workspace_clients_tocontext

This commit is contained in:
Marco Lettere 2023-10-13 10:26:34 +02:00
parent e0028de1f0
commit ab1010c417
4 changed files with 50 additions and 40 deletions

View File

@ -13,13 +13,13 @@ workflows:
# - 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
- add_all_system_services_to_vre # - add_all_system_services_to_vre
# - create_workspace_client - create_workspace_client
# - add_workspace_client_to_context - add_workspace_client_to_context
# - enable_workspace_clients_for_context - enable_workspace_clients_for_context
# - add_workspace_client_to_contexts - add_workspace_client_to_contexts
# - ghn_client_add_to_context # - ghn_client_add_to_context
# - ghn_client_add_to_contexts # - ghn_client_add_to_contexts
# - ghn_client_create # - ghn_client_create

View File

@ -8,9 +8,9 @@
"inputParameters" : ["client_id", "context"], "inputParameters" : ["client_id", "context"],
"tasks" : [ "tasks" : [
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "init", "taskReferenceName": "init",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"root_vo": "{{ root_vo }}", "root_vo": "{{ root_vo }}",
"storagehub" : "{{ storagehub }}", "storagehub" : "{{ storagehub }}",
@ -18,7 +18,8 @@
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"id" : "${workflow.input.client_id}", "id" : "${workflow.input.client_id}",
"ctx" : "${workflow.input.context}", "ctx" : "${workflow.input.context}",
"scriptExpression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.id) || e($.ctx)) throw('Client ID and Context must not be empty'); else return { encoded_root_vo : encodeURI($.root_vo), encoded_context : $.ctx.replaceAll('/', '%2F')}" "evaluatorType": "javascript",
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; function f(){if(e($.id) || e($.ctx)) throw('Client ID and Context must not be empty'); else return { encoded_root_vo : encodeURI($.root_vo), encoded_context : $.ctx.replaceAll('/', '%2F')}} f()"
} }
}, },
{ {
@ -59,12 +60,13 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "extract_ws_client", "taskReferenceName": "extract_ws_client",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"client" : "${lookup_client.output.body}", "client" : "${lookup_client.output.body}",
"scriptExpression": "function e(v){ return (v.length === 0)}; if(e($.client)) throw('Workspace client not found'); else return { client : $.client[0], id : $.client[0].id}" "evaluatorType" : "javascript",
"expression": "function e(v){ return (v.length === 0)}; function f(){if(e($.client)) throw('Workspace client not found'); else return { client : $.client[0], id : $.client[0].id}} f()"
} }
}, },
{ {
@ -97,12 +99,13 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "extract_context", "taskReferenceName": "extract_context",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"client" : "${lookup_context.output.body}", "client" : "${lookup_context.output.body}",
"scriptExpression": "function e(v){ return (v.length === 0)}; if(e($.client)) throw('Workspace client not found'); else return { client : $.client[0], id: $.client[0].id }" "evaluatorType" : "javascript",
"expression": "function e(v){ return (v.length === 0)}; function f(){if(e($.client)) throw('Workspace client not found'); else return { client : $.client[0], id: $.client[0].id }} f()"
} }
}, },
{ {
@ -128,12 +131,13 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "shubify_context_name", "taskReferenceName": "shubify_context_name",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"context_name" : "${extract_context.output.result.client.name}", "context_name" : "${extract_context.output.result.client.name}",
"scriptExpression": "var s = $.context_name; return { shubified_context_name : (s[0] === '/' ? s.replace('/', '') : s).split('/').join('-')}" "evaluatorType" : "javascript",
"expression": "var s = $.context_name; function f(){return { shubified_context_name : (s[0] === '/' ? s.replace('/', '') : s).split('/').join('-')}} f()"
} }
} }
] ]

View File

@ -8,25 +8,27 @@
"inputParameters" : ["client_id", "context_list"], "inputParameters" : ["client_id", "context_list"],
"tasks" : [ "tasks" : [
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "init", "taskReferenceName": "init",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"root_vo": "{{ root_vo }}", "root_vo": "{{ root_vo }}",
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"id" : "${workflow.input.client_id}", "id" : "${workflow.input.client_id}",
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"scriptExpression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.id)) throw('Client ID must not be empty'); return { }" "evaluatorType" : "javascript",
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; function f(){if(e($.id)) throw('Client ID must not be empty'); return { }} f()"
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "build_tasks_to_add_ws_client_to_all_contexts", "taskReferenceName": "build_tasks_to_add_ws_client_to_all_contexts",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"context_list" : "${workflow.input.context_list}", "context_list" : "${workflow.input.context_list}",
"client_id" : "${workflow.input.client_id}", "client_id" : "${workflow.input.client_id}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.context_list.length;i++)c=$.context_list[i],tasks.push({name:'sub_workflow_task',type:'SUB_WORKFLOW',taskReferenceName:'add_workspace_client_to_context_'+i, subWorkflowParam:{ name:'add_workspace_client_to_context'}}),inputs['add_workspace_client_to_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};" "evaluatorType" : "javascript",
"expression": "inputs={},tasks=[];functionf(){for(var i=0;i<$.context_list.length;i++)c=$.context_list[i],tasks.push({name:'sub_workflow_task',type:'SUB_WORKFLOW',taskReferenceName:'add_workspace_client_to_context_'+i, subWorkflowParam:{ name:'add_workspace_client_to_context'}}),inputs['add_workspace_client_to_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f()"
} }
}, },
{ {

View File

@ -8,9 +8,9 @@
"inputParameters" : ["client_id", "client_secret", "description", "context_list"], "inputParameters" : ["client_id", "client_secret", "description", "context_list"],
"tasks" : [ "tasks" : [
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "init", "taskReferenceName": "init",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"root_vo": "{{ root_vo }}", "root_vo": "{{ root_vo }}",
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
@ -19,7 +19,8 @@
"id" : "${workflow.input.client_id}", "id" : "${workflow.input.client_id}",
"secret" : "${workflow.input.client_secret}", "secret" : "${workflow.input.client_secret}",
"description" : "${workflow.input.description}", "description" : "${workflow.input.description}",
"scriptExpression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.id)) throw('Client ID must not be empty'); return { encoded_root_vo : encodeURI($.root_vo), client : { clientId : $.id, description : ($.description ? $.description : $.id), secret : ($.secret ? $.secret : Java.type('java.util.UUID').randomUUID().toString()), rootUrl : '', enabled : true, serviceAccountsEnabled : true, standardFlowEnabled : true, authorizationServicesEnabled : false, publicClient : false, fullScopeAllowed : true, protocol : 'openid-connect'} }" "evaluatorType" : "javascript",
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; function f(){if(e($.id)) throw('Client ID must not be empty'); return { encoded_root_vo : encodeURI($.root_vo), client : { clientId : $.id, description : ($.description ? $.description : $.id), secret : ($.secret ? $.secret : Java.type('java.util.UUID').randomUUID().toString()), rootUrl : '', enabled : true, serviceAccountsEnabled : true, standardFlowEnabled : true, authorizationServicesEnabled : false, publicClient : false, fullScopeAllowed : true, protocol : 'openid-connect'}}} f()"
} }
}, },
{ {
@ -60,12 +61,13 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "extract_client_id", "taskReferenceName": "extract_client_id",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"client_location" : "${create_client.output.headers.location}", "client_location" : "${create_client.output.headers.location}",
"scriptExpression": "var client_id = $.client_location.split('/').pop(); return {'client_resource_id' : client_id}" "evaluatorType" :"javascript",
"expression": "var client_id = $.client_location.split('/').pop(); function f(){return {'client_resource_id' : client_id}} f()"
} }
}, },
{ {
@ -184,8 +186,9 @@
"inputParameters": { "inputParameters": {
"status": "${check_workspace.output.status}" "status": "${check_workspace.output.status}"
}, },
"type": "DECISION", "type": "SWITCH",
"caseExpression": "($.status === 406 ? 'create' : 'exists')", "evaluatorType" : "javascript",
"expression": "($.status === 406 ? 'create' : 'exists')",
"decisionCases": { "decisionCases": {
"create": [ "create": [
{ {
@ -225,13 +228,14 @@
} }
}, },
{ {
"name": "LAMBDA_TASK", "name": "INLINE_TASK",
"taskReferenceName": "build_tasks_to_add_ws_client_to_all_contexts", "taskReferenceName": "build_tasks_to_add_ws_client_to_all_contexts",
"type": "LAMBDA", "type": "INLINE",
"inputParameters": { "inputParameters": {
"context_list" : "${workflow.input.context_list}", "context_list" : "${workflow.input.context_list}",
"client_id" : "${workflow.input.client_id}", "client_id" : "${workflow.input.client_id}",
"scriptExpression": "inputs={},tasks=[];for(var i=0;i<$.context_list.length;i++)c=$.context_list[i],tasks.push({name:'sub_workflow_task',type:'SUB_WORKFLOW',taskReferenceName:'add_workspace_client_to_context_'+i, subWorkflowParam:{ name:'add_workspace_client_to_context'}}),inputs['add_workspace_client_to_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};" "evaluatorType" : "javascript",
"expression": "inputs={},tasks=[];function f(){for(var i=0;i<$.context_list.length;i++)c=$.context_list[i],tasks.push({name:'sub_workflow_task',type:'SUB_WORKFLOW',taskReferenceName:'add_workspace_client_to_context_'+i, subWorkflowParam:{ name:'add_workspace_client_to_context'}}),inputs['add_workspace_client_to_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f()"
} }
}, },
{ {