ansible-role-conductor-work.../templates/ghn_client_add_to_context.j...

160 lines
5.0 KiB
Plaintext
Raw Normal View History

2022-03-17 12:53:50 +01:00
{
"ownerApp" : "Orchestrator",
"name" : "ghn_client_add_to_context",
"createBy" : "Marco Lettere",
"description": "A GHN client is made Member of a context and it's workspace folder is linked to context's shared folder",
"version" : 1,
"ownerEmail" : "marco.lettere@nubisware.com",
"inputParameters" : ["client_id", "context"],
"tasks" : [
{
2023-10-13 11:24:19 +02:00
"name": "INLINE_TASK",
2022-03-17 12:53:50 +01:00
"taskReferenceName": "init",
2023-10-13 11:24:19 +02:00
"type": "INLINE",
2022-03-17 12:53:50 +01:00
"inputParameters": {
"keycloak": "{{ keycloak }}/{{ keycloak_realm }}",
"keycloak_admin" : "{{ keycloak_admin }}/{{ keycloak_realm }}",
"id" : "${workflow.input.client_id}",
"ctx" : "${workflow.input.context}",
2023-10-13 11:24:19 +02:00
"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()"
2022-03-17 12:53:50 +01:00
}
},
{
"name" : "pyrest",
"taskReferenceName" : "authorize",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "{{ keycloak }}/master/protocol/openid-connect/token",
"method" : "POST",
"headers" : {
"Accept" : "application/json"
},
"body" : {
"client_id" : "orchestrator",
"client_secret" : "{{ keycloak_auth_master }}",
"grant_type" : "client_credentials"
}
}
},
{
"name" : "fork_join",
"taskReferenceName" : "fork1",
"type" : "FORK_JOIN",
"forkTasks" : [
[
{
"name" : "pyrest",
"taskReferenceName" : "lookup_client",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients",
"params" : { "clientId" : "${workflow.input.client_id}"},
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
2023-10-13 11:24:19 +02:00
"name": "INLINE_TASK",
2022-03-17 12:53:50 +01:00
"taskReferenceName": "extract_ghn_client",
2023-10-13 11:24:19 +02:00
"type": "INLINE",
2022-03-17 12:53:50 +01:00
"inputParameters": {
"client" : "${lookup_client.output.body}",
2023-10-13 11:24:19 +02:00
"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()"
2022-03-17 12:53:50 +01:00
}
},
{
"name" : "pyrest",
"taskReferenceName" : "get_service_account_user",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients/${extract_ghn_client.output.result.id}/service-account-user",
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
}
],
[
{
"name" : "pyrest",
"taskReferenceName" : "lookup_context",
"type" : "SIMPLE",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients",
"params" : { "clientId" : "${init.output.result.encoded_context}"},
"method" : "GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
2023-10-13 11:24:19 +02:00
"name": "INLINE_TASK",
2022-03-17 12:53:50 +01:00
"taskReferenceName": "extract_context",
2023-10-13 11:24:19 +02:00
"type": "INLINE",
2022-03-17 12:53:50 +01:00
"inputParameters": {
"client" : "${lookup_context.output.body}",
2023-10-13 11:24:19 +02:00
"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()"
2022-03-17 12:53:50 +01:00
}
},
{
"name" : "pyrest",
"type" : "SIMPLE",
"taskReferenceName": "retrieve_member_role",
"inputParameters" : {
"url" : "${init.input.keycloak_admin}/clients/${extract_context.output.result.id}/roles/Member",
"method" :"GET",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Accept" : "application/json"
}
}
},
{
"name": "jq_1",
"taskReferenceName": "roles_to_assign",
"type": "JSON_JQ_TRANSFORM",
"inputParameters": {
"role": "${retrieve_member_role.output.body}",
"queryExpression" : ".role"
}
}
]
]
},
{
"name": "join",
"taskReferenceName": "join1",
"type": "JOIN",
"joinOn": [
2022-03-17 13:45:46 +01:00
"get_service_account_user",
"roles_to_assign"
2022-03-17 12:53:50 +01:00
]
},
{
"name" : "pyrest",
"type" : "SIMPLE",
"taskReferenceName": "assign_member_role",
"inputParameters" : {
2022-03-17 12:57:59 +01:00
"url" : "${init.input.keycloak_admin}/users/${get_service_account_user.output.body.id}/role-mappings/clients/${retrieve_member_role.output.body.containerId}",
2022-03-17 12:53:50 +01:00
"method" :"POST",
"headers" : {
"Authorization" : "Bearer ${authorize.output.body.access_token}",
"Content-Type" : "application/json",
"Accept":"application/json"
},
"body" : "${roles_to_assign.output.resultList}"
}
}
]
}