Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workflows/servicenow/assets/cf_token.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: cf-api-key-aperture
name: cf-api-key
type: Opaque
stringData:
token: "642xxxxxxxxxxxxxxxxxdedc.584xxxxxxxxxxxxxxxxxxxxxxxxxefda"
95 changes: 95 additions & 0 deletions workflows/servicenow/assets/js/approveCodefreshGitOpsWorkflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(function execute(inputs, outputs) {
/*
This funtion retrieve the IngressHost URL
Then terminate or resume the workflow
*/

// Inputs
var url=inputs['cf_url'] + '/2.0/api/graphql';
var token=inputs['token'];
var workflowName=inputs['workflow_name'];
var runtime=inputs['runtime'];
var action=inputs['action'];

/*
action value is oringally from the Classic side so approve or deny
It needs to be translated into workflow action: resumeWorkflow or terminateWorkflow
*/
if (action == "approve"){
action="resumeWorkflow"
} else {
action="terminateWorkflow"
}

// Variables
var requestBody;
var responseBody;
var status;
var sm;
var data;
var ingressHost; // the URL of the runtime ingress
var namespace; // the namespace where the runtime is installed as
// it could be different
/*
Getting the ingress host
*/
try {
sm = new sn_ws.RESTMessageV2();
sm.setEndpoint(url);
sm.setHttpMethod("post");
sm.setRequestHeader("Authorization", token);
sm.setRequestHeader("Content-type", "application/json");
data=JSON.stringify({
"query": "query getRuntime($runtime: String!) { runtime(name: \$runtime) { metadata {\n name\n namespace}\n ingressHost}}",
"variables": {
"runtime": runtime
}
});
sm.setRequestBody(data);
response = sm.execute(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
} catch(ex) {
responseBody = ex.getMessage();
status = '500';
} finally {
requestBody = sm ? sm.getRequestBody():null;
}
gs.info("Response ingress: " + responseBody);
gs.info("HTTP Status: " + status);

ingressHost=JSON.parse(responseBody).data.runtime.ingressHost
namespace=JSON.parse(responseBody).data.runtime.metadata.namespace

/*
Stopping or resuming the workflow
*/
try{
sm = new sn_ws.RESTMessageV2();
sm.setEndpoint(ingressHost + '/app-proxy/api/graphql');
sm.setHttpMethod("post");
sm.setRequestHeader("Authorization",token);
sm.setRequestHeader("Content-type", "application/json");
data=JSON.stringify({
"query": "mutation " + action +"($namespace: String!, $workflowName: String!) { " + action + "(namespace: \$namespace, workflowName: \$workflowName)}",
"variables": {
"namespace": namespace,
"workflowName": workflowName
}
});
sm.setRequestBody(data);

response = sm.execute(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
} catch(ex) {
responseBody = ex.getMessage();
status = '500';
} finally {
requestBody = sm ? sm.getRequestBody():null;
}
gs.info("Request Body: " + requestBody);
gs.info("Response: " + responseBody);
gs.info("HTTP Status: " + status);

})(inputs, outputs);
3 changes: 1 addition & 2 deletions workflows/servicenow/assets/sn_auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ metadata:
type: Opaque
stringData:
username: <username>
data:
password: <encoded base64 password>
password: <password>

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions workflows/servicenow/assets/xml/cf_token.yaml

This file was deleted.

17 changes: 12 additions & 5 deletions workflows/servicenow/versions/1.3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@

## Summary

A set of templates to perform operations against a ServiceNow instance
A set of templates to perform operations against a ServiceNow instance.

### Compatibility

The workflowTemplate have been tested on the following instance releases:

* Tokyo
* Washington DC

## Requirements
1. create a secret containing 2 pieces of informations to connect to your
1. Create a secret containing 2 pieces of informations to connect to your
ServiceNow instance. See [example](../../assets/sn_auth.yml)
- username
- password
2. create a secret containing the Codefresh API Key (in the token field). See [example](../../assets/cf_token.yaml)
3. install the [local update](../../assets/xml/ServiceNow-Codefresh_Integration_1.3.0.xml) set in your instance
See the [example](../../assets/sn_auth.yml) for more details.

The user needs change_management permissions.

2. Create a secret containing the Codefresh API Key (in the token field). See the [example](../../assets/cf_token.yaml) for more details.
3. install the [local update](../../assets/xml/ServiceNow-Codefresh_Integration_1.3.1.xml)
set in your instance using the Retrieve Update Sets table. Check with your
ServiceNow admin if you're not sure or don't have enough permissions. The
architecture is detailed in this [old blog article](https://codefresh.io/blog/servicenow-integration/).

## Templates
1. [createcr](https://github.com/codefresh-io/argo-hub/blob/main/workflows/servicenow/versions/1.3.1/docs/createcr.md)
Expand Down