From 900fa993ba63e81d7b82306ee552b6800874999e Mon Sep 17 00:00:00 2001 From: "m.lettere" Date: Fri, 13 Oct 2023 11:24:19 +0200 Subject: [PATCH] modernized all the ghn workflows --- defaults/main.yaml | 20 ++++++++-------- templates/ghn_client_add_to_context.json.j2 | 21 +++++++++-------- templates/ghn_client_add_to_contexts.json.j2 | 20 ++++++++-------- templates/ghn_client_create.json.j2 | 23 +++++++++++-------- templates/ghn_client_delete.json.j2 | 16 +++++++------ .../ghn_client_remove_from_context.json.j2 | 21 +++++++++-------- .../ghn_client_remove_from_contexts.json.j2 | 20 ++++++++-------- 7 files changed, 78 insertions(+), 63 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index ccbd46b..3e14084 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -16,16 +16,16 @@ workflows: # - create_system_service # - delete_system_service # - add_all_system_services_to_vre - - create_workspace_client - - add_workspace_client_to_context - - enable_workspace_clients_for_context - - add_workspace_client_to_contexts - # - ghn_client_add_to_context - # - ghn_client_add_to_contexts - # - ghn_client_create - # - ghn_client_delete - # - ghn_client_remove_from_contexts - # - ghn_client_remove_from_context + # - create_workspace_client + # - add_workspace_client_to_context + # - enable_workspace_clients_for_context + # - add_workspace_client_to_contexts + - ghn_client_add_to_context + - ghn_client_add_to_contexts + - ghn_client_create + - ghn_client_delete + - ghn_client_remove_from_contexts + - ghn_client_remove_from_context # - jupyterhub_add_serveroptions_to_context # - record_context_to_is # - create_vre_folder_for_context diff --git a/templates/ghn_client_add_to_context.json.j2 b/templates/ghn_client_add_to_context.json.j2 index 07e411c..0c27a46 100644 --- a/templates/ghn_client_add_to_context.json.j2 +++ b/templates/ghn_client_add_to_context.json.j2 @@ -8,15 +8,16 @@ "inputParameters" : ["client_id", "context"], "tasks" : [ { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "init", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "id" : "${workflow.input.client_id}", "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_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_context : $.ctx.replaceAll('/', '%2F')}} f()" } }, { @@ -57,12 +58,13 @@ } }, { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "extract_ghn_client", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "client" : "${lookup_client.output.body}", - "scriptExpression": "function e(v){ return (v.length === 0)}; if(e($.client)) throw('GHN 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('GHN client not found'); else return { client : $.client[0], id : $.client[0].id}} f()" } }, { @@ -95,12 +97,13 @@ } }, { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "extract_context", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "client" : "${lookup_context.output.body}", - "scriptExpression": "function e(v){ return (v.length === 0)}; if(e($.client)) throw('Context 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('Context not found'); else return { client : $.client[0], id: $.client[0].id }} f()" } }, { diff --git a/templates/ghn_client_add_to_contexts.json.j2 b/templates/ghn_client_add_to_contexts.json.j2 index 3d6af36..2ccf38b 100644 --- a/templates/ghn_client_add_to_contexts.json.j2 +++ b/templates/ghn_client_add_to_contexts.json.j2 @@ -8,24 +8,26 @@ "inputParameters" : ["client_id", "context_list"], "tasks" : [ { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "init", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { - "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", - "id" : "${workflow.input.client_id}", - "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 { }" + "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", + "id" : "${workflow.input.client_id}", + "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", + "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_ghn_client_to_all_contexts", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "context_list" : "${workflow.input.context_list}", "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_ghn_client_to_context_'+i, subWorkflowParam:{ name:'ghn_client_add_to_context'}}),inputs['add_ghn_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_ghn_client_to_context_'+i, subWorkflowParam:{ name:'ghn_client_add_to_context'}}),inputs['add_ghn_client_to_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f()" } }, { diff --git a/templates/ghn_client_create.json.j2 b/templates/ghn_client_create.json.j2 index c07179b..303c58a 100644 --- a/templates/ghn_client_create.json.j2 +++ b/templates/ghn_client_create.json.j2 @@ -8,9 +8,9 @@ "inputParameters" : ["client_id", "client_secret", "description", "context_list"], "tasks" : [ { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "init", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "root_vo": "{{ root_vo }}", "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", @@ -19,7 +19,8 @@ "id" : "${workflow.input.client_id}", "secret" : "${workflow.input.client_secret}", "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", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { - "client_location" : "${create_client.output.headers.location}", - "scriptExpression": "var client_id = $.client_location.split('/').pop(); return {'client_resource_id' : client_id}" + "client_location" : "${create_client.output.headers.location}", + "evaluatorType" : "javascript", + "expression": "var client_id = $.client_location.split('/').pop(); function f(){return {'client_resource_id' : client_id}} f()" } }, { @@ -147,13 +149,14 @@ } }, { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "build_tasks_to_add_ghn_client_to_all_contexts", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "context_list" : "${workflow.input.context_list}", "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_ghn_client_to_context_'+i, subWorkflowParam:{ name:'ghn_client_add_to_context'}}),inputs['add_ghn_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_ghn_client_to_context_'+i, subWorkflowParam:{ name:'ghn_client_add_to_context'}}),inputs['add_ghn_client_to_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f()" } }, { diff --git a/templates/ghn_client_delete.json.j2 b/templates/ghn_client_delete.json.j2 index 5dcde4b..2ea6002 100644 --- a/templates/ghn_client_delete.json.j2 +++ b/templates/ghn_client_delete.json.j2 @@ -8,14 +8,15 @@ "inputParameters" : ["client_id"], "tasks" : [ { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "init", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "id" : "${workflow.input.client_id}", - "scriptExpression" : "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.id)) throw('Client ID must not be empty');" + "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');} f()" } }, { @@ -50,12 +51,13 @@ } }, { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "check", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { - "list" : "${lookup_client.output.body}", - "scriptExpression" : "if($.list.length === 0 || $.list.length > 1) throw('No client found with client_id or ambiguous query returned multiple clients.')" + "evaluatorType" : "javascript", + "list" : "${lookup_client.output.body}", + "expression" : "if($.list.length === 0 || $.list.length > 1) throw('No client found with client_id or ambiguous query returned multiple clients.')" } }, { diff --git a/templates/ghn_client_remove_from_context.json.j2 b/templates/ghn_client_remove_from_context.json.j2 index b8d27de..317e6f2 100644 --- a/templates/ghn_client_remove_from_context.json.j2 +++ b/templates/ghn_client_remove_from_context.json.j2 @@ -8,15 +8,16 @@ "inputParameters" : ["client_id", "context"], "tasks" : [ { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "init", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", "id" : "${workflow.input.client_id}", "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_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_context : $.ctx.replaceAll('/', '%2F')}} f()" } }, { @@ -57,12 +58,13 @@ } }, { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "extract_ghn_client", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "client" : "${lookup_client.output.body}", - "scriptExpression": "function e(v){ return (v.length === 0)}; if(e($.client)) throw('GHN 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('GHN client not found'); else return { client : $.client[0], id : $.client[0].id}} f()" } }, { @@ -95,12 +97,13 @@ } }, { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "extract_context", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "client" : "${lookup_context.output.body}", - "scriptExpression": "function e(v){ return (v.length === 0)}; if(e($.client)) throw('Context 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('Context not found'); else return { client : $.client[0], id: $.client[0].id }} f()" } }, { diff --git a/templates/ghn_client_remove_from_contexts.json.j2 b/templates/ghn_client_remove_from_contexts.json.j2 index 95b7cda..a84c0d5 100644 --- a/templates/ghn_client_remove_from_contexts.json.j2 +++ b/templates/ghn_client_remove_from_contexts.json.j2 @@ -8,24 +8,26 @@ "inputParameters" : ["client_id", "context_list"], "tasks" : [ { - "name": "LAMBDA_TASK", + "name": "INLINE_TASK", "taskReferenceName": "init", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { - "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", - "id" : "${workflow.input.client_id}", - "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 { }" + "keycloak": "{{ keycloak }}/{{ keycloak_realm }}", + "id" : "${workflow.input.client_id}", + "keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}", + "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", "taskReferenceName": "build_tasks_to_remove_ghn_client_from_all_contexts", - "type": "LAMBDA", + "type": "INLINE", "inputParameters": { "context_list" : "${workflow.input.context_list}", "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:'remove_ghn_client_from_context_'+i, subWorkflowParam:{ name:'ghn_client_remove_from_context'}}),inputs['remove_ghn_client_from_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:'remove_ghn_client_from_context_'+i, subWorkflowParam:{ name:'ghn_client_remove_from_context'}}),inputs['remove_ghn_client_from_context_'+i]={client_id : $.client_id, context: c};return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f()" } }, {