modernized group_created, group_deleted, jupyterhub_add_resources and enable_workspace_clients_for_context

This commit is contained in:
Marco Lettere 2023-10-12 19:55:46 +02:00
parent d775a774f9
commit 3febc0751b
4 changed files with 37 additions and 29 deletions

View File

@ -18,7 +18,7 @@ workflows:
# - add_all_system_services_to_vre
# - create_workspace_client
# - add_workspace_client_to_context
# - enable_workspace_clients_for_context
- enable_workspace_clients_for_context
# - add_workspace_client_to_contexts
# - ghn_client_add_to_context
# - ghn_client_add_to_contexts
@ -26,7 +26,7 @@ workflows:
# - ghn_client_delete
# - ghn_client_remove_from_contexts
# - ghn_client_remove_from_context
# - jupyterhub_add_serveroptions_to_context
- jupyterhub_add_serveroptions_to_context
# - record_context_to_is
# - create_vre_folder_for_context
# - create_vre

View File

@ -8,15 +8,16 @@
"inputParameters" : ["filter", "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 }}",
"ctx" : "${workflow.input.context}",
"filter" : "${workflow.input.filter}",
"scriptExpression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))} if(e($.ctx)) throw('Context must not be empty'); f=$.filter; if(e(f)) f = []; else if(typeof(f) === 'string') f=[f]; else f=Java.from(f); return { encoded_root_vo : encodeURI($.root_vo), filter : Java.to(f,'java.lang.String[]')}"
"evaluatorType" : "javascript",
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))} function f(){if(e($.ctx)) throw('Context must not be empty'); f=$.filter; if(e(f)) f = []; else if(typeof(f) === 'string') f=[f]; else f=Java.from(f); return { encoded_root_vo : encodeURI($.root_vo), filter : Java.to(f,'java.lang.String[]')}} f()"
}
},
{
@ -59,23 +60,25 @@
}
},
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "filtered_workspace_client_names",
"type": "LAMBDA",
"type": "INLINE",
"inputParameters": {
"evaluatorType" : "javascript",
"names" : "${extract_workspace_client_names.output.result}",
"filter" : "${init.output.result.filter}",
"scriptExpression": "names=Java.from($.names); f=Java.from($.filter); if(f.length === 0) output=names; else { output=[]; for(i=0;i<names.length;i++){ if(f.indexOf(names[i]) !== -1) output.push(names[i])}} return { 'names' : Java.to(output, 'java.lang.String[]')}"
"expression": "names=Java.from($.names); f=Java.from($.filter); function f(){if(f.length === 0) output=names; else { output=[]; for(i=0;i<names.length;i++){ if(f.indexOf(names[i]) !== -1) output.push(names[i])}} return { 'names' : Java.to(output, 'java.lang.String[]')}} f()"
}
},
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "build_add_workspace_client_to_context_tasks",
"type": "LAMBDA",
"type": "INLINE",
"inputParameters": {
"context" : "${workflow.input.context}",
"names" : "${filtered_workspace_client_names.output.result.names}",
"scriptExpression": "inputs={};tasks=[];for(var i=0;i<$.names.length;i++){tasks.push({name:'sub_workflow_task',type:'SUB_WORKFLOW',taskReferenceName:'call_add_ws_client_to_context_'+i, subWorkflowParam:{ name:'add_workspace_client_to_context'}});inputs['call_add_ws_client_to_context_'+i]={client_id:$.names[i], context:$.context}} return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};"
"evaluatorType" : "javascript",
"scriptExpression": "inputs={};tasks=[];function f(){for(var i=0;i<$.names.length;i++){tasks.push({name:'sub_workflow_task',type:'SUB_WORKFLOW',taskReferenceName:'call_add_ws_client_to_context_'+i, subWorkflowParam:{ name:'add_workspace_client_to_context'}});inputs['call_add_ws_client_to_context_'+i]={client_id:$.names[i], context:$.context}} return {tasks:Java.to(tasks,'java.util.Map[]'),inputs:inputs};} f()"
}
},
{

View File

@ -17,7 +17,7 @@
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"group" : "${workflow.input.group}",
"evaluatorType" : "javascript",
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.group)) throw('Group must not be empty'); var tree = $.group.startsWith('%2F') ? $.group.split('%2F') : [$.group]; return { 'tree' : tree, 'child': tree[tree.length-1], 'append' : tree.slice(0,-1).join('/'), 'name' : tree.join('/'), encoded_root_vo : encodeURI($.root_vo)}"
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; function f(){if(e($.group)) throw('Group must not be empty'); var tree = $.group.startsWith('%2F') ? $.group.split('%2F') : [$.group]; return { 'tree' : tree, 'child': tree[tree.length-1], 'append' : tree.slice(0,-1).join('/'), 'name' : tree.join('/'), encoded_root_vo : encodeURI($.root_vo)}} f()"
}
},
{
@ -135,7 +135,7 @@
"taskReferenceName": "prepare",
"type": "INLINE",
"inputParameters": {
"evaluatorType" : "jaascript",
"evaluatorType" : "javascript",
"append": "${init.output.result.append}",
"groups": "${list_kc_groups.output.body}",
"expression": "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}; function f(){return {'group' : $.append == '' ? '' : recurse($.groups)}} f()"
@ -188,7 +188,7 @@
"location": "${create_kc_group.output.headers.location}",
"client_location": "${create_client.output.headers.location}",
"epression": "function f(){var newid=$.location.split('/').pop(); var client_id = $.client_location.split('/').pop(); return {'newid' : newid, 'client_id' : client_id}} f()"
"expression": "function f(){var newid=$.location.split('/').pop(); var client_id = $.client_location.split('/').pop(); return {'newid' : newid, 'client_id' : client_id}} f()"
},
"type": "INLINE"
}
@ -408,7 +408,7 @@
"groupid": "${prepare.output.result.group}"
},
"type": "SWITCH",
"evaluatorType" : "javascript",
"evaluatorType" : "value-param",
"expression": "groupid",
"decisionCases": {
"": [

View File

@ -6,16 +6,17 @@
"version": 1,
"tasks": [
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "init",
"inputParameters": {
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"keycloak_admin": "{{ keycloak_admin }}/{{ keycloak_realm }}",
"ctx": "${workflow.input.context}",
"jupyterhub_clientid" : "jupyterhub-prod",
"scriptExpression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.ctx)) throw('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($.ctx)) throw('Context must not be empty'); else return { encoded_context : $.ctx.replaceAll('/', '%2F')}} f()"
},
"type": "LAMBDA",
"type": "INLINE",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
@ -247,13 +248,14 @@
"loopOver": []
},
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "check",
"inputParameters": {
"evaluatorType" : "javascript",
"param": "ok",
"scriptExpression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; if(e($.param)) throw('Param must not be empty'); else return $.param"
"expression": "function e(v){ return (v == null || (v.trim && v.trim() === ''))}; function(){if(e($.param)) throw('Param must not be empty'); else return $.param} f()"
},
"type": "LAMBDA",
"type": "INLINE",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
@ -265,15 +267,16 @@
"loopOver": []
},
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "filter_and_update",
"inputParameters": {
"evaluatorType" : "javascript",
"allowed": "${extract_authids.output.result}",
"res": "${lookup_jupyterhub_resources.output.body}",
"ctx": "${init.output.result.encoded_context}",
"scriptExpression": "var ret = []; for(var r=0; r < $.res.length; r++){ if($.allowed.indexOf($.res[r].name) !== -1){ $.res[r].attributes[$.ctx] = Java.to(['true'], 'java.lang.String[]'); ret.push($.res[r]) } } return Java.to(ret, 'java.util.Map[]')"
"expression": "var ret = []; function() f(){for(var r=0; r < $.res.length; r++){ if($.allowed.indexOf($.res[r].name) !== -1){ $.res[r].attributes[$.ctx] = Java.to(['true'], 'java.lang.String[]'); ret.push($.res[r]) } } return Java.to(ret, 'java.util.Map[]')} f()"
},
"type": "LAMBDA",
"type": "INLINE",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
@ -285,14 +288,15 @@
"loopOver": []
},
{
"name": "LAMBDA_TASK",
"name": "INLINE_TASK",
"taskReferenceName": "build_parallel_tasks",
"inputParameters": {
"evaluatorType" : "javascript",
"res": "${filter_and_update.output.result}",
"url": "${init.input.keycloak_admin}/clients/${lookup_jupyterhub.output.body[0].id}/authz/resource-server/resource/",
"scriptExpression": "inputs = {}, tasks = [];for (var i = 0; i < $.res.length; i++){s = $.res[i];tasks.push({name: 'pyrest',type: 'SIMPLE',taskReferenceName: 't' + i});inputs['t' + i] = {url: $.url + $.res[i]._id,method: 'PUT', body: $.res[i], headers: {Authorization: 'Bearer ${authorize.output.body.access_token}', 'Content-Type': 'application/json'}}};return {tasks: Java.to(tasks, 'java.util.Map[]'),inputs: inputs};"
"expression": "inputs = {}, tasks = [];function(){for (var i = 0; i < $.res.length; i++){s = $.res[i];tasks.push({name: 'pyrest',type: 'SIMPLE',taskReferenceName: 't' + i});inputs['t' + i] = {url: $.url + $.res[i]._id,method: 'PUT', body: $.res[i], headers: {Authorization: 'Bearer ${authorize.output.body.access_token}', 'Content-Type': 'application/json'}}};return {tasks: Java.to(tasks, 'java.util.Map[]'),inputs: inputs};} f()"
},
"type": "LAMBDA",
"type": "INLINE",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
@ -335,8 +339,9 @@
"inputParameters": {
"tasks": "${join_parallel_tasks.input.*}"
},
"type": "DECISION",
"caseExpression": "($.tasks.length > 0 ? 'true' : 'false')",
"type": "SWITCH",
"evaluatorType" : "javascript",
"expression": "($.tasks.length > 0 ? 'true' : 'false')",
"decisionCases": {
"true": [
{