From e3dc5d779df1dc577a17fff26289851a25523559 Mon Sep 17 00:00:00 2001 From: John Cook Date: Fri, 27 Jan 2023 22:30:46 +0000 Subject: [PATCH 1/5] Added test coverage to check behaviour when there are no webhooks defined --- .../targets/meraki_webhook/tasks/tests.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/integration/targets/meraki_webhook/tasks/tests.yml b/tests/integration/targets/meraki_webhook/tasks/tests.yml index ae4f9816..c4efbf5f 100644 --- a/tests/integration/targets/meraki_webhook/tasks/tests.yml +++ b/tests/integration/targets/meraki_webhook/tasks/tests.yml @@ -17,6 +17,22 @@ net_name: '{{test_net_name}}' type: appliance + - name: Query for any webhooks expecting None + meraki_webhook: + auth_key: '{{auth_key}}' + state: query + org_name: '{{test_org_name}}' + net_name: '{{test_net_name}}' + register: query_none + + - debug: + var: query_none + + - assert: + that: + - query_none is not changed + - query_none.data[0] is not defined + - name: Create webhook with check mode meraki_webhook: auth_key: '{{auth_key}}' From af210310e300e6498ae7744536a10f0a018fc4f2 Mon Sep 17 00:00:00 2001 From: John Cook Date: Fri, 27 Jan 2023 22:38:51 +0000 Subject: [PATCH 2/5] removed hard coded list subscript to make sanitize_no_log_values cope with however many items are in the list --- plugins/modules/meraki_webhook.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/modules/meraki_webhook.py b/plugins/modules/meraki_webhook.py index 31252818..4f76f633 100644 --- a/plugins/modules/meraki_webhook.py +++ b/plugins/modules/meraki_webhook.py @@ -210,9 +210,13 @@ def sanitize_no_log_values(meraki): except KeyError: pass try: - meraki.result["data"][0][ - "shared_secret" - ] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" + i=0 + while i < len(meraki.result["data"]): + meraki.result["data"][i][ + "shared_secret" + ] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" + i += 1 + except KeyError: pass try: From 92a2efcf1998879044a3cc7e032fe14704014e68 Mon Sep 17 00:00:00 2001 From: John Cook Date: Fri, 27 Jan 2023 22:51:11 +0000 Subject: [PATCH 3/5] resolved linting and sanity errors --- plugins/modules/meraki_webhook.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/meraki_webhook.py b/plugins/modules/meraki_webhook.py index 4f76f633..f214361d 100644 --- a/plugins/modules/meraki_webhook.py +++ b/plugins/modules/meraki_webhook.py @@ -210,13 +210,13 @@ def sanitize_no_log_values(meraki): except KeyError: pass try: - i=0 + i = 0 while i < len(meraki.result["data"]): - meraki.result["data"][i][ - "shared_secret" - ] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" - i += 1 - + meraki.result["data"][i][ + "shared_secret" + ] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" + i += 1 + except KeyError: pass try: From 12fa18681d48ccd5a41b0e8e652ddb9ea5b3c90a Mon Sep 17 00:00:00 2001 From: John Cook Date: Mon, 30 Jan 2023 08:40:11 +0000 Subject: [PATCH 4/5] Added changelog fragment --- .../fragments/Resolve_meraki_webhook_fail_when_none_defined.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml diff --git a/changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml b/changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml new file mode 100644 index 00000000..1c50947e --- /dev/null +++ b/changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml @@ -0,0 +1,2 @@ +bugfix: + - Resolved an issue where an empty response from the API triggered an exception in module meraki_webhook \ No newline at end of file From 16c45a7093fb6f1e8e99755792205ca1fa400944 Mon Sep 17 00:00:00 2001 From: John Cook Date: Mon, 30 Jan 2023 11:33:14 +0000 Subject: [PATCH 5/5] refactored patch to correctly deal with the variety of types --- ...ve_meraki_webhook_fail_when_none_defined.yml | 2 ++ ...ve_meraki_webhook_fail_when_none_defined.yml | 2 -- plugins/modules/meraki_webhook.py | 9 +++------ .../targets/meraki_webhook/tasks/tests.yml | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/433_Resolve_meraki_webhook_fail_when_none_defined.yml delete mode 100644 changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml diff --git a/changelogs/fragments/433_Resolve_meraki_webhook_fail_when_none_defined.yml b/changelogs/fragments/433_Resolve_meraki_webhook_fail_when_none_defined.yml new file mode 100644 index 00000000..10d14e21 --- /dev/null +++ b/changelogs/fragments/433_Resolve_meraki_webhook_fail_when_none_defined.yml @@ -0,0 +1,2 @@ +bugfixes: + - Resolved an issue where an empty response from the API triggered an exception in module meraki_webhook (https://github.com/CiscoDevNet/ansible-meraki/issues/433) \ No newline at end of file diff --git a/changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml b/changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml deleted file mode 100644 index 1c50947e..00000000 --- a/changelogs/fragments/Resolve_meraki_webhook_fail_when_none_defined.yml +++ /dev/null @@ -1,2 +0,0 @@ -bugfix: - - Resolved an issue where an empty response from the API triggered an exception in module meraki_webhook \ No newline at end of file diff --git a/plugins/modules/meraki_webhook.py b/plugins/modules/meraki_webhook.py index f214361d..95babb90 100644 --- a/plugins/modules/meraki_webhook.py +++ b/plugins/modules/meraki_webhook.py @@ -210,14 +210,11 @@ def sanitize_no_log_values(meraki): except KeyError: pass try: - i = 0 - while i < len(meraki.result["data"]): - meraki.result["data"][i][ + for i in meraki.result['data']: + i[ "shared_secret" ] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" - i += 1 - - except KeyError: + except (KeyError, TypeError): pass try: meraki.result["data"]["shared_secret"] = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" diff --git a/tests/integration/targets/meraki_webhook/tasks/tests.yml b/tests/integration/targets/meraki_webhook/tasks/tests.yml index c4efbf5f..4ce573cc 100644 --- a/tests/integration/targets/meraki_webhook/tasks/tests.yml +++ b/tests/integration/targets/meraki_webhook/tasks/tests.yml @@ -75,6 +75,23 @@ - set_fact: webhook_id: '{{create_one.data.id}}' + - name: Query all webhooks expecting 1 + meraki_webhook: + auth_key: '{{auth_key}}' + state: query + org_name: '{{test_org_name}}' + net_name: '{{test_net_name}}' + register: query_one + + - debug: + var: query_one + + - assert: + that: + - query_one.data is defined + - query_one.data[0] is defined + - query_one.data[1] is not defined + - name: Query one webhook meraki_webhook: auth_key: '{{auth_key}}'