From 364cfbac3d7abe646feff2bd178ef78f5201ae79 Mon Sep 17 00:00:00 2001 From: Alex Carrie Date: Wed, 17 Nov 2021 16:27:33 +0000 Subject: [PATCH 1/7] APM-2707 Change to check specId rather than apiId and just debug --- .../remove-old-pr-portal-apis/tasks/main.yml | 12 ++++++------ .../tasks/remove-pr-portal-api.yml | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml index 9d6ec145d..cdf7f4a15 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml @@ -24,12 +24,12 @@ set_fact: portal_filter: "{{ apidocs.json.data | to_json | from_json | json_query(item) }}" with_items: - - "[?contains(apiId, '-pr-')]" - - "[?contains(apiId, '-apm-')]" - - "[?contains(apiId, '-aea-')]" - - "[?contains(apiId, '-adz-')]" - - "[?contains(apiId, '-apmspii-')]" - - "[?contains(apiId, '-dependabot-')]" + - "[?contains(specId, '-pr-')]" + - "[?contains(specId, '-apm-')]" + - "[?contains(specId, '-aea-')]" + - "[?contains(specId, '-adz-')]" + - "[?contains(specId, '-apmspii-')]" + - "[?contains(specId, '-dependabot-')]" register: search_result - name: make a list and set portal_api diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml index 6e2df0ad4..a66614a5a 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml @@ -25,11 +25,11 @@ - "age_hours, {{ age_hours }}" - "should remove, {{ should_remove }}" -- name: "remove pr portal api {{ item.apiId }}" - uri: - url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" - method: DELETE - headers: - Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" - when: should_remove - changed_when: yes +# - name: "remove pr portal api {{ item.apiId }}" +# uri: +# url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" +# method: DELETE +# headers: +# Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" +# when: should_remove +# changed_when: yes From 33f3bf654c61a7595a7c44e152449ac2ac1ae077 Mon Sep 17 00:00:00 2001 From: Alex Carrie Date: Wed, 17 Nov 2021 16:45:04 +0000 Subject: [PATCH 2/7] APM-2707 Set portals.json.data index to 1 to fetch correct portal --- .../roles/remove-old-pr-portal-apis/tasks/main.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml index cdf7f4a15..c42520d3d 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml @@ -8,7 +8,7 @@ - name: set portal_id set_fact: - portal_id: "{{ portals.json.data[0].id }}" + portal_id: "{{ portals.json.data[1].id }}" - name: get apidocs uri: @@ -24,12 +24,12 @@ set_fact: portal_filter: "{{ apidocs.json.data | to_json | from_json | json_query(item) }}" with_items: - - "[?contains(specId, '-pr-')]" - - "[?contains(specId, '-apm-')]" - - "[?contains(specId, '-aea-')]" - - "[?contains(specId, '-adz-')]" - - "[?contains(specId, '-apmspii-')]" - - "[?contains(specId, '-dependabot-')]" + - "[?contains(apiId, '-pr-')]" + - "[?contains(apiId, '-apm-')]" + - "[?contains(apiId, '-aea-')]" + - "[?contains(apiId, '-adz-')]" + - "[?contains(apiId, '-apmspii-')]" + - "[?contains(apiId, '-dependabot-')]" register: search_result - name: make a list and set portal_api From ca539fb6a3ac85cad99c9c0acefa927e291da607 Mon Sep 17 00:00:00 2001 From: Alex Carrie Date: Wed, 17 Nov 2021 16:47:48 +0000 Subject: [PATCH 3/7] APM-2707 Comment back in the delete step --- .../tasks/remove-pr-portal-api.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml index a66614a5a..6e2df0ad4 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml @@ -25,11 +25,11 @@ - "age_hours, {{ age_hours }}" - "should remove, {{ should_remove }}" -# - name: "remove pr portal api {{ item.apiId }}" -# uri: -# url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" -# method: DELETE -# headers: -# Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" -# when: should_remove -# changed_when: yes +- name: "remove pr portal api {{ item.apiId }}" + uri: + url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" + method: DELETE + headers: + Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" + when: should_remove + changed_when: yes From edb20eb9742accf5d5cffd303548f378486b663f Mon Sep 17 00:00:00 2001 From: Alex Carrie Date: Thu, 18 Nov 2021 10:45:38 +0000 Subject: [PATCH 4/7] Specify portal_id and comment out delete to test --- .../remove-old-pr-portal-apis/tasks/main.yml | 20 +++++++++---------- .../tasks/remove-pr-portal-api.yml | 16 +++++++-------- .../remove-old-pr-portal-apis/vars/main.yml | 1 + 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml index c42520d3d..6bba2b4bc 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml @@ -1,14 +1,14 @@ -- name: list portals - uri: - url: "{{ portals_list_uri }}" - headers: - Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" - return_content: yes - register: portals +# - name: list portals +# uri: +# url: "{{ portals_list_uri }}" +# headers: +# Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" +# return_content: yes +# register: portals -- name: set portal_id - set_fact: - portal_id: "{{ portals.json.data[1].id }}" +# - name: set portal_id +# set_fact: +# portal_id: "{{ portals.json.data[1].id }}" - name: get apidocs uri: diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml index 6e2df0ad4..a66614a5a 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml @@ -25,11 +25,11 @@ - "age_hours, {{ age_hours }}" - "should remove, {{ should_remove }}" -- name: "remove pr portal api {{ item.apiId }}" - uri: - url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" - method: DELETE - headers: - Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" - when: should_remove - changed_when: yes +# - name: "remove pr portal api {{ item.apiId }}" +# uri: +# url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" +# method: DELETE +# headers: +# Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" +# when: should_remove +# changed_when: yes diff --git a/ansible/roles/remove-old-pr-portal-apis/vars/main.yml b/ansible/roles/remove-old-pr-portal-apis/vars/main.yml index 0dd2ed2d0..437f6bf0a 100644 --- a/ansible/roles/remove-old-pr-portal-apis/vars/main.yml +++ b/ansible/roles/remove-old-pr-portal-apis/vars/main.yml @@ -1,3 +1,4 @@ portals_base_uri: "https://apigee.com/portals/api/sites" portals_list_uri: "{{ portals_base_uri }}?orgname={{ APIGEE_ORGANIZATION }}" +portal_id: "{{ APIGEE_ORGANIZATION }}-developerportal" retain_hours: "{{ (lookup('env', 'retain_hours') or 72) }}" From abbff419cf22fd8f512bfab6f28b7b6f67131f1b Mon Sep 17 00:00:00 2001 From: Alex Carrie Date: Thu, 18 Nov 2021 10:55:16 +0000 Subject: [PATCH 5/7] APM-2707 Remove call to get portal ids and comment back in deletes --- .../remove-old-pr-portal-apis/tasks/main.yml | 12 ------------ .../tasks/remove-pr-portal-api.yml | 16 ++++++++-------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml index 6bba2b4bc..b3081f9d4 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/main.yml @@ -1,15 +1,3 @@ -# - name: list portals -# uri: -# url: "{{ portals_list_uri }}" -# headers: -# Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" -# return_content: yes -# register: portals - -# - name: set portal_id -# set_fact: -# portal_id: "{{ portals.json.data[1].id }}" - - name: get apidocs uri: url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs" diff --git a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml index a66614a5a..6e2df0ad4 100644 --- a/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml +++ b/ansible/roles/remove-old-pr-portal-apis/tasks/remove-pr-portal-api.yml @@ -25,11 +25,11 @@ - "age_hours, {{ age_hours }}" - "should remove, {{ should_remove }}" -# - name: "remove pr portal api {{ item.apiId }}" -# uri: -# url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" -# method: DELETE -# headers: -# Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" -# when: should_remove -# changed_when: yes +- name: "remove pr portal api {{ item.apiId }}" + uri: + url: "{{ portals_base_uri }}/{{ portal_id }}/apidocs/{{ item.id }}" + method: DELETE + headers: + Authorization: "Bearer {{ APIGEE_ACCESS_TOKEN }}" + when: should_remove + changed_when: yes From 9e4c8899cff975efe035ebb5ee6a9ccb2139fac0 Mon Sep 17 00:00:00 2001 From: Ben Strutt Date: Wed, 5 Jan 2022 11:11:09 +0000 Subject: [PATCH 6/7] APM-2782 Make the ptl instance of api-registry the canonical one --- .../nhsd/apigee/plugins/module_utils/paas/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/collections/ansible_collections/nhsd/apigee/plugins/module_utils/paas/urls.py b/ansible/collections/ansible_collections/nhsd/apigee/plugins/module_utils/paas/urls.py index f6b98ccb3..d3f03a6c5 100644 --- a/ansible/collections/ansible_collections/nhsd/apigee/plugins/module_utils/paas/urls.py +++ b/ansible/collections/ansible_collections/nhsd/apigee/plugins/module_utils/paas/urls.py @@ -12,4 +12,4 @@ def _localstack() -> bool: def api_registry() -> str: if _localstack(): return "http://localhost:9000" - return "https://api-registry.prod.api.platform.nhs.uk:9000" + return "https://api-registry.ptl.api.platform.nhs.uk:9000" From 025b9dd2c307d47d7ff9bd8049e1ad92f27e98e2 Mon Sep 17 00:00:00 2001 From: Ben Strutt Date: Wed, 5 Jan 2022 14:39:48 +0000 Subject: [PATCH 7/7] APM-2782 Colourize ansible tests --- azure/utils-pr-pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure/utils-pr-pipeline.yml b/azure/utils-pr-pipeline.yml index 02f7e6522..285a2ac39 100644 --- a/azure/utils-pr-pipeline.yml +++ b/azure/utils-pr-pipeline.yml @@ -103,12 +103,12 @@ jobs: displayName: Install utils pre-requisites - bash: | - poetry run ansible-test units --python=3.8 + ANSIBLE_FORCE_COLOR=yes poetry run ansible-test units --python=3.8 workingDirectory: ansible/collections/ansible_collections/nhsd/apigee displayName: Unit test ansible - bash: | - poetry run ansible-test integration --python=3.8 + ANSIBLE_FORCE_COLOR=yes poetry run ansible-test integration --python=3.8 workingDirectory: ansible/collections/ansible_collections/nhsd/apigee displayName: Integration test ansible