From bc69946a1bd72e6e6d5d2b8782c79a14e5e396d3 Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Mon, 8 Feb 2021 16:17:38 -0600 Subject: [PATCH 1/4] ServiceNow Pack Update Proposed Revision Number: 0.5.0 Objective: Update to pack to prevent deprecation warnings from use of the old style API calls by replacing them with the [PySNow](https://pysnow.readthedocs.io/) library [Resource](https://pysnow.readthedocs.io/en/latest/api/resource.html) APIs. Scope: This update applies to the following *actions* of the [Stackstorm ServiceNow pack](https://github.com/StackStorm-Exchange/stackstorm-servicenow): * get * create * update * delete None of the "custom" methods were updated. Approach/Implementation: A new pack-level (in `config.schema.yaml`) boolean configuration flag named `use_new_service_now_api` is introduced. When enabled (checked), a new code block in each of the specified actions above is executed that uses the Resource APIs. Otherwise, the existing module code is used. In addition, the `get` module/method includes one new _optional_ *array* (list) parameter: `fields`. This parameter accepts a comma-separated list of field names for the specified ServiceNow table and returns only those fields in the response (result set) for each record. Note: This attribute applies *ONLY* to the new API. --- .gitignore | 1 - CHANGES.md | 4 ++++ actions/delete.py | 7 +++++++ actions/get.py | 15 ++++++++++++++- actions/get.yaml | 4 ++++ actions/insert.py | 7 +++++++ actions/update.py | 7 +++++++ config.schema.yaml | 6 ++++++ pack.yaml | 2 +- 9 files changed, 50 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 72364f9..a76c9cc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/CHANGES.md b/CHANGES.md index 1da27e0..ae21722 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Change Log +## 0.5.0 +- Add support of PySNow Resource API via `use_new_service_now_api` flag. +- Add support for returning specific fields on "get". + ## 0.4.0 - Add support for upload attachment and get attachment metadata diff --git a/actions/delete.py b/actions/delete.py index f285df5..05c6b95 100755 --- a/actions/delete.py +++ b/actions/delete.py @@ -3,6 +3,13 @@ class DeleteAction(BaseAction): def run(self, table, sysid): + # If using new ServiceNew API... + if self.config['use_new_service_now_api'] == True: + client = self.client + resource = client.resource(api_path="/table/{0}".format(table)) + response = resource.delete(query={"sys_id": sysid}) # pylint: disable=no-member + return response + s = self.client r = s.query(table=table, query={'sys_id': sysid}) # pylint: disable=no-member response = r.delete() # pylint: disable=no-member diff --git a/actions/get.py b/actions/get.py index 8dba052..28023d1 100755 --- a/actions/get.py +++ b/actions/get.py @@ -2,7 +2,20 @@ class GetAction(BaseAction): - def run(self, table, query): + def run(self, table, query, fields=[]): + # If using new ServiceNew API... + if self.config['use_new_service_now_api'] == True: + client = self.client + resource = client.resource(api_path="/table/{0}".format(table)) + if not fields: + response = resource.get(query=query) + else: + response = resource.get(query=query, fields=fields) + output = [] + for each_item in response.all(): + output.append(each_item) + return output + s = self.client r = s.query(table=table, query=query) # pylint: disable=no-member response = r.get_all() # pylint: disable=no-member diff --git a/actions/get.yaml b/actions/get.yaml index 3877d9e..69ea30e 100755 --- a/actions/get.yaml +++ b/actions/get.yaml @@ -13,3 +13,7 @@ parameters: type: "object" description: "Structured query for SN data" required: true + fields: + type: "array" + description: "Comma-separated list of fields to return. ***New API only***" + required: false \ No newline at end of file diff --git a/actions/insert.py b/actions/insert.py index 49b8fde..c88351c 100755 --- a/actions/insert.py +++ b/actions/insert.py @@ -3,6 +3,13 @@ class InsertAction(BaseAction): def run(self, table, payload): + # If using new ServiceNew API... + if self.config['use_new_service_now_api'] == True: + client = self.client + resource = client.resource(api_path="/table/{0}".format(table)) + response = resource.create(payload=payload) # pylint: disable=no-member + return response + s = self.client response = s.insert(table=table, payload=payload) # pylint: disable=no-member return response diff --git a/actions/update.py b/actions/update.py index 8033dae..0f16a93 100755 --- a/actions/update.py +++ b/actions/update.py @@ -3,6 +3,13 @@ class UpdateAction(BaseAction): def run(self, table, payload, sysid): + # If using new ServiceNew API... + if self.config['use_new_service_now_api'] == True: + client = self.client + resource = client.resource(api_path="/table/{0}".format(table)) + response = resource.update(query={"sys_id": sysid}, payload=payload) # pylint: disable=no-member + return response + s = self.client r = s.query(table=table, query={'sys_id': sysid}) # pylint: disable=no-member response = r.update(payload) # pylint: disable=no-member diff --git a/config.schema.yaml b/config.schema.yaml index 7feef28..177b3bc 100755 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -17,3 +17,9 @@ description: "ServiceNow options that will be passed to all requests" type: object required: false + use_new_service_now_api: + description: "Use the new ServiceNow APIs to avoid deprecation warnings." + type: "boolean" + secret: false + required: false + default: true diff --git a/pack.yaml b/pack.yaml index e34d6d5..8dc4f7e 100755 --- a/pack.yaml +++ b/pack.yaml @@ -5,7 +5,7 @@ description: ServiceNow Integration Pack keywords: - servicenow - incident management -version: 0.4.0 +version: 0.5.0 python_versions: - "2" - "3" From 9299c57748c01ee6e0a8bb1da40c8161703d185d Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Wed, 23 Mar 2022 12:19:44 -0500 Subject: [PATCH 2/4] Replace 'if self.config['use_new_service_now_api'] == True' with 'if self.config['use_new_service_now_api']' from CI/CD errors. --- actions/delete.py | 2 +- actions/get.py | 2 +- actions/insert.py | 2 +- actions/update.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/delete.py b/actions/delete.py index 05c6b95..7bc796b 100755 --- a/actions/delete.py +++ b/actions/delete.py @@ -4,7 +4,7 @@ class DeleteAction(BaseAction): def run(self, table, sysid): # If using new ServiceNew API... - if self.config['use_new_service_now_api'] == True: + if self.config['use_new_service_now_api']: client = self.client resource = client.resource(api_path="/table/{0}".format(table)) response = resource.delete(query={"sys_id": sysid}) # pylint: disable=no-member diff --git a/actions/get.py b/actions/get.py index 28023d1..b39b963 100755 --- a/actions/get.py +++ b/actions/get.py @@ -4,7 +4,7 @@ class GetAction(BaseAction): def run(self, table, query, fields=[]): # If using new ServiceNew API... - if self.config['use_new_service_now_api'] == True: + if self.config['use_new_service_now_api']: client = self.client resource = client.resource(api_path="/table/{0}".format(table)) if not fields: diff --git a/actions/insert.py b/actions/insert.py index c88351c..86331a8 100755 --- a/actions/insert.py +++ b/actions/insert.py @@ -4,7 +4,7 @@ class InsertAction(BaseAction): def run(self, table, payload): # If using new ServiceNew API... - if self.config['use_new_service_now_api'] == True: + if self.config['use_new_service_now_api']: client = self.client resource = client.resource(api_path="/table/{0}".format(table)) response = resource.create(payload=payload) # pylint: disable=no-member diff --git a/actions/update.py b/actions/update.py index 0f16a93..d6b0309 100755 --- a/actions/update.py +++ b/actions/update.py @@ -4,7 +4,7 @@ class UpdateAction(BaseAction): def run(self, table, payload, sysid): # If using new ServiceNew API... - if self.config['use_new_service_now_api'] == True: + if self.config['use_new_service_now_api']: client = self.client resource = client.resource(api_path="/table/{0}".format(table)) response = resource.update(query={"sys_id": sysid}, payload=payload) # pylint: disable=no-member From dbbc0e695a9a68b6ff19877a1cf70f179f7613cf Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Wed, 11 May 2022 08:42:55 -0500 Subject: [PATCH 3/4] Update actions/get.yaml Co-authored-by: Amanda McGuinness --- actions/get.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/get.yaml b/actions/get.yaml index 69ea30e..4b01f74 100644 --- a/actions/get.yaml +++ b/actions/get.yaml @@ -15,5 +15,5 @@ parameters: required: true fields: type: "array" - description: "Comma-separated list of fields to return. ***New API only***" + description: "Comma-separated list of fields to return. ***Only supported when config parameter use_new_service_now_api is true***" required: false \ No newline at end of file From 8022a868ee09605e49af741a9b3c0010931f76f8 Mon Sep 17 00:00:00 2001 From: TimothyDJones Date: Wed, 19 Oct 2022 16:26:51 -0500 Subject: [PATCH 4/4] Update pack references to version 1.5.0. --- CHANGES.md | 8 ++++---- pack.yaml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7c100e6..2adc337 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,14 +1,14 @@ # Change Log ======= +## 1.5.0 +- Add support of PySNow Resource API via `use_new_service_now_api` flag. +- Add support for returning specific fields on "get". + ## 1.0.0 * Drop Python 2.7 support -## 0.5.0 -- Add support of PySNow Resource API via `use_new_service_now_api` flag. -- Add support for returning specific fields on "get". - ## 0.4.0 - Add support for upload attachment and get attachment metadata diff --git a/pack.yaml b/pack.yaml index 5beadab..696f9b8 100755 --- a/pack.yaml +++ b/pack.yaml @@ -5,7 +5,7 @@ description: ServiceNow Integration Pack keywords: - servicenow - incident management -version: 1.0.0 +version: 1.5.0 python_versions: - "3" author: James Fryman