Last active
April 14, 2021 13:42
-
-
Save lbrenman/48f5ec43c2e42dbbf49960645c5bfc8a to your computer and use it in GitHub Desktop.
AMPLIFY Central New API Approval (Assets)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 49957, | |
"name": "AMPLIFY Central New API Approval Processor 2", | |
"description": "", | |
"debugLoggingExpires": "2021-04-14T03:11:13Z", | |
"userId": 21107, | |
"accountId": 18281, | |
"createdDate": "2021-04-13T18:53:47Z", | |
"steps": [{ | |
"id": 513425, | |
"onSuccess": [], | |
"onFailure": [], | |
"name": "addCommentToIncident", | |
"type": "elementRequest", | |
"properties": { | |
"body": "${steps.prepareAddCommentToIncident.body}", | |
"api": "/${steps.prepareAddCommentToIncident.url}", | |
"method": "POST", | |
"elementInstanceId": "${config.jira}" | |
} | |
}, { | |
"id": 513423, | |
"onSuccess": ["prepareAddCommentToIncident"], | |
"onFailure": [], | |
"name": "consumerInstancePublish", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepareConsumerInstancePublish.body}", | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"url": "${steps.prepareGetConsumerInstance.url}", | |
"method": "PUT" | |
} | |
}, { | |
"id": 513402, | |
"onSuccess": ["getFieldNames"], | |
"onFailure": [], | |
"name": "defineUtils", | |
"type": "script", | |
"properties": { | |
"body": "function findObjectByKey(array, key, value){\n for (var i = 0; i < array.length; i++) {\n if (array[i][key] === value) {\n return array[i];\n }\n }\n return null;\n}\n\nlet utils = {\n findObjectByKey: findObjectByKey\n}\n\ndone({utils});" | |
} | |
}, { | |
"id": 513403, | |
"onSuccess": ["setGlobals"], | |
"onFailure": [], | |
"name": "getAxwayAccessToken", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepAxwayAccessTokenRequest.form}", | |
"headers": "${steps.prepAxwayAccessTokenRequest.headers}", | |
"url": "https://login.axway.com/auth/realms/Broker/protocol/openid-connect/token", | |
"method": "POST" | |
} | |
}, { | |
"id": 513416, | |
"onSuccess": ["prepareConsumerInstancePublish"], | |
"onFailure": [], | |
"name": "getConsumerInstance", | |
"type": "httpRequest", | |
"properties": { | |
"url": "${steps.prepareGetConsumerInstance.url}", | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"method": "GET" | |
} | |
}, { | |
"id": 513404, | |
"onSuccess": ["shouldProcess"], | |
"onFailure": [], | |
"name": "getFieldNames", | |
"type": "elementRequest", | |
"properties": { | |
"api": "/fields", | |
"method": "GET", | |
"elementInstanceId": "${config.jira}" | |
} | |
}, { | |
"id": 513424, | |
"onSuccess": ["addCommentToIncident"], | |
"onFailure": [], | |
"name": "prepareAddCommentToIncident", | |
"type": "script", | |
"properties": { | |
"body": "let url = 'incidents/'+trigger.body.message.raw.issue.key+'/comments';\n\nlet body = {\n \"body\": \"API Published by the approval flow.\"\n}\n\ndone({url:url, body:body});" | |
} | |
}, { | |
"id": 513422, | |
"onSuccess": ["consumerInstancePublish"], | |
"onFailure": [], | |
"name": "prepareConsumerInstancePublish", | |
"type": "script", | |
"properties": { | |
"body": "let body = steps.getConsumerInstance.response.body;\n\nbody.spec.state = 'PUBLISHED'\n\ndone({body:body})" | |
} | |
}, { | |
"id": 513415, | |
"onSuccess": ["getConsumerInstance"], | |
"onFailure": [], | |
"name": "prepareGetConsumerInstance", | |
"type": "script", | |
"properties": { | |
"body": "let consumerInstanceUrlField = steps.defineUtils.utils.findObjectByKey(steps.getFieldNames.response.body, 'name', config.consumerInstanceJiraCustomFieldName).key;\n\nlet url = trigger.body.message.raw.issue.fields[consumerInstanceUrlField]\n\ndone({url:url})" | |
} | |
}, { | |
"id": 513408, | |
"onSuccess": ["getAxwayAccessToken"], | |
"onFailure": [], | |
"name": "prepAxwayAccessTokenRequest", | |
"type": "script", | |
"properties": { | |
"body": "\ndone({\n 'headers': { \n Authorization: 'Basic ' + CE.b64(config.axwayClientId + ':' + config.axwayClientSecret),\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n form: 'grant_type=client_credentials'\n});\n" | |
} | |
}, { | |
"id": 513401, | |
"onSuccess": ["shouldApprove"], | |
"onFailure": [], | |
"name": "setGlobals", | |
"type": "script", | |
"properties": { | |
"body": "let apiServerHeaders = {\n 'Authorization': `Bearer ${steps.getAxwayAccessToken.response.body.access_token}`,\n 'Content-Type': 'application/json'\n}\n\nlet apicentralUrl = config.apiCentralUrl ? config.apiCentralUrl : 'https://apicentral.axway.com';\n\nlet globals = {\n apicentralUrl: apicentralUrl,\n apiServerHeaders: apiServerHeaders\n}\n\ndone({globals});" | |
} | |
}, { | |
"id": 513413, | |
"onSuccess": ["prepareGetConsumerInstance"], | |
"onFailure": [], | |
"name": "shouldApprove", | |
"type": "filter", | |
"properties": { | |
"body": "let approveRejectField = steps.defineUtils.utils.findObjectByKey(steps.getFieldNames.response.body, 'name', config.approveRejectJiraCustomFieldName).key;\n\ndone(trigger.body.message.raw.issue.fields[approveRejectField].value === config.approveRejectJiraCustomFieldApproveValue);" | |
} | |
}, { | |
"id": 513409, | |
"onSuccess": ["prepAxwayAccessTokenRequest"], | |
"onFailure": [], | |
"name": "shouldProcess", | |
"type": "filter", | |
"properties": { | |
"body": "let approveRejectField = steps.defineUtils.utils.findObjectByKey(steps.getFieldNames.response.body, 'name', config.approveRejectJiraCustomFieldName).key;\n\nlet projectKey = trigger.body.message.raw.issue.fields.project.key;\n\ndone((projectKey === config.jiraProjectKey) && (trigger.body.message.raw.issue.fields.status.name === 'Done') && trigger.body.message.raw.issue.fields[approveRejectField].hasOwnProperty('value'));" | |
} | |
}], | |
"triggers": [{ | |
"id": 44254, | |
"onSuccess": ["defineUtils"], | |
"onFailure": [], | |
"type": "event", | |
"async": true, | |
"active": true, | |
"name": "trigger", | |
"properties": { | |
"elementInstanceId": "${config.jira}" | |
} | |
}], | |
"engine": "v3", | |
"active": true, | |
"debugLoggingEnabled": false, | |
"singleThreaded": false, | |
"configuration": [{ | |
"id": 90480, | |
"key": "apiCentralUrl", | |
"name": "apiCentralUrl", | |
"type": "value", | |
"required": false | |
}, { | |
"id": 90482, | |
"key": "approveRejectJiraCustomFieldApproveValue", | |
"name": "approveRejectJiraCustomFieldApproveValue", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90483, | |
"key": "approveRejectJiraCustomFieldName", | |
"name": "approveRejectJiraCustomFieldName", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90484, | |
"key": "approveRejectJiraCustomFieldRejectValue", | |
"name": "approveRejectJiraCustomFieldRejectValue", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90485, | |
"key": "axwayClientId", | |
"name": "axwayClientId", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90486, | |
"key": "axwayClientSecret", | |
"name": "axwayClientSecret", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90487, | |
"key": "consumerInstanceJiraCustomFieldName", | |
"name": "consumerInstanceJiraCustomFieldName", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90488, | |
"key": "jira", | |
"name": "jira", | |
"type": "elementInstance", | |
"required": true | |
}, { | |
"id": 90489, | |
"key": "jiraProjectKey", | |
"name": "jiraProjectKey", | |
"type": "value", | |
"required": true | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 49540, | |
"name": "AMPLIFY Central New API Approval Processor", | |
"debugLoggingExpires": "2021-04-14T05:29:00Z", | |
"userId": 21107, | |
"accountId": 18281, | |
"createdDate": "2021-04-09T13:46:24Z", | |
"steps": [{ | |
"id": 513395, | |
"onSuccess": ["prepareSendToTeams"], | |
"onFailure": [], | |
"name": "createIncident", | |
"type": "elementRequest", | |
"properties": { | |
"body": "${steps.prepareCreateIncident.body}", | |
"api": "/incidents", | |
"elementInstanceId": "${config.jira}", | |
"method": "POST" | |
} | |
}, { | |
"id": 513392, | |
"onSuccess": ["prepAxwayAccessTokenRequest"], | |
"onFailure": [], | |
"name": "defineUtils", | |
"type": "script", | |
"properties": { | |
"body": "function findObjectByKey(array, key, value){\n for (var i = 0; i < array.length; i++) {\n if (array[i][key] === value) {\n return array[i];\n }\n }\n return null;\n}\n\nlet utils = {\n findObjectByKey: findObjectByKey\n}\n\ndone({utils});" | |
} | |
}, { | |
"id": 513388, | |
"onSuccess": ["getFieldNames"], | |
"onFailure": [], | |
"name": "getApiService", | |
"type": "httpRequest", | |
"properties": { | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"method": "GET", | |
"url": "${steps.prepareGetApiService.url}" | |
} | |
}, { | |
"id": 513379, | |
"onSuccess": ["prepareGetApiServiceRevision"], | |
"onFailure": [], | |
"name": "getApiServiceInstance", | |
"type": "httpRequest", | |
"properties": { | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"url": "${steps.prepareGetApiServiceInstance.url}", | |
"method": "GET" | |
} | |
}, { | |
"id": 513386, | |
"onSuccess": ["prepareGetApiService"], | |
"onFailure": [], | |
"name": "getApiServiceRevision", | |
"type": "httpRequest", | |
"properties": { | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"url": "${steps.prepareGetApiServiceRevision.url}", | |
"method": "GET" | |
} | |
}, { | |
"id": 511866, | |
"onSuccess": ["setGlobals"], | |
"onFailure": [], | |
"name": "getAxwayAccessToken", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepAxwayAccessTokenRequest.form}", | |
"headers": "${steps.prepAxwayAccessTokenRequest.headers}", | |
"url": "https://login.axway.com/auth/realms/Broker/protocol/openid-connect/token", | |
"method": "POST" | |
} | |
}, { | |
"id": 511868, | |
"onSuccess": ["prepareUnpublishConsumerInstance"], | |
"onFailure": [], | |
"name": "getConsumerInstance", | |
"type": "httpRequest", | |
"properties": { | |
"retry": "false", | |
"body": "${steps.prepareGetConsumerInstances.body}", | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"retryAttempts": "1", | |
"retryDelay": "500", | |
"url": "${steps.prepareGetConsumerInstance.url}", | |
"method": "GET", | |
"form": "" | |
} | |
}, { | |
"id": 513394, | |
"onSuccess": ["prepareCreateIncident"], | |
"onFailure": [], | |
"name": "getFieldNames", | |
"type": "elementRequest", | |
"properties": { | |
"api": "/fields", | |
"elementInstanceId": "${config.jira}", | |
"method": "GET" | |
} | |
}, { | |
"id": 513393, | |
"onSuccess": ["createIncident"], | |
"onFailure": [], | |
"name": "prepareCreateIncident", | |
"type": "script", | |
"properties": { | |
"body": "let ApiServiceURL = steps.setGlobals.globals.apicentralUrl+'/topology/environments/'+steps.getApiService.response.body.metadata.scope.name+'/'+steps.getApiService.response.body.name;\n\nlet consumerInstanceField = steps.defineUtils.utils.findObjectByKey(steps.getFieldNames.response.body, 'name', config.consumerInstanceJiraCustomFieldName);\n\nconsole.log(consumerInstanceField);\n\n\nlet consumerInstanceURL = steps.setGlobals.globals.apicentralUrl+'/apis'+trigger.args.payload.metadata.selfLink;\n\nconsole.log(consumerInstanceURL);\n\nlet summary = 'New API Publish Approval Request for API: \"'+steps.getApiService.response.body.title+'\"';\n\nlet description = summary+\" in Environment: \"+steps.getApiService.response.body.metadata.scope.name+\"\\n\\n\";\n\ndescription += \"In order to approve or reject the Publish request, set the Approve/Reject field and close the incident.\\n\\n\";\n\ndescription += \"You can review the API Service here:\\n\"+ApiServiceURL+\"\\n\\n\";\n\nlet body = {\n \"fields\": {\n \"issuetype\": {\n \"name\": \"Bug\"\n },\n \"priority\": {\n \"name\": \"Highest\"\n },\n \"project\": {\n \"key\": config.jiraProjectKey\n },\n \"summary\": summary,\n \"description\": description\n }\n};\n\nbody.fields[consumerInstanceField.key] = consumerInstanceURL;\n\ndone({body:body});" | |
} | |
}, { | |
"id": 513387, | |
"onSuccess": ["getApiService"], | |
"onFailure": [], | |
"name": "prepareGetApiService", | |
"type": "script", | |
"properties": { | |
"body": "let reference = steps.defineUtils.utils.findObjectByKey(steps.getApiServiceRevision.response.body.metadata.references, 'kind', 'APIService');\n\nconst url = steps.setGlobals.globals.apicentralUrl + '/apis'+reference.selfLink;\n\n// const url = steps.setGlobals.globals.apicentralUrl + '/apis'+steps.getApiServiceRevision.response.body.metadata.references[0].selfLink;\n\ndone({url:url});" | |
} | |
}, { | |
"id": 513380, | |
"onSuccess": ["getApiServiceInstance"], | |
"onFailure": [], | |
"name": "prepareGetApiServiceInstance", | |
"type": "script", | |
"properties": { | |
"body": "let reference = steps.defineUtils.utils.findObjectByKey(steps.getConsumerInstance.response.body.metadata.references, 'kind', 'APIServiceInstance');\n\nconst url = steps.setGlobals.globals.apicentralUrl + '/apis'+reference.selfLink;\n\ndone({url:url});" | |
} | |
}, { | |
"id": 513385, | |
"onSuccess": ["getApiServiceRevision"], | |
"onFailure": [], | |
"name": "prepareGetApiServiceRevision", | |
"type": "script", | |
"properties": { | |
"body": "let reference = steps.defineUtils.utils.findObjectByKey(steps.getApiServiceInstance.response.body.metadata.references, 'kind', 'APIServiceRevision');\n\nconst url = steps.setGlobals.globals.apicentralUrl + '/apis'+reference.selfLink;\n\n\n// const url = steps.setGlobals.globals.apicentralUrl + '/apis'+steps.getApiServiceInstance.response.body.metadata.references[0].selfLink;\n\ndone({url:url});" | |
} | |
}, { | |
"id": 511874, | |
"onSuccess": ["getConsumerInstance"], | |
"onFailure": [], | |
"name": "prepareGetConsumerInstance", | |
"type": "script", | |
"properties": { | |
"body": "const url = steps.setGlobals.globals.apicentralUrl + '/apis'+trigger.args.payload.metadata.selfLink;\n\ndone({url:url});" | |
} | |
}, { | |
"id": 513396, | |
"onSuccess": ["sendToTeams"], | |
"onFailure": [], | |
"name": "prepareSendToTeams", | |
"type": "script", | |
"properties": { | |
"body": "let url = config.msTeamsWebhookURL;\n\nlet ApiServiceURL = steps.setGlobals.globals.apicentralUrl+'/topology/environments/'+steps.getApiService.response.body.metadata.scope.name+'/'+steps.getApiService.response.body.name;\n\nlet incidentUrl = config.jiraBaseAddress + '/jira/software/c/projects/' + config.jiraProjectKey + '/issues/' + steps.createIncident.response.body.key;\n\nlet body = {\n \"@type\": \"MessageCard\",\n \"@context\": \"http://schema.org/extensions\",\n \"themeColor\": \"0076D7\",\n \"summary\": \"API Publication Approval Request\",\n \"sections\": [{\n \"activityTitle\": \"API Publish Approval Request for API: [\"+steps.getApiService.response.body.title+\"](\"+ApiServiceURL+\") in Environment: \"+steps.getApiService.response.body.metadata.scope.name,\n \"text\": \"A Jira incident was automatically created. Click on incident link below to approve/reject the API Publication Approval request and set the incident status to Done.\",\n \"markdown\": true\n }],\n \"potentialAction\": [\n {\n \t\t\t\"@type\": \"OpenUri\",\n \t\t\t\"name\": \"View Incident\",\n \t\t\t\"targets\": [\n \t\t\t\t{\n \t\t\t\t\t\"os\": \"default\",\n \t\t\t\t\t\"uri\": incidentUrl\n \t\t\t\t}\n \t\t\t]\n \t\t}\n ]\n};\n\ndone({body: body, url: url});" | |
} | |
}, { | |
"id": 513376, | |
"onSuccess": ["unpublishConsumerInstance"], | |
"onFailure": [], | |
"name": "prepareUnpublishConsumerInstance", | |
"type": "script", | |
"properties": { | |
"body": "let body = steps.getConsumerInstance.response.body;\n\nbody.spec.state = 'UNPUBLISHED'\n\ndone({body:body})" | |
} | |
}, { | |
"id": 511878, | |
"onSuccess": ["getAxwayAccessToken"], | |
"onFailure": [], | |
"name": "prepAxwayAccessTokenRequest", | |
"type": "script", | |
"properties": { | |
"body": "\ndone({\n 'headers': { \n Authorization: 'Basic ' + CE.b64(config.axwayClientId + ':' + config.axwayClientSecret),\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n form: 'grant_type=client_credentials'\n});\n" | |
} | |
}, { | |
"id": 513397, | |
"onSuccess": [], | |
"onFailure": [], | |
"name": "sendToTeams", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepareSendToTeams.body}", | |
"method": "POST", | |
"url": "${steps.prepareSendToTeams.url}" | |
} | |
}, { | |
"id": 511880, | |
"onSuccess": ["prepareGetConsumerInstance"], | |
"onFailure": [], | |
"name": "setGlobals", | |
"type": "script", | |
"properties": { | |
"body": "let apiServerHeaders = {\n 'Authorization': `Bearer ${steps.getAxwayAccessToken.response.body.access_token}`,\n 'Content-Type': 'application/json'\n}\n\nlet apicentralUrl = config.apiCentralUrl ? config.apiCentralUrl : 'https://apicentral.axway.com';\n\nlet globals = {\n apicentralUrl: apicentralUrl,\n apiServerHeaders: apiServerHeaders\n}\n\ndone({globals});" | |
} | |
}, { | |
"id": 511881, | |
"onSuccess": ["defineUtils"], | |
"onFailure": [], | |
"name": "shouldProcess", | |
"type": "filter", | |
"properties": { | |
"body": "done(trigger.args.payload.kind === 'ConsumerInstance' && trigger.args.type === 'ResourceCreated');" | |
} | |
}, { | |
"id": 513377, | |
"onSuccess": ["prepareGetApiServiceInstance"], | |
"onFailure": [], | |
"name": "unpublishConsumerInstance", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepareUnpublishConsumerInstance.body}", | |
"headers": "${steps.setGlobals.globals.apiServerHeaders}", | |
"url": "${steps.prepareGetConsumerInstance.url}", | |
"method": "PUT" | |
} | |
}], | |
"triggers": [{ | |
"id": 43984, | |
"onSuccess": ["shouldProcess"], | |
"onFailure": [], | |
"type": "manual", | |
"async": true, | |
"active": true, | |
"name": "trigger", | |
"properties": {} | |
}], | |
"engine": "v3", | |
"active": true, | |
"debugLoggingEnabled": false, | |
"singleThreaded": false, | |
"configuration": [{ | |
"id": 90229, | |
"key": "apiCentralUrl", | |
"name": "apiCentralUrl", | |
"type": "value", | |
"required": false | |
}, { | |
"id": 90230, | |
"key": "axwayClientId", | |
"name": "axwayClientId", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90231, | |
"key": "axwayClientSecret", | |
"name": "axwayClientSecret", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90479, | |
"key": "consumerInstanceJiraCustomFieldName", | |
"name": "consumerInstanceJiraCustomFieldName", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90474, | |
"key": "jira", | |
"name": "jira", | |
"type": "elementInstance", | |
"required": true | |
}, { | |
"id": 90475, | |
"key": "jiraBaseAddress", | |
"name": "jiraBaseAddress", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90476, | |
"key": "jiraProjectKey", | |
"name": "jiraProjectKey", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 90477, | |
"key": "msTeamsWebhookURL", | |
"name": "msTeamsWebhookURL", | |
"type": "value", | |
"required": true | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment