From 1ff3afafe6a73d066b202046617b3022211453c5 Mon Sep 17 00:00:00 2001 From: israelpolishook Date: Sun, 29 Oct 2023 13:45:13 +0200 Subject: [PATCH 1/6] fix handle values bug [Google Sheets] --- .../Integrations/GoogleSheets/GoogleSheets.py | 23 +++++++++++++------ .../GoogleSheets/GoogleSheets_test.py | 5 +++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py index 52a6a407902a..0b9d77aa69a4 100644 --- a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py +++ b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py @@ -1,3 +1,4 @@ +import ast import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 import json @@ -105,16 +106,24 @@ def handle_values_input(values: str) -> list: Returns: (list) A list of lists of the values for this example [[1,2,3],[4,5,6]...] """ - if not values: - raise ValueError('Wrong format of values entered, please check the documentation') - split_by_brackets = re.findall("\[(.*?)\]", values) - res_for_values_req = [] - for element in split_by_brackets: - res_for_values_req.append(element.split(",")) - if not res_for_values_req: + # Validate that the user has entered valid values + if not values or not re.findall("\[(.*?)\]", values): raise ValueError('Wrong format of values entered, please check the documentation') + # Converting the values the user entered into an array of arrays + if isinstance(values_as_array := ast.literal_eval(values), list) and ( + not values_as_array or not all(isinstance(item, list) for item in values_as_array)): + values_as_array = [values_as_array] + + # Handling all values including the `None` value to be string + res_for_values_req = [] + for element in values_as_array: + if not element: + res_for_values_req.append(['']) + continue + res_for_values_req.append([str(value) for value in element]) + return res_for_values_req diff --git a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets_test.py b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets_test.py index b270f943ccfa..5d64cf9d8698 100644 --- a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets_test.py +++ b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets_test.py @@ -134,9 +134,12 @@ def test_create_list_id_title(): handle_values_input_parametrized = [ ("[1,2,3],[4,5,6]", [['1', '2', '3'], ['4', '5', '6']]), + ("[1,'test, for test',3],[4,5,6]", [['1', 'test, for test', '3'], ['4', '5', '6']]), + ("[1,[2],3],[4,5,6]", [['1', '[2]', '3'], ['4', '5', '6']]), ("[1,2]", [['1', '2']]), ("[1]", [['1']]), - ("[]", [['']]) + ("[]", [['']]), + ("[[1,2,3],[4,5,6]]", [['1', '2', '3'], ['4', '5', '6']]) ] From d43b3cfe9e3e27f3499b3bf1fbe8f2c5fde59b94 Mon Sep 17 00:00:00 2001 From: israelpolishook Date: Sun, 29 Oct 2023 14:06:20 +0200 Subject: [PATCH 2/6] update RN --- Packs/GoogleSheets/ReleaseNotes/1_0_35.md | 6 ++++++ Packs/GoogleSheets/pack_metadata.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Packs/GoogleSheets/ReleaseNotes/1_0_35.md diff --git a/Packs/GoogleSheets/ReleaseNotes/1_0_35.md b/Packs/GoogleSheets/ReleaseNotes/1_0_35.md new file mode 100644 index 000000000000..52c26e5eb31f --- /dev/null +++ b/Packs/GoogleSheets/ReleaseNotes/1_0_35.md @@ -0,0 +1,6 @@ + +#### Integrations + +##### Google Sheets + +- Fixed an issue where the ***google-sheets-value-append*** command incorrectly appended values to a spreadsheet. diff --git a/Packs/GoogleSheets/pack_metadata.json b/Packs/GoogleSheets/pack_metadata.json index 5e1bc56a5d41..7bf28c0c2a74 100644 --- a/Packs/GoogleSheets/pack_metadata.json +++ b/Packs/GoogleSheets/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Google Sheets", "description": "The Google Sheets API is a RESTful interface that lets you read and modify a spreadsheet's data. The most common uses of this API include the following tasks- create spreadsheets, read and write spreadsheets cells, update spreadsheet formatting", "support": "xsoar", - "currentVersion": "1.0.34", + "currentVersion": "1.0.35", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", From c19924e4836e158a22926d60dde27edde86b328f Mon Sep 17 00:00:00 2001 From: israelpolishook Date: Sun, 29 Oct 2023 14:10:59 +0200 Subject: [PATCH 3/6] update Docker and RN --- Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.yml | 2 +- Packs/GoogleSheets/ReleaseNotes/1_0_35.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.yml b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.yml index 899b02a1f86a..b71650a00585 100644 --- a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.yml +++ b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.yml @@ -665,7 +665,7 @@ script: - contextPath: GoogleSheets.Spreadsheet.updatedSpreadsheet.sheets.title description: Sheet title. type: String - dockerimage: demisto/googleapi-python3:1.0.0.77375 + dockerimage: demisto/googleapi-python3:1.0.0.78508 runonce: false script: "-" subtype: python3 diff --git a/Packs/GoogleSheets/ReleaseNotes/1_0_35.md b/Packs/GoogleSheets/ReleaseNotes/1_0_35.md index 52c26e5eb31f..3b4c89190c7c 100644 --- a/Packs/GoogleSheets/ReleaseNotes/1_0_35.md +++ b/Packs/GoogleSheets/ReleaseNotes/1_0_35.md @@ -2,5 +2,5 @@ #### Integrations ##### Google Sheets - +- Updated the Docker image to: *demisto/googleapi-python3:1.0.0.78508*. - Fixed an issue where the ***google-sheets-value-append*** command incorrectly appended values to a spreadsheet. From 02af2c3e750252375bb68accf32c1ab32a8945fc Mon Sep 17 00:00:00 2001 From: israelpolishook Date: Sun, 5 Nov 2023 14:51:33 +0200 Subject: [PATCH 4/6] flake8 --- .../Integrations/GoogleSheets/GoogleSheets.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py index 0b9d77aa69a4..e4507afbbaad 100644 --- a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py +++ b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py @@ -109,18 +109,22 @@ def handle_values_input(values: str) -> list: # Validate that the user has entered valid values if not values or not re.findall("\[(.*?)\]", values): - raise ValueError('Wrong format of values entered, please check the documentation') + raise ValueError( + "Wrong format of values entered, please check the documentation" + ) # Converting the values the user entered into an array of arrays if isinstance(values_as_array := ast.literal_eval(values), list) and ( - not values_as_array or not all(isinstance(item, list) for item in values_as_array)): - values_as_array = [values_as_array] + not values_as_array + or not all(isinstance(item, list) for item in values_as_array) + ): + values_as_array = [values_as_array] # Handling all values including the `None` value to be string res_for_values_req = [] for element in values_as_array: if not element: - res_for_values_req.append(['']) + res_for_values_req.append([""]) continue res_for_values_req.append([str(value) for value in element]) From da2fd05dc04fc3faa9a0b20d231efef7c01b2ba4 Mon Sep 17 00:00:00 2001 From: Content Bot Date: Mon, 6 Nov 2023 08:08:03 +0000 Subject: [PATCH 5/6] Bump pack from version GoogleSheets to 1.0.36. --- Packs/GoogleSheets/ReleaseNotes/1_0_36.md | 6 ++++++ Packs/GoogleSheets/pack_metadata.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Packs/GoogleSheets/ReleaseNotes/1_0_36.md diff --git a/Packs/GoogleSheets/ReleaseNotes/1_0_36.md b/Packs/GoogleSheets/ReleaseNotes/1_0_36.md new file mode 100644 index 000000000000..3b4c89190c7c --- /dev/null +++ b/Packs/GoogleSheets/ReleaseNotes/1_0_36.md @@ -0,0 +1,6 @@ + +#### Integrations + +##### Google Sheets +- Updated the Docker image to: *demisto/googleapi-python3:1.0.0.78508*. +- Fixed an issue where the ***google-sheets-value-append*** command incorrectly appended values to a spreadsheet. diff --git a/Packs/GoogleSheets/pack_metadata.json b/Packs/GoogleSheets/pack_metadata.json index 7bf28c0c2a74..b4b7262fd3c6 100644 --- a/Packs/GoogleSheets/pack_metadata.json +++ b/Packs/GoogleSheets/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Google Sheets", "description": "The Google Sheets API is a RESTful interface that lets you read and modify a spreadsheet's data. The most common uses of this API include the following tasks- create spreadsheets, read and write spreadsheets cells, update spreadsheet formatting", "support": "xsoar", - "currentVersion": "1.0.35", + "currentVersion": "1.0.36", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", From d26eebbef5e58e865a151b7b7cc782ebefa40f79 Mon Sep 17 00:00:00 2001 From: israelpolishook Date: Mon, 6 Nov 2023 12:39:04 +0200 Subject: [PATCH 6/6] add docstring to "handle_values_input" function --- .../Integrations/GoogleSheets/GoogleSheets.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py index e4507afbbaad..f84c9fa8ed70 100644 --- a/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py +++ b/Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py @@ -114,10 +114,16 @@ def handle_values_input(values: str) -> list: ) # Converting the values the user entered into an array of arrays - if isinstance(values_as_array := ast.literal_eval(values), list) and ( - not values_as_array - or not all(isinstance(item, list) for item in values_as_array) - ): + values_as_array = ast.literal_eval(values) + + # Checks whether the given values are a singular empty list, such as "[]". + # if that's the case, it will convert it to [[]] (a list of lists). + if isinstance(values_as_array, list) and len(values_as_array) == 0: + values_as_array = [values_as_array] + + # Checks whether the given values are a single non-empty list, e.g., "[1,2,3]". + # in such a case, it will convert it to [[1,2,3]] (a list of lists). + elif not all(isinstance(item, list) for item in values_as_array): values_as_array = [values_as_array] # Handling all values including the `None` value to be string