Skip to content

Commit dd12773

Browse files
authored
issue 559 (#560)
* fix name * for keep-sake * reformat * wrong location * improve doc * new version to allow namespace different that runtime name
1 parent 7f80336 commit dd12773

File tree

6 files changed

+1016
-16
lines changed

6 files changed

+1016
-16
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: Secret
33
metadata:
4-
name: cf-api-key-aperture
4+
name: cf-api-key
55
type: Opaque
66
stringData:
77
token: "642xxxxxxxxxxxxxxxxxdedc.584xxxxxxxxxxxxxxxxxxxxxxxxxefda"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
(function execute(inputs, outputs) {
2+
/*
3+
This funtion retrieve the IngressHost URL
4+
Then terminate or resume the workflow
5+
*/
6+
7+
// Inputs
8+
var url=inputs['cf_url'] + '/2.0/api/graphql';
9+
var token=inputs['token'];
10+
var workflowName=inputs['workflow_name'];
11+
var runtime=inputs['runtime'];
12+
var action=inputs['action'];
13+
14+
/*
15+
action value is oringally from the Classic side so approve or deny
16+
It needs to be translated into workflow action: resumeWorkflow or terminateWorkflow
17+
*/
18+
if (action == "approve"){
19+
action="resumeWorkflow"
20+
} else {
21+
action="terminateWorkflow"
22+
}
23+
24+
// Variables
25+
var requestBody;
26+
var responseBody;
27+
var status;
28+
var sm;
29+
var data;
30+
var ingressHost; // the URL of the runtime ingress
31+
var namespace; // the namespace where the runtime is installed as
32+
// it could be different
33+
/*
34+
Getting the ingress host
35+
*/
36+
try {
37+
sm = new sn_ws.RESTMessageV2();
38+
sm.setEndpoint(url);
39+
sm.setHttpMethod("post");
40+
sm.setRequestHeader("Authorization", token);
41+
sm.setRequestHeader("Content-type", "application/json");
42+
data=JSON.stringify({
43+
"query": "query getRuntime($runtime: String!) { runtime(name: \$runtime) { metadata {\n name\n namespace}\n ingressHost}}",
44+
"variables": {
45+
"runtime": runtime
46+
}
47+
});
48+
sm.setRequestBody(data);
49+
response = sm.execute(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.
50+
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
51+
status = response.getStatusCode();
52+
} catch(ex) {
53+
responseBody = ex.getMessage();
54+
status = '500';
55+
} finally {
56+
requestBody = sm ? sm.getRequestBody():null;
57+
}
58+
gs.info("Response ingress: " + responseBody);
59+
gs.info("HTTP Status: " + status);
60+
61+
ingressHost=JSON.parse(responseBody).data.runtime.ingressHost
62+
namespace=JSON.parse(responseBody).data.runtime.metadata.namespace
63+
64+
/*
65+
Stopping or resuming the workflow
66+
*/
67+
try{
68+
sm = new sn_ws.RESTMessageV2();
69+
sm.setEndpoint(ingressHost + '/app-proxy/api/graphql');
70+
sm.setHttpMethod("post");
71+
sm.setRequestHeader("Authorization",token);
72+
sm.setRequestHeader("Content-type", "application/json");
73+
data=JSON.stringify({
74+
"query": "mutation " + action +"($namespace: String!, $workflowName: String!) { " + action + "(namespace: \$namespace, workflowName: \$workflowName)}",
75+
"variables": {
76+
"namespace": namespace,
77+
"workflowName": workflowName
78+
}
79+
});
80+
sm.setRequestBody(data);
81+
82+
response = sm.execute(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.
83+
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
84+
status = response.getStatusCode();
85+
} catch(ex) {
86+
responseBody = ex.getMessage();
87+
status = '500';
88+
} finally {
89+
requestBody = sm ? sm.getRequestBody():null;
90+
}
91+
gs.info("Request Body: " + requestBody);
92+
gs.info("Response: " + responseBody);
93+
gs.info("HTTP Status: " + status);
94+
95+
})(inputs, outputs);

workflows/servicenow/assets/sn_auth.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ metadata:
55
type: Opaque
66
stringData:
77
username: <username>
8-
data:
9-
password: <encoded base64 password>
8+
password: <password>

workflows/servicenow/assets/xml/ServiceNow-Codefresh_Integration_1.3.1.xml

Lines changed: 907 additions & 0 deletions
Large diffs are not rendered by default.

workflows/servicenow/assets/xml/cf_token.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

workflows/servicenow/versions/1.3.1/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22

33
## Summary
44

5-
A set of templates to perform operations against a ServiceNow instance
5+
A set of templates to perform operations against a ServiceNow instance.
66

77
### Compatibility
88

99
The workflowTemplate have been tested on the following instance releases:
1010

11-
* Tokyo
11+
* Washington DC
1212

1313
## Requirements
14-
1. create a secret containing 2 pieces of informations to connect to your
14+
1. Create a secret containing 2 pieces of informations to connect to your
1515
ServiceNow instance. See [example](../../assets/sn_auth.yml)
1616
- username
1717
- password
18-
2. create a secret containing the Codefresh API Key (in the token field). See [example](../../assets/cf_token.yaml)
19-
3. install the [local update](../../assets/xml/ServiceNow-Codefresh_Integration_1.3.0.xml) set in your instance
18+
See the [example](../../assets/sn_auth.yml) for more details.
19+
20+
The user needs change_management permissions.
21+
22+
2. Create a secret containing the Codefresh API Key (in the token field). See the [example](../../assets/cf_token.yaml) for more details.
23+
3. install the [local update](../../assets/xml/ServiceNow-Codefresh_Integration_1.3.1.xml)
24+
set in your instance using the Retrieve Update Sets table. Check with your
25+
ServiceNow admin if you're not sure or don't have enough permissions. The
26+
architecture is detailed in this [old blog article](https://codefresh.io/blog/servicenow-integration/).
2027

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

0 commit comments

Comments
 (0)