From c81de76584b8fe797e9e5c40f2ca10ba6fff30ba Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 17 Sep 2021 11:01:14 -0700 Subject: [PATCH 01/37] bumping version to force rebuild --- incubating/service-now/step.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 1fd6fb71b..05ff2f46c 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -2,7 +2,7 @@ kind: step-type version: '1.0' metadata: name: service-now - version: 1.0.2 + version: 1.0.3 isPublic: true description: Integration with ServiceNow Change Management sources: @@ -109,7 +109,7 @@ spec: createCR: name: Create a ServiceNow Change Request title: Use REST API to create a CR - image: 'quay.io/codefreshplugins/service-now:1.0.2' + image: 'quay.io/codefreshplugins/service-now:1.0.3' environment: - action=createCR [[ range $key, $val := .Arguments ]] @@ -127,7 +127,7 @@ spec: callback: name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected title: ServiceNow callback setup - image: 'quay.io/codefreshplugins/service-now:1.0.2' + image: 'quay.io/codefreshplugins/service-now:1.0.3' environment: - action=callback From 08a449bf6c509f0d38166e0d92ea416302fc45ca Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 15:17:48 -0700 Subject: [PATCH 02/37] Change to private account --- incubating/service-now/step.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 05ff2f46c..4dfce87c7 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -1,8 +1,8 @@ kind: step-type version: '1.0' metadata: - name: service-now - version: 1.0.3 + name: laurent-cf/service-now + version: 1.1.0 isPublic: true description: Integration with ServiceNow Change Management sources: @@ -109,7 +109,8 @@ spec: createCR: name: Create a ServiceNow Change Request title: Use REST API to create a CR - image: 'quay.io/codefreshplugins/service-now:1.0.3' + # image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0' environment: - action=createCR [[ range $key, $val := .Arguments ]] @@ -127,7 +128,8 @@ spec: callback: name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected title: ServiceNow callback setup - image: 'quay.io/codefreshplugins/service-now:1.0.3' + #image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0' environment: - action=callback From 22ee7b4721c1ee5e5172b0fc83238f1bec3d8de2 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 15:53:45 -0700 Subject: [PATCH 03/37] #402: Adding logic for action --- incubating/service-now/step.yaml | 41 ++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 4dfce87c7..f008070dd 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -31,7 +31,25 @@ metadata: SN_INSTANCE: https://instance.service-now.com SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} - cr_body: '{"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"}' + data: '{"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"}' + wait: + stage: deploy + title: Waiting for Change Request to be approved + type: pending-approval + timeout: + duration: 48 + timeUnit: hours + finalState: denied + closeCR: + title: Close the CR + type: service-now + stage: cleaning + arguments: + action: closeCR + SN_INSTANCE: https://instance.service-now.com + SN_USER: ${{SN_USER}} + SN_PASSWORD: ${{SN_PASSWORD}} + data: '{"close_code": "", "close_note": "Closed automatically by Codefreshuild ${{CF_BUILD_ID}}"}' spec: arguments: |- { @@ -65,13 +83,18 @@ spec: }, "namespace": { "type": "string", - "description": "The endpoint to call if using a different one. The system will call $SN_INSTANCE/api/$endpoint", + "description": "The endpoint namespace to call if using a different one. The system will call $SN_INSTANCE/api/$endpoint", "default": "409723" }, "data": { "type": "string", "description": "The body to create the CR. Need to include all the fields required for your Change Management implementation." }, + "action": { + "type": "string", + "description": "Action to execute: createCR or closeCR", + "default": "createCR" + }, "debug": { "type": "string", "default": "false", @@ -106,6 +129,19 @@ spec: } } stepsTemplate: |- + [[ if .Arguments.action == "closeCR" ]] + createCR: + name: Close a ServiceNow Change Request + title: Use REST API to close the CR + # image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0' + environment: + - action=closeCR + [[ range $key, $val := .Arguments ]] + - '[[ $key ]]=[[ $val ]]' + [[- end ]] + [[ end ]] + [[ if .Arguments.action == "createCR" ]] createCR: name: Create a ServiceNow Change Request title: Use REST API to create a CR @@ -136,6 +172,7 @@ spec: [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] + [[ end ]] delimiters: left: '[[' right: ']]' From 43c196a8a8a499cdac92bf30281f9fd76a50713e Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 17:35:07 -0700 Subject: [PATCH 04/37] #402: fix step.yaml syntax --- incubating/service-now/step.yaml | 87 ++++++++++++++++---------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index f008070dd..438823211 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -49,7 +49,8 @@ metadata: SN_INSTANCE: https://instance.service-now.com SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} - data: '{"close_code": "", "close_note": "Closed automatically by Codefreshuild ${{CF_BUILD_ID}}"}' + data: '{"close_code":"success", "close_note":"Closed automatically by Codefresh build ${{CF_BUILD_ID}}"}' + spec: arguments: |- { @@ -129,50 +130,48 @@ spec: } } stepsTemplate: |- - [[ if .Arguments.action == "closeCR" ]] - createCR: - name: Close a ServiceNow Change Request - title: Use REST API to close the CR - # image: 'quay.io/codefreshplugins/service-now:1.1.0' - image: lrochette/service-now:1.1.0' - environment: - - action=closeCR - [[ range $key, $val := .Arguments ]] - - '[[ $key ]]=[[ $val ]]' - [[- end ]] - [[ end ]] - [[ if .Arguments.action == "createCR" ]] - createCR: - name: Create a ServiceNow Change Request - title: Use REST API to create a CR - # image: 'quay.io/codefreshplugins/service-now:1.1.0' - image: lrochette/service-now:1.1.0' - environment: - - action=createCR - [[ range $key, $val := .Arguments ]] - - '[[ $key ]]=[[ $val ]]' - [[- end ]] - createAnnotation: - name: Assign CR_NUMBER as annotation - image: codefresh/cli - commands: - - | - codefresh create annotation workflow ${{CF_BUILD_ID}} CR_NUMBER=${{CR_NUMBER}} - export createAnnotation_CF_OUTPUT_URL='[[.Arguments.SN_INSTANCE]]/nav_to.do?uri=/change_request.do?sys_id=${{CR_SYS_ID}}' - # echo $createAnnotation_CF_OUTPUT_URL - # cf_export createAnnotation_CF_OUTPUT_URL - callback: - name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected - title: ServiceNow callback setup - #image: 'quay.io/codefreshplugins/service-now:1.1.0' - image: lrochette/service-now:1.1.0' + [[ if .Arguments.action == "closeCR" ]] + createCR: + name: Close a ServiceNow Change Request + title: Use REST API to close the CR + image: lrochette/service-now:1.1.0' + environment: + - action=closeCR + [[ range $key, $val := .Arguments ]] + - '[[ $key ]]=[[ $val ]]' + [[- end ]] + [[ end ]] + [[ if .Arguments.action == "createCR" ]] + createCR: + name: Create a ServiceNow Change Request + title: Use REST API to create a CR + image: lrochette/service-now:1.1.0' + environment: + - action=createCR + [[ range $key, $val := .Arguments ]] + - '[[ $key ]]=[[ $val ]]' + [[- end ]] + createAnnotation: + name: Assign CR_NUMBER as annotation + image: codefresh/cli + commands: + - | + codefresh create annotation workflow ${{CF_BUILD_ID}} CR_NUMBER=${{CR_NUMBER}} + export createAnnotation_CF_OUTPUT_URL='[[.Arguments.SN_INSTANCE]]/nav_to.do?uri=/change_request.do?sys_id=${{CR_SYS_ID}}' + # echo $createAnnotation_CF_OUTPUT_URL + # cf_export createAnnotation_CF_OUTPUT_URL + callback: + name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected + title: ServiceNow callback setup + #image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0' - environment: - - action=callback - [[ range $key, $val := .Arguments ]] - - '[[ $key ]]=[[ $val ]]' - [[- end ]] - [[ end ]] + environment: + - action=callback + [[ range $key, $val := .Arguments ]] + - '[[ $key ]]=[[ $val ]]' + [[- end ]] + [[ end ]] delimiters: left: '[[' right: ']]' From 2c1bc1e0ccca5acf6ce3d1382e717d5d21c04ec3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 17:59:50 -0700 Subject: [PATCH 05/37] #402: smaller SVG icon --- incubating/service-now/images/servicenow-2.svg | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 incubating/service-now/images/servicenow-2.svg diff --git a/incubating/service-now/images/servicenow-2.svg b/incubating/service-now/images/servicenow-2.svg new file mode 100644 index 000000000..7913d06cf --- /dev/null +++ b/incubating/service-now/images/servicenow-2.svg @@ -0,0 +1,14 @@ + +ServiceNow logoA cloud computing and enterprise software provider based in Santa Clara, California, United Statesimage/svg+xml + + + + + + + + + + + + From 962e26b1fdb6085a4f5523ae93e027c772626334 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 18:03:13 -0700 Subject: [PATCH 06/37] 402: new smaller logo in svg format --- incubating/service-now/step.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 438823211..01799fc86 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -17,7 +17,7 @@ metadata: tags: [] icon: type: svg - url: https://raw.githubusercontent.com/codefresh-io/steps/master/incubating/service-now/images/servicenow-1.png + url: https://raw.githubusercontent.com/codefresh-io/steps/snow-issue402/incubating/service-now/images/servicenow-2.svg background: "#f4f4f4" examples: - description: service-now From e52613ade916807129c1a9da1f1ba5d91da351ce Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 22:45:40 -0700 Subject: [PATCH 07/37] #402: adding code for closing CR --- incubating/service-now/lib/snow.py | 60 +++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 3d82274ab..37d1dc0ae 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -55,7 +55,7 @@ def processChangeRequestResponse(response): # # Call SNow REST API to create a new Change Request -# Fields required are past in the data +# Fields required are pasted in the data def createChangeRequest(user, password, baseUrl, title, data, description): if DEBUG: @@ -84,6 +84,47 @@ def createChangeRequest(user, password, baseUrl, title, data, description): auth=(user, password)) processChangeRequestResponse(response=resp) +def processCloseChangeRequestResponse(response): + + print("Processing answer from CR closing REST call") + print("Close Change Request returned code %s" % (response.status_code)) + if (response.status_code != 200 and response.status_code != 201): + print("Close Change Request creation failed with code %s" % (response.status_code)) + print("Error: " + response.text) + return response.status_code + + print("Close Change Request creation successful") + data=response.json() # json.loads(response.text) + + FULL_JSON=json.dumps(data, indent=2) + + if os.path.exists(env_file_path): + env_file = open(env_file_path, "a") + env_file.write("CR_CLOSE_FULL_JSON=/codefresh/volume/servicenow-cr-close.json\n") + env_file.close() + + json_file=open("/codefresh/volume/servicenow-cr-close.json", "w") + json_file.write(FULL_JSON) + json_file.close() + +# Call SNow REST API to close a CR +# Fields required are pasted in the data +def closeChangeRequest(user, password, baseUrl, sysid, code): + if DEBUG: + print("Entering closeChangeRequest:") + print("Body: " + data) + if (bool(data)): + crBody=json.loads(data) + else: + crBody= {} + crBody["state"] = 3 + crBody["close_code"] = code + url="%s/now/table/change_request/%s" % (baseUrl, sysid) + resp=requests.patch(url, + json = crBody, + headers = {"content-type":"application/json"}, + auth=(user, password)) + processCloseChangeRequestResponse(response=resp) # Use rest API to call scripted REST API to start a flow that will wait for CR # to be approved or rejected, then callback Codefreh to approve/deny pipeline # @@ -120,12 +161,12 @@ def main(): PASSWORD = os.getenv('SN_PASSWORD') INSTANCE = os.getenv('SN_INSTANCE') DATA = os.getenv('data') - #DEBUG = True if os.getenv('debug', "false").lower == "true" else False - TITLE = os.getenv('title', 'Change Request created by Codefresh') - DESCRIPTION = os.getenv('description', '') if ACTION == "createcr": + TITLE = os.getenv('title', 'Change Request created by Codefresh') + DESCRIPTION = os.getenv('description', '') + createChangeRequest(user=USER, password=PASSWORD, baseUrl=getBaseUrl(instance=INSTANCE), @@ -140,7 +181,16 @@ def main(): token=os.getenv('TOKEN'), cf_build_id=os.getenv('CF_BUILD_ID') ) - + elif ACTION == "closecr": + CR_SYS_ID= os.getenv('CR_SYS_ID') + CODE= "successful" if os.getenv('closeCode') == "success" else "unsuccessful" + closeChangeRequest( + user=USER, + password=PASSWORD, + baseUrl=getBaseUrl(instance=INSTANCE), + number=os.getenv('CR_SYSID'), + code=CODE + ) else: sys.exit(f"Unknown action: {ACTION}") From 36d4e2e54a42972c332addaf69bf84d3beec610c Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 6 Oct 2021 23:08:38 -0700 Subject: [PATCH 08/37] : use all CAPS for parameters to get consistency --- incubating/service-now/step.yaml | 45 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 01799fc86..e652ac37d 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -34,7 +34,7 @@ metadata: data: '{"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"}' wait: stage: deploy - title: Waiting for Change Request to be approved + title: Waiting for the Change Request to be approved type: pending-approval timeout: duration: 48 @@ -49,6 +49,7 @@ metadata: SN_INSTANCE: https://instance.service-now.com SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} + close_code: ${{workflow.status}} data: '{"close_code":"success", "close_note":"Closed automatically by Codefresh build ${{CF_BUILD_ID}}"}' spec: @@ -62,8 +63,7 @@ spec: "required": [ "SN_INSTANCE", "SN_USER", - "SN_PASSWORD", - "TOKEN" + "SN_PASSWORD" ], "properties": { "SN_INSTANCE": { @@ -82,21 +82,26 @@ spec: "type": "string", "description": "The Codefresh API token to allow ServiceNow to approve/deny the pipeline" }, - "namespace": { + "SN_NAMESPACE": { "type": "string", "description": "The endpoint namespace to call if using a different one. The system will call $SN_INSTANCE/api/$endpoint", "default": "409723" }, - "data": { + "CR_DATA": { "type": "string", "description": "The body to create the CR. Need to include all the fields required for your Change Management implementation." }, - "action": { + "CR_ACTION": { "type": "string", "description": "Action to execute: createCR or closeCR", "default": "createCR" }, - "debug": { + "CR_CLOSE_CODE": { + "type": "string", + "description": "Close code for the closeCR action: successful or unsuccessful", + "default": "successful" + }, + "DEBUG": { "type": "string", "default": "false", "description": "a hidden option show more debug info" @@ -115,39 +120,37 @@ spec: "CR_SYS_ID" ], "properties": { - "sys_id": { + "CR_SYS_ID": { "type": "string", "description": "The sys_id of the CR created" }, - "cr_number": { + "CR_NUMBER": { "type": "string", "description": "The number of the CR created." - }, - "cr_sysid": { - "type": "string", - "description": "The sys_id of the CR created." } } } stepsTemplate: |- - [[ if .Arguments.action == "closeCR" ]] + [[ if .Arguments.CR_ACTION == "closeCR" ]] createCR: name: Close a ServiceNow Change Request title: Use REST API to close the CR - image: lrochette/service-now:1.1.0' + #image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0 environment: - - action=closeCR + - CR_ACTION=closeCR [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] [[ end ]] - [[ if .Arguments.action == "createCR" ]] + [[ if .Arguments.CR_ACTION == "createCR" ]] createCR: name: Create a ServiceNow Change Request title: Use REST API to create a CR - image: lrochette/service-now:1.1.0' + #image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0 environment: - - action=createCR + - CR_ACTION=createCR [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] @@ -164,10 +167,10 @@ spec: name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected title: ServiceNow callback setup #image: 'quay.io/codefreshplugins/service-now:1.1.0' - image: lrochette/service-now:1.1.0' + image: lrochette/service-now:1.1.0 environment: - - action=callback + - CR_ACTION=callback [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] From ba7283d6a0a256afcaf84776a6f85ed9e533208b Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 15:09:01 -0700 Subject: [PATCH 09/37] #402: Fixing python script Adding code for modifying a CR as well --- incubating/service-now/lib/snow.py | 102 +++++++++++++++++++++-------- incubating/service-now/step.yaml | 44 +++++++++---- 2 files changed, 107 insertions(+), 39 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 37d1dc0ae..146ce71f9 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -24,7 +24,7 @@ def processCallbackResponse(response): print("Callback creation successful") -def processChangeRequestResponse(response): +def processCreateChangeRequestResponse(response): print("Processing answer from CR creation REST call") print("Change Request returned code %s" % (response.status_code)) @@ -45,7 +45,7 @@ def processChangeRequestResponse(response): if os.path.exists(env_file_path): env_file = open(env_file_path, "a") env_file.write(f"CR_NUMBER={CR_NUMBER}\n") - env_file.write(f"CR_SYS_ID={CR_SYSID}\n") + env_file.write(f"CR_SYSID={CR_SYSID}\n") env_file.write("CR_FULL_JSON=/codefresh/volume/servicenow-cr.json\n") env_file.close() @@ -56,11 +56,11 @@ def processChangeRequestResponse(response): # # Call SNow REST API to create a new Change Request # Fields required are pasted in the data -def createChangeRequest(user, password, baseUrl, title, data, description): +def createChangeRequest(user, password, baseUrl, data): if DEBUG: print("Entering createChangeRequest:") - print("Body: " + data) + print(f"Data: {data}") if (bool(data)): crBody=json.loads(data) @@ -82,49 +82,77 @@ def createChangeRequest(user, password, baseUrl, title, data, description): json = crBody, headers = {"content-type":"application/json"}, auth=(user, password)) - processChangeRequestResponse(response=resp) + processCreateChangeRequestResponse(response=resp) -def processCloseChangeRequestResponse(response): +def processModifyChangeRequestResponse(response, action): - print("Processing answer from CR closing REST call") + print("Processing answer from CR %s REST call" %(action)) print("Close Change Request returned code %s" % (response.status_code)) if (response.status_code != 200 and response.status_code != 201): - print("Close Change Request creation failed with code %s" % (response.status_code)) + print("%s Change Request creation failed with code %s" % (action, response.status_code)) print("Error: " + response.text) return response.status_code - print("Close Change Request creation successful") + print("%s Change Request creation successful" %(action)) data=response.json() # json.loads(response.text) FULL_JSON=json.dumps(data, indent=2) + if (action == "close" ): + jsonVar="CR_CLOSE_FULL_JSON" + jsonFileName="/codefresh/volume/servicenow-cr-close.json" + elif (action == "update" ): + jsonVar="CR_UPDATE_FULL_JSON" + jsonFileName="/codefresh/volume/servicenow-cr-update.json" + else: + print("ERROR: action unknonw. Should not be here. Error should have been caught earlier") if os.path.exists(env_file_path): env_file = open(env_file_path, "a") - env_file.write("CR_CLOSE_FULL_JSON=/codefresh/volume/servicenow-cr-close.json\n") + env_file.write(f"{jsonVar}=/codefresh/volume/servicenow-cr-close.json\n") env_file.close() json_file=open("/codefresh/volume/servicenow-cr-close.json", "w") json_file.write(FULL_JSON) json_file.close() - + # Call SNow REST API to close a CR # Fields required are pasted in the data -def closeChangeRequest(user, password, baseUrl, sysid, code): +def closeChangeRequest(user, password, baseUrl, sysid, code, notes, data): if DEBUG: print("Entering closeChangeRequest:") - print("Body: " + data) + print(f"DATA: {data}") if (bool(data)): crBody=json.loads(data) else: crBody= {} crBody["state"] = 3 crBody["close_code"] = code + crBody["close_notes"] = notes url="%s/now/table/change_request/%s" % (baseUrl, sysid) resp=requests.patch(url, json = crBody, headers = {"content-type":"application/json"}, auth=(user, password)) - processCloseChangeRequestResponse(response=resp) + processModifyChangeRequestResponse(response=resp, action="close") + +# Call SNow REST API to update a CR +# Fields required are pasted in the data +def updateChangeRequest(user, password, baseUrl, sysid, data): + if DEBUG: + print("Entering closeChangeRequest:") + print(f"DATA: {data}") + if (bool(data)): + crBody=json.loads(data) + else: + crBody= {} + print("WARNING: CR_DATA is empty. What are you updating exactly?") + + url="%s/now/table/change_request/%s" % (baseUrl, sysid) + resp=requests.patch(url, + json = crBody, + headers = {"content-type":"application/json"}, + auth=(user, password)) + processModifyChangeRequestResponse(response=resp, action="update") # Use rest API to call scripted REST API to start a flow that will wait for CR # to be approved or rejected, then callback Codefreh to approve/deny pipeline # @@ -153,26 +181,31 @@ def callback(user, password, baseUrl, number, cf_build_id, token): auth=(user, password)) processCallbackResponse(response=resp) +def checkSysid(sysid): + if DEBUG: + print("Entering checkSysid: ") + print(" CR_SYSID: %s" % (sysid)) + + if ( sysid == None ): + sys.exit("FATAL: CR_SYS_ID is not defined.") + + def main(): global DEBUG - ACTION = os.getenv('action', 'createCR').lower() + ACTION = os.getenv('CR_ACTION', 'createCR').lower() USER = os.getenv('SN_USER') PASSWORD = os.getenv('SN_PASSWORD') INSTANCE = os.getenv('SN_INSTANCE') - DATA = os.getenv('data') + DATA = os.getenv('CR_DATA') #DEBUG = True if os.getenv('debug', "false").lower == "true" else False if ACTION == "createcr": - TITLE = os.getenv('title', 'Change Request created by Codefresh') - DESCRIPTION = os.getenv('description', '') createChangeRequest(user=USER, password=PASSWORD, baseUrl=getBaseUrl(instance=INSTANCE), - title=TITLE, - data=DATA, - description=DESCRIPTION) + data=DATA) elif ACTION == "callback": callback(user=USER, password=PASSWORD, @@ -182,17 +215,34 @@ def main(): cf_build_id=os.getenv('CF_BUILD_ID') ) elif ACTION == "closecr": - CR_SYS_ID= os.getenv('CR_SYS_ID') - CODE= "successful" if os.getenv('closeCode') == "success" else "unsuccessful" + CR_SYSID= os.getenv('CR_SYSID') + CODE=os.getenv('CR_CLOSE_CODE') + NOTES=os.getenv('CR_CLOSE_NOTES') + + checkSysid(CR_SYSID) + closeChangeRequest( user=USER, password=PASSWORD, baseUrl=getBaseUrl(instance=INSTANCE), - number=os.getenv('CR_SYSID'), - code=CODE + sysid=os.getenv('CR_SYSID'), + code=CODE, + notes=NOTES, + data=DATA + ) + elif ACTION == "updatecr": + CR_SYSID= os.getenv('CR_SYSID') + checkSysid(CR_SYSID) + + updateChangeRequest( + user=USER, + password=PASSWORD, + baseUrl=getBaseUrl(instance=INSTANCE), + sysid=os.getenv('CR_SYSID'), + data=DATA ) else: - sys.exit(f"Unknown action: {ACTION}") + sys.exit(f"FATAL: Unknown action: {ACTION}. Allowed values are createCR, closeCR or updateCR.") if __name__ == "__main__": diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index e652ac37d..d48e07874 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -3,7 +3,7 @@ version: '1.0' metadata: name: laurent-cf/service-now version: 1.1.0 - isPublic: true + isPublic: false description: Integration with ServiceNow Change Management sources: - https://github.com/codefresh-io/steps/tree/master/incubating/service-now @@ -13,7 +13,7 @@ metadata: - email: laurent.rochette@codefresh.io categories: - utilities - official: true + official: false tags: [] icon: type: svg @@ -27,11 +27,11 @@ metadata: type: service-now stage: deploy arguments: - action: createCR + CR_ACTION: createCR SN_INSTANCE: https://instance.service-now.com SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} - data: '{"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"}' + CR_DATA: '{"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"}' wait: stage: deploy title: Waiting for the Change Request to be approved @@ -45,12 +45,13 @@ metadata: type: service-now stage: cleaning arguments: - action: closeCR + CR_ACTION: closeCR SN_INSTANCE: https://instance.service-now.com SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} - close_code: ${{workflow.status}} - data: '{"close_code":"success", "close_note":"Closed automatically by Codefresh build ${{CF_BUILD_ID}}"}' + CR_CLOSE_CODE: successful + CR_CLOSE_NOTES: "CR closed by Codefresh build ${{CF_BUILD_ID}}" + CR_DATA: '{"close_note":"Closed automatically by Codefresh build ${{CF_BUILD_ID}}"}' spec: arguments: |- @@ -98,9 +99,14 @@ spec: }, "CR_CLOSE_CODE": { "type": "string", - "description": "Close code for the closeCR action: successful or unsuccessful", + "description": "Close code for the closeCR action: successful, successful_issues or unsuccessful", "default": "successful" }, + "CR_CLOSE_NOTES": { + "type": "string", + "description": "Close notes for the closeCR action: successful, successful_issues or unsuccessful", + "default": "Closed by Codefresh" + }, "DEBUG": { "type": "string", "default": "false", @@ -117,12 +123,12 @@ spec: "patterns": [], "required": [ "CR_NUMBER", - "CR_SYS_ID" + "CR_SYSID" ], "properties": { - "CR_SYS_ID": { + "CR_SYSID": { "type": "string", - "description": "The sys_id of the CR created" + "description": "The sysid of the CR created" }, "CR_NUMBER": { "type": "string", @@ -132,7 +138,7 @@ spec: } stepsTemplate: |- [[ if .Arguments.CR_ACTION == "closeCR" ]] - createCR: + closeCR: name: Close a ServiceNow Change Request title: Use REST API to close the CR #image: 'quay.io/codefreshplugins/service-now:1.1.0' @@ -143,6 +149,18 @@ spec: - '[[ $key ]]=[[ $val ]]' [[- end ]] [[ end ]] + [[ if .Arguments.CR_ACTION == "updateCR" ]] + closeCR: + name: Update a ServiceNow Change Request + title: Use REST API to close the CR + #image: 'quay.io/codefreshplugins/service-now:1.1.0' + image: lrochette/service-now:1.1.0 + environment: + - CR_ACTION=updateCR + [[ range $key, $val := .Arguments ]] + - '[[ $key ]]=[[ $val ]]' + [[- end ]] + [[ end ]] [[ if .Arguments.CR_ACTION == "createCR" ]] createCR: name: Create a ServiceNow Change Request @@ -160,7 +178,7 @@ spec: commands: - | codefresh create annotation workflow ${{CF_BUILD_ID}} CR_NUMBER=${{CR_NUMBER}} - export createAnnotation_CF_OUTPUT_URL='[[.Arguments.SN_INSTANCE]]/nav_to.do?uri=/change_request.do?sys_id=${{CR_SYS_ID}}' + export createAnnotation_CF_OUTPUT_URL='[[.Arguments.SN_INSTANCE]]/nav_to.do?uri=/change_request.do?sys_id=${{CR_SYSID}}' # echo $createAnnotation_CF_OUTPUT_URL # cf_export createAnnotation_CF_OUTPUT_URL callback: From 4be688ec80d5f34c086efbeac30e937c0e5373d5 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 15:37:52 -0700 Subject: [PATCH 10/37] #402: test for empty CR_DATA --- incubating/service-now/lib/snow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 146ce71f9..bbdc201c4 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -60,7 +60,7 @@ def createChangeRequest(user, password, baseUrl, data): if DEBUG: print("Entering createChangeRequest:") - print(f"Data: {data}") + print(f"Data: {data}") if bool(data) if (bool(data)): crBody=json.loads(data) From d38a408b50ff016d4606c337fe91baececd13001 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 15:42:03 -0700 Subject: [PATCH 11/37] #402: test for empty CR_DATA --- incubating/service-now/lib/snow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index bbdc201c4..da15a5b99 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -60,10 +60,12 @@ def createChangeRequest(user, password, baseUrl, data): if DEBUG: print("Entering createChangeRequest:") - print(f"Data: {data}") if bool(data) + if (bool(data)): crBody=json.loads(data) + if DEBUG: + print(f"Data: {data}") else: crBody= {} From 6ee91cd3b7bc7ff0f560182dc532320ca173eacc Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 15:42:51 -0700 Subject: [PATCH 12/37] #402: test for empty CR_DATA --- incubating/service-now/lib/snow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index da15a5b99..558163dbe 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -68,7 +68,8 @@ def createChangeRequest(user, password, baseUrl, data): print(f"Data: {data}") else: crBody= {} - + if DEBUG: + print("Data: None") crBody["cf_build_id"] = os.getenv('CF_BUILD_ID') From ba322bdc90fdd2457fe95c2ac9bebe884e092d6c Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 15:46:53 -0700 Subject: [PATCH 13/37] #402: test for empty CR_DATA --- incubating/service-now/lib/snow.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 558163dbe..d36022b6e 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -61,11 +61,10 @@ def createChangeRequest(user, password, baseUrl, data): if DEBUG: print("Entering createChangeRequest:") - if (bool(data)): crBody=json.loads(data) if DEBUG: - print(f"Data: {data}") + print("Data: " + data) else: crBody= {} if DEBUG: From 46052e9e52e3e5ed8d14b2cd2f4378e663ab229c Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 16:18:22 -0700 Subject: [PATCH 14/37] #402: step.yaml syntax? --- incubating/service-now/lib/snow.py | 23 +++++++++++------------ incubating/service-now/step.yaml | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index d36022b6e..95121d9f5 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -27,20 +27,20 @@ def processCallbackResponse(response): def processCreateChangeRequestResponse(response): print("Processing answer from CR creation REST call") - print("Change Request returned code %s" % (response.status_code)) + print(" Change Request returned code %s" % (response.status_code)) if (response.status_code != 200 and response.status_code != 201): - print("Change Request creation failed with code %s" % (response.status_code)) - print("Error: " + response.text) + print(" Change Request creation failed with code %s" % (response.status_code)) + print(" Error: " + response.text) return response.status_code - print("Change Request creation successful") + print(" Change Request creation successful") data=response.json() # json.loads(response.text) CR_NUMBER=data["result"]["number"] CR_SYSID=data["result"]["sys_id"] FULL_JSON=json.dumps(data, indent=2) - print(f"Change Request Number: {CR_NUMBER}") - print(f"Change Request sys_id: {CR_SYSID}") - print("Change Request full answer:\n" + FULL_JSON) + print(f" Change Request Number: {CR_NUMBER}") + print(f" Change Request sys_id: {CR_SYSID}") + print(" Change Request full answer:\n" + FULL_JSON) if os.path.exists(env_file_path): env_file = open(env_file_path, "a") @@ -68,17 +68,16 @@ def createChangeRequest(user, password, baseUrl, data): else: crBody= {} if DEBUG: - print("Data: None") + print(" Data: None") crBody["cf_build_id"] = os.getenv('CF_BUILD_ID') url="%s/now/table/change_request" % (baseUrl) if DEBUG: - print(f"Entering createChangeRequest:") - print(f"URL: {url}") - print(f"User: {user}") - print(f"Body: {crBody}") + print(f" URL: {url}") + print(f" User: {user}") + print(f" Body: {crBody}") resp=requests.post(url, json = crBody, diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index d48e07874..2b49f559f 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -31,15 +31,27 @@ metadata: SN_INSTANCE: https://instance.service-now.com SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} - CR_DATA: '{"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"}' + CR_DATA: {"short_description":"This is a Change Request created by Codefresh","description":"long description for Codefresh build ${{CF_BUILD_ID}}","justification":"because our app is awesome"} wait: stage: deploy title: Waiting for the Change Request to be approved type: pending-approval + stage: deploy timeout: duration: 48 timeUnit: hours finalState: denied + modifyCR: + title: Close the CR + type: service-now + stage: deploy + arguments: + CR_ACTION: closeCR + SN_INSTANCE: https://instance.service-now.com + SN_USER: ${{SN_USER}} + SN_PASSWORD: ${{SN_PASSWORD}} + CR_DATA: {"work_notes":"Test pass rate: ${{_TEST_RATE}}"} + closeCR: title: Close the CR type: service-now @@ -51,7 +63,7 @@ metadata: SN_PASSWORD: ${{SN_PASSWORD}} CR_CLOSE_CODE: successful CR_CLOSE_NOTES: "CR closed by Codefresh build ${{CF_BUILD_ID}}" - CR_DATA: '{"close_note":"Closed automatically by Codefresh build ${{CF_BUILD_ID}}"}' + CR_DATA: {"close_note":"Closed automatically by Codefresh build ${{CF_BUILD_ID}}"} spec: arguments: |- @@ -141,7 +153,6 @@ spec: closeCR: name: Close a ServiceNow Change Request title: Use REST API to close the CR - #image: 'quay.io/codefreshplugins/service-now:1.1.0' image: lrochette/service-now:1.1.0 environment: - CR_ACTION=closeCR @@ -153,7 +164,6 @@ spec: closeCR: name: Update a ServiceNow Change Request title: Use REST API to close the CR - #image: 'quay.io/codefreshplugins/service-now:1.1.0' image: lrochette/service-now:1.1.0 environment: - CR_ACTION=updateCR @@ -165,7 +175,6 @@ spec: createCR: name: Create a ServiceNow Change Request title: Use REST API to create a CR - #image: 'quay.io/codefreshplugins/service-now:1.1.0' image: lrochette/service-now:1.1.0 environment: - CR_ACTION=createCR @@ -184,7 +193,6 @@ spec: callback: name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected title: ServiceNow callback setup - #image: 'quay.io/codefreshplugins/service-now:1.1.0' image: lrochette/service-now:1.1.0 environment: From 21c4cee677e6309193bebcf4e4b1a6ff903ab7f5 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 16:37:39 -0700 Subject: [PATCH 15/37] #402: remvoing blank lines --- incubating/service-now/step.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 2b49f559f..4e8d2281b 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -36,7 +36,6 @@ metadata: stage: deploy title: Waiting for the Change Request to be approved type: pending-approval - stage: deploy timeout: duration: 48 timeUnit: hours @@ -51,7 +50,6 @@ metadata: SN_USER: ${{SN_USER}} SN_PASSWORD: ${{SN_PASSWORD}} CR_DATA: {"work_notes":"Test pass rate: ${{_TEST_RATE}}"} - closeCR: title: Close the CR type: service-now @@ -161,7 +159,7 @@ spec: [[- end ]] [[ end ]] [[ if .Arguments.CR_ACTION == "updateCR" ]] - closeCR: + updateCR: name: Update a ServiceNow Change Request title: Use REST API to close the CR image: lrochette/service-now:1.1.0 @@ -194,7 +192,6 @@ spec: name: invoke scripted REST API to have ServiceNow callback Codefresh when CR is approved/rejected title: ServiceNow callback setup image: lrochette/service-now:1.1.0 - environment: - CR_ACTION=callback [[ range $key, $val := .Arguments ]] From f77157159f143e8815833010277fff2ef90f0679 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 17:53:11 -0700 Subject: [PATCH 16/37] #402: fix go template syntax with eq instead of == --- incubating/service-now/step.yaml | 6 +-- incubating/service-now/venonalog.json | 59 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 incubating/service-now/venonalog.json diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 4e8d2281b..59bd42e5c 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -147,7 +147,7 @@ spec: } } stepsTemplate: |- - [[ if .Arguments.CR_ACTION == "closeCR" ]] + [[ if eq .Arguments.CR_ACTION "closeCR" ]] closeCR: name: Close a ServiceNow Change Request title: Use REST API to close the CR @@ -158,7 +158,7 @@ spec: - '[[ $key ]]=[[ $val ]]' [[- end ]] [[ end ]] - [[ if .Arguments.CR_ACTION == "updateCR" ]] + [[ if eq .Arguments.CR_ACTION "updateCR" ]] updateCR: name: Update a ServiceNow Change Request title: Use REST API to close the CR @@ -169,7 +169,7 @@ spec: - '[[ $key ]]=[[ $val ]]' [[- end ]] [[ end ]] - [[ if .Arguments.CR_ACTION == "createCR" ]] + [[ if eq .Arguments.CR_ACTION "createCR" ]] createCR: name: Create a ServiceNow Change Request title: Use REST API to create a CR diff --git a/incubating/service-now/venonalog.json b/incubating/service-now/venonalog.json new file mode 100644 index 000000000..0f1eb517a --- /dev/null +++ b/incubating/service-now/venonalog.json @@ -0,0 +1,59 @@ +{"Command":"Install-monitor-agent","caller":"cmdutils.go:123","fn":"github.com/codefresh-io/venona/venonactl/cmd.extendStoreWithKubeClient","kubeconfig":"/Users/lrochette/.kube/config","lvl":"dbug","msg":"Path to kubeconfig not set, using:","t":"2021-10-11T17:17:52.7148-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - cluster-role-binding.dind-volume-provisioner.vp.yaml","t":"2021-10-11T17:17:53.780767-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - deployment.venona.yaml","t":"2021-10-11T17:17:53.781165-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - pod.network-tester.yaml","t":"2021-10-11T17:17:53.781289-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - secret.venona.yaml","t":"2021-10-11T17:17:53.781354-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template service-account.monitor.yaml","t":"2021-10-11T17:17:53.781409-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - cluster-role-binding.venona.yaml","t":"2021-10-11T17:17:53.782653-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - deployment.app-proxy.yaml","t":"2021-10-11T17:17:53.782722-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template role.monitor.yaml","t":"2021-10-11T17:17:53.782768-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - service-account.app-proxy.yaml","t":"2021-10-11T17:17:53.78358-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - secret.dind-volume-provisioner.vp.yaml","t":"2021-10-11T17:17:53.783669-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - service-account.engine.yaml","t":"2021-10-11T17:17:53.783715-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - cluster-role-binding.app-proxy.yaml","t":"2021-10-11T17:17:53.78376-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - cluster-role.app-proxy.yaml","t":"2021-10-11T17:17:53.783811-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - daemonset.dind-lv-monitor.vp.yaml","t":"2021-10-11T17:17:53.783871-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template rollback-role-binding.monitor.yaml","t":"2021-10-11T17:17:53.78391-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template deployment.monitor.yaml","t":"2021-10-11T17:17:53.784688-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - role.engine.yaml","t":"2021-10-11T17:17:53.785672-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - secret.runtime-attach.yaml","t":"2021-10-11T17:17:53.785724-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - service.app-proxy.yaml","t":"2021-10-11T17:17:53.785759-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - dind-daemon-conf.re.yaml","t":"2021-10-11T17:17:53.785793-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template rolebinding.monitor.yaml","t":"2021-10-11T17:17:53.785825-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template rollback-serviceaccount.monitor.yaml","t":"2021-10-11T17:17:53.786156-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - storageclass.dind-volume-provisioner.vp.yaml","t":"2021-10-11T17:17:53.786432-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - venonaconf.secret.venona.yaml","t":"2021-10-11T17:17:53.78648-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - cluster-role.dind-volume-provisioner.vp.yaml","t":"2021-10-11T17:17:53.786513-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - dind-headless-service.re.yaml","t":"2021-10-11T17:17:53.786548-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - codefresh-certs-server-secret.re.yaml","t":"2021-10-11T17:17:53.786582-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - cron-job.dind-volume-cleanup.vp.yaml","t":"2021-10-11T17:17:53.786644-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - deployment.dind-volume-provisioner.vp.yaml","t":"2021-10-11T17:17:53.786678-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - ingress.app-proxy.yaml","t":"2021-10-11T17:17:53.786712-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - role-binding.engine.yaml","t":"2021-10-11T17:17:53.786745-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - role-binding.re.yaml","t":"2021-10-11T17:17:53.786772-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - role.re.yaml","t":"2021-10-11T17:17:53.786806-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - service-account.dind-volume-provisioner.vp.yaml","t":"2021-10-11T17:17:53.78684-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:165","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Skipping parsing, pattern does not match .*.monitor.yaml - service-account.re.yaml","t":"2021-10-11T17:17:53.786873-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:168","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.ParseTemplates","installer":"monitor-agent","lvl":"dbug","msg":"parsing template service.monitor.yaml","t":"2021-10-11T17:17:53.786901-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template deployment.monitor.yaml \napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: monitor\n namespace: runner\n labels:\n app: runner\n version: 1.6.8\nspec:\n replicas: 1\n strategy:\n type: RollingUpdate\n rollingUpdate:\n maxUnavailable: 50%\n maxSurge: 50%\n selector:\n matchLabels:\n app: monitor\n template:\n metadata:\n labels:\n app: monitor\n version: 1.6.8\n spec:\n serviceAccountName: monitor\n containers:\n - name: monitor\n resources:\n null\n image: quay.io/codefresh/agent:stable\n imagePullPolicy: Always\n env:\n - name: SERVICE_NAME\n value: monitor\n - name: PORT\n value: \"9020\"\n - name: API_TOKEN\n value: 60119b8818d83b4a235631f1.d5c52ad6eeae9dbde77a2bfed56d28dd\n - name: CLUSTER_ID\n value: cf_onprem_eks\n - name: API_URL\n value: https://g.codefresh.io/api/k8s-monitor/events\n - name: ACCOUNT_ID\n value: user\n - name: HELM3\n value: \"false\"\n - name: NAMESPACE\n value: \"runner\"\n - name: NODE_OPTIONS\n value: \"--max_old_space_size=4096\"\n ports:\n - containerPort: 9020\n protocol: TCP\n readinessProbe:\n httpGet:\n path: /api/ping\n port: 9020\n periodSeconds: 5\n timeoutSeconds: 5\n successThreshold: 1\n failureThreshold: 5 \n","t":"2021-10-11T17:17:53.787457-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success deployment.monitor.yaml group=apps","t":"2021-10-11T17:17:53.79346-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template rolebinding.monitor.yaml \nkind: ClusterRoleBinding\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n name: monitor-cluster-reader\n namespace: runner\n labels:\n app: monitor\n version: 1.6.8\nsubjects:\n- kind: ServiceAccount\n namespace: runner\n name: monitor\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: ClusterRole\n name: monitor-cluster-reader","t":"2021-10-11T17:17:53.793542-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success rolebinding.monitor.yaml group=rbac.authorization.k8s.io","t":"2021-10-11T17:17:53.794427-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template rollback-serviceaccount.monitor.yaml \napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: monitor-rollback\n namespace: runner\n annotations:\n \n labels:\n app: monitor\n version: 1.6.8","t":"2021-10-11T17:17:53.794479-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success rollback-serviceaccount.monitor.yaml group=","t":"2021-10-11T17:17:53.794963-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template service.monitor.yaml \napiVersion: v1\nkind: Service\nmetadata:\n name: monitor\n namespace: runner\n labels:\n app: monitor\n version: 1.6.8\nspec:\n type: ClusterIP\n ports:\n - name: \"http\"\n port: 80\n protocol: TCP\n targetPort: 9020\n selector:\n app: monitor\n","t":"2021-10-11T17:17:53.795004-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success service.monitor.yaml group=","t":"2021-10-11T17:17:53.796751-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template service-account.monitor.yaml \napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: monitor\n namespace: runner\n annotations:\n \n labels:\n app: monitor\n version: 1.6.8\n","t":"2021-10-11T17:17:53.796886-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success service-account.monitor.yaml group=","t":"2021-10-11T17:17:53.797055-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template role.monitor.yaml \nkind: ClusterRole\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n name: monitor-cluster-reader\n namespace: runner\n labels:\n app: monitor\n version: 1.6.8\nrules:\n- apiGroups:\n - \"\"\n resources: [\"*\"]\n verbs:\n - get\n - list\n - watch\n - create\n - delete\n- apiGroups:\n - \"\"\n resources: [\"pods\"]\n verbs:\n - get\n - list\n - watch\n - create\n - deletecollection\n- apiGroups:\n - extensions\n resources: [\"*\"]\n verbs:\n - get\n - list\n - watch\n- apiGroups:\n - apps\n resources: [\"*\"]\n verbs:\n - get\n - list\n - watch","t":"2021-10-11T17:17:53.797091-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success role.monitor.yaml group=rbac.authorization.k8s.io","t":"2021-10-11T17:17:53.797809-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:196","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"Deserializing template rollback-role-binding.monitor.yaml \nkind: ClusterRoleBinding\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n name: monitor-rollback\n namespace: runner\n labels:\n app: monitor\n version: 1.6.8\nsubjects:\n - kind: ServiceAccount\n namespace: runner\n name: monitor-rollback\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: ClusterRole\n name: cluster-admin","t":"2021-10-11T17:17:53.797852-07:00"} +{"Command":"Install-monitor-agent","caller":"helper.go:202","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.KubeObjectsFromTemplates","installer":"monitor-agent","lvl":"dbug","msg":"deserializing template success rollback-role-binding.monitor.yaml group=rbac.authorization.k8s.io","t":"2021-10-11T17:17:53.798014-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"ClusterRoleBinding \"monitor-rollback\" created","t":"2021-10-11T17:17:54.170612-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"Deployment \"monitor\" created","t":"2021-10-11T17:17:54.525298-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"ClusterRoleBinding \"monitor-cluster-reader\" created","t":"2021-10-11T17:17:54.6199-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"ServiceAccount \"monitor-rollback\" created","t":"2021-10-11T17:17:54.719771-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"Service \"monitor\" created","t":"2021-10-11T17:17:54.83388-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"ServiceAccount \"monitor\" created","t":"2021-10-11T17:17:54.923643-07:00"} +{"Command":"Install-monitor-agent","caller":"plugin.go:273","fn":"github.com/codefresh-io/venona/venonactl/pkg/plugins.install","installer":"monitor-agent","lvl":"dbug","msg":"ClusterRole \"monitor-cluster-reader\" created","t":"2021-10-11T17:17:55.019581-07:00"} +{"Command":"Install-monitor-agent","caller":"install-monitor.go:126","fn":"github.com/codefresh-io/venona/venonactl/cmd.glob..func4","lvl":"info","msg":"Monitor agent installation completed Successfully","t":"2021-10-11T17:17:55.019676-07:00"} From 76745a062c456572412df082b06092f992dc2609 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Oct 2021 18:07:22 -0700 Subject: [PATCH 17/37] #402: fix conflict between CR_ACTION to the step and ACTION to the script --- incubating/service-now/lib/snow.py | 2 +- incubating/service-now/step.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 95121d9f5..55700c135 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -194,7 +194,7 @@ def checkSysid(sysid): def main(): global DEBUG - ACTION = os.getenv('CR_ACTION', 'createCR').lower() + ACTION = os.getenv('ACTION').lower() USER = os.getenv('SN_USER') PASSWORD = os.getenv('SN_PASSWORD') INSTANCE = os.getenv('SN_INSTANCE') diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index 59bd42e5c..ab0513526 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -153,7 +153,7 @@ spec: title: Use REST API to close the CR image: lrochette/service-now:1.1.0 environment: - - CR_ACTION=closeCR + - ACTION=closecr [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] @@ -164,7 +164,7 @@ spec: title: Use REST API to close the CR image: lrochette/service-now:1.1.0 environment: - - CR_ACTION=updateCR + - ACTION=updatecr [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] @@ -175,7 +175,7 @@ spec: title: Use REST API to create a CR image: lrochette/service-now:1.1.0 environment: - - CR_ACTION=createCR + - ACTION=createcr [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] @@ -193,7 +193,7 @@ spec: title: ServiceNow callback setup image: lrochette/service-now:1.1.0 environment: - - CR_ACTION=callback + - ACTION=callback [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] From cf4ef11b0d8a687fb136d40db146e7d3cf6057e3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 12 Oct 2021 08:32:09 -0700 Subject: [PATCH 18/37] more debug info --- incubating/service-now/lib/snow.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 55700c135..aa0e203c6 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -201,8 +201,11 @@ def main(): DATA = os.getenv('CR_DATA') #DEBUG = True if os.getenv('debug', "false").lower == "true" else False + if DEBUG: + print(f"ACTION: {ACTION}") + print(f"DATA: {data}") + if ACTION == "createcr": - createChangeRequest(user=USER, password=PASSWORD, baseUrl=getBaseUrl(instance=INSTANCE), @@ -219,7 +222,6 @@ def main(): CR_SYSID= os.getenv('CR_SYSID') CODE=os.getenv('CR_CLOSE_CODE') NOTES=os.getenv('CR_CLOSE_NOTES') - checkSysid(CR_SYSID) closeChangeRequest( From 51f83ddab974d4987536c0142536ed8aaacc2af1 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 12 Oct 2021 08:39:10 -0700 Subject: [PATCH 19/37] #402: more debug info --- incubating/service-now/lib/snow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index aa0e203c6..a8fa23f77 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -203,8 +203,8 @@ def main(): if DEBUG: print(f"ACTION: {ACTION}") - print(f"DATA: {data}") - + print(f"DATA: {DATA}") + if ACTION == "createcr": createChangeRequest(user=USER, password=PASSWORD, From 10087b3eb2271ca935b51d1042635c3930563862 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 12 Oct 2021 09:14:59 -0700 Subject: [PATCH 20/37] #402: push overwrite of env variable to the end of the block --- incubating/service-now/lib/snow.py | 8 +++++--- incubating/service-now/step.yaml | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index a8fa23f77..3286d690c 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -140,7 +140,7 @@ def closeChangeRequest(user, password, baseUrl, sysid, code, notes, data): # Fields required are pasted in the data def updateChangeRequest(user, password, baseUrl, sysid, data): if DEBUG: - print("Entering closeChangeRequest:") + print("Entering updateChangeRequest:") print(f"DATA: {data}") if (bool(data)): crBody=json.loads(data) @@ -202,8 +202,10 @@ def main(): #DEBUG = True if os.getenv('debug', "false").lower == "true" else False if DEBUG: - print(f"ACTION: {ACTION}") - print(f"DATA: {DATA}") + printf("Starting ServiceNow pugin for Codefresh") + print(f" ACTION: {ACTION}") + print(f" DATA: {DATA}") + print("---") if ACTION == "createcr": createChangeRequest(user=USER, diff --git a/incubating/service-now/step.yaml b/incubating/service-now/step.yaml index ab0513526..5ea7defd4 100644 --- a/incubating/service-now/step.yaml +++ b/incubating/service-now/step.yaml @@ -153,10 +153,10 @@ spec: title: Use REST API to close the CR image: lrochette/service-now:1.1.0 environment: - - ACTION=closecr [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] + - ACTION=closecr [[ end ]] [[ if eq .Arguments.CR_ACTION "updateCR" ]] updateCR: @@ -164,10 +164,10 @@ spec: title: Use REST API to close the CR image: lrochette/service-now:1.1.0 environment: - - ACTION=updatecr [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] + - ACTION=updatecr [[ end ]] [[ if eq .Arguments.CR_ACTION "createCR" ]] createCR: @@ -175,10 +175,10 @@ spec: title: Use REST API to create a CR image: lrochette/service-now:1.1.0 environment: - - ACTION=createcr [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] + - ACTION=createcr createAnnotation: name: Assign CR_NUMBER as annotation image: codefresh/cli @@ -193,10 +193,10 @@ spec: title: ServiceNow callback setup image: lrochette/service-now:1.1.0 environment: - - ACTION=callback [[ range $key, $val := .Arguments ]] - '[[ $key ]]=[[ $val ]]' [[- end ]] + - ACTION=callback [[ end ]] delimiters: left: '[[' From 3b8f6424929a1936e8277aa5651262b9aa9e85cf Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 12 Oct 2021 09:36:03 -0700 Subject: [PATCH 21/37] #402: minor debug info fixes --- incubating/service-now/lib/snow.py | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/incubating/service-now/lib/snow.py b/incubating/service-now/lib/snow.py index 3286d690c..b1aa732a7 100644 --- a/incubating/service-now/lib/snow.py +++ b/incubating/service-now/lib/snow.py @@ -3,7 +3,7 @@ import json import requests -DEBUG = True +DEBUG = False API_NAMESPACE=409723 env_file_path = "/meta/env_vars_to_export" @@ -25,12 +25,12 @@ def processCallbackResponse(response): def processCreateChangeRequestResponse(response): - - print("Processing answer from CR creation REST call") - print(" Change Request returned code %s" % (response.status_code)) + if DEBUG: + print("Processing answer from CR creation REST call") + print(" Change Request returned code %s" % (response.status_code)) if (response.status_code != 200 and response.status_code != 201): print(" Change Request creation failed with code %s" % (response.status_code)) - print(" Error: " + response.text) + print(" ERROR: " + response.text) return response.status_code print(" Change Request creation successful") @@ -38,9 +38,11 @@ def processCreateChangeRequestResponse(response): CR_NUMBER=data["result"]["number"] CR_SYSID=data["result"]["sys_id"] FULL_JSON=json.dumps(data, indent=2) - print(f" Change Request Number: {CR_NUMBER}") - print(f" Change Request sys_id: {CR_SYSID}") - print(" Change Request full answer:\n" + FULL_JSON) + + print(f" Change Request Number: {CR_NUMBER}") + print(f" Change Request sys_id: {CR_SYSID}") + if DEBUG: + print( " Change Request full answer:\n" + FULL_JSON) if os.path.exists(env_file_path): env_file = open(env_file_path, "a") @@ -87,16 +89,16 @@ def createChangeRequest(user, password, baseUrl, data): def processModifyChangeRequestResponse(response, action): - print("Processing answer from CR %s REST call" %(action)) - print("Close Change Request returned code %s" % (response.status_code)) + if DEBUG: + print("Processing answer from CR %s REST call" %(action)) + print(" %s Change Request returned code %s" % (action,response.status_code)) if (response.status_code != 200 and response.status_code != 201): - print("%s Change Request creation failed with code %s" % (action, response.status_code)) - print("Error: " + response.text) + print(" %s Change Request creation failed with code %s" % (action, response.status_code)) + print(" ERROR: " + response.text) return response.status_code - print("%s Change Request creation successful" %(action)) + print(" %s Change Request successful" %(action)) data=response.json() # json.loads(response.text) - FULL_JSON=json.dumps(data, indent=2) if (action == "close" ): @@ -106,7 +108,7 @@ def processModifyChangeRequestResponse(response, action): jsonVar="CR_UPDATE_FULL_JSON" jsonFileName="/codefresh/volume/servicenow-cr-update.json" else: - print("ERROR: action unknonw. Should not be here. Error should have been caught earlier") + print("ERROR: action unknown. Should not be here. Error should have been caught earlier") if os.path.exists(env_file_path): env_file = open(env_file_path, "a") env_file.write(f"{jsonVar}=/codefresh/volume/servicenow-cr-close.json\n") @@ -199,10 +201,10 @@ def main(): PASSWORD = os.getenv('SN_PASSWORD') INSTANCE = os.getenv('SN_INSTANCE') DATA = os.getenv('CR_DATA') - #DEBUG = True if os.getenv('debug', "false").lower == "true" else False + DEBUG = True if os.getenv('DEBUG', "false").lower == "true" else False if DEBUG: - printf("Starting ServiceNow pugin for Codefresh") + print("Starting ServiceNow plugin for Codefresh") print(f" ACTION: {ACTION}") print(f" DATA: {DATA}") print("---") From bf26d3729f30cb5cc4021b467da3a9097ce0ffa3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 12 Oct 2021 09:53:12 -0700 Subject: [PATCH 22/37] #402: change DEBUG to boolean --- incubating/.DS_Store | Bin 6148 -> 6148 bytes incubating/service-now/step.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/incubating/.DS_Store b/incubating/.DS_Store index 4e0d5217f61eab7ea9e574b701e9abeff72a5beb..9143ca79292d60b7020f526bd93851cb2d73de8d 100644 GIT binary patch delta 136 zcmZoMXfc@J&&akhU^g=(+h!gXcP4RehGK?Ph9ZVChD?TJAWN4ak0GC-e6k#iEE@+G z2Ny5bWJi`{Sq@GP&UgWd>S{wnLmdSZLyKA+g=$M910dVjZ1O=CQ)L_ml?4~&<>cq3 RGcYhPPApusnVsV=KLF7x9{d0R delta 32 ocmZoMXfc@J&&aYdU^g=(%Vr)Hcc#f1?DID^h%#