From d45f90517ae2398c8a762a711d789517e2701de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Wed, 13 Mar 2019 09:14:09 +0100 Subject: [PATCH] #40: improve the galaxy quality score --- support/docker/install.yaml | 1 - .../jenkins-slave-template-centos.yaml | 3 -- tasks/api-calls/create_activedoc.yml | 18 +++++-- tasks/api-calls/create_application.yml | 7 +-- tasks/api-calls/create_application_plan.yml | 18 +++++-- tasks/api-calls/create_mapping_rule.yml | 4 +- tasks/api-calls/create_method.yml | 18 +++++-- tasks/api-calls/create_service.yml | 18 +++++-- tasks/api-calls/delete_mapping_rule.yml | 11 +++- tasks/api-calls/delete_metric.yml | 8 ++- tasks/api-calls/find_application.yml | 7 +-- tasks/api-calls/find_first_account.yml | 5 +- tasks/api-calls/get_proxy_version.yml | 31 ++++++++--- tasks/api-calls/keycloak/authenticate.yml | 8 +-- tasks/api-calls/keycloak/patch_client.yml | 4 +- tasks/api-calls/keycloak/wait_for_client.yml | 5 +- tasks/api-calls/promote_proxy.yml | 9 ++-- tasks/api-calls/smoke_test.yml | 2 +- tasks/api-calls/update_activedoc.yml | 4 +- tasks/api-calls/update_application.yml | 11 ++-- tasks/api-calls/update_application_plan.yml | 10 ++-- tasks/api-calls/update_mapping_rule.yml | 4 +- tasks/api-calls/update_method.yml | 9 ++-- tasks/api-calls/update_policies.yml | 4 +- tasks/api-calls/update_proxy.yml | 4 +- tasks/api-calls/update_service.yml | 4 +- tasks/cleanup.yaml | 12 +++-- tasks/main.yml | 2 +- tasks/steps/ansible_requirements.yml | 15 +++--- tasks/steps/application_plan.yml | 1 - tasks/steps/default_application.yml | 6 +-- tasks/steps/discover.yml | 52 ++++++++++++------- tasks/steps/find_goswagger.yml | 8 ++- tasks/steps/install_goswagger.yml | 10 ++-- tasks/steps/mapping_rules.yml | 11 ++-- tasks/steps/methods.yml | 14 +++-- tasks/steps/policies.yml | 8 ++- tasks/steps/read_openapi.yml | 22 +++++--- tasks/steps/requirements.yml | 6 ++- tasks/steps/smoke_test.yml | 2 +- tasks/steps/validate_openapi.yml | 2 +- tasks/steps/variables_from_inventory.yml | 19 ++++--- tests/setup/delete-travis-logs.yml | 1 - 43 files changed, 274 insertions(+), 144 deletions(-) diff --git a/support/docker/install.yaml b/support/docker/install.yaml index 3e50a5b..31516d6 100644 --- a/support/docker/install.yaml +++ b/support/docker/install.yaml @@ -1,4 +1,3 @@ - - name: Install the pre-requisites hosts: localhost gather_facts: no diff --git a/support/jenkins/jenkins-slave-template-centos.yaml b/support/jenkins/jenkins-slave-template-centos.yaml index a9f279b..4723479 100644 --- a/support/jenkins/jenkins-slave-template-centos.yaml +++ b/support/jenkins/jenkins-slave-template-centos.yaml @@ -29,7 +29,6 @@ objects: - name: latest annotations: role: jenkins-slave - - apiVersion: v1 kind: ImageStream metadata: @@ -44,7 +43,6 @@ objects: name: docker.io/openshift/jenkins-slave-base-centos7:${OPENSHIFT_VERSION} importPolicy: scheduled: true - - apiVersion: v1 kind: BuildConfig metadata: @@ -89,4 +87,3 @@ objects: triggers: - type: ConfigChange - type: ImageChange - diff --git a/tasks/api-calls/create_activedoc.yml b/tasks/api-calls/create_activedoc.yml index 73d040a..2b6297d 100644 --- a/tasks/api-calls/create_activedoc.yml +++ b/tasks/api-calls/create_activedoc.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_create_activedoc_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Create the ActiveDocs uri: @@ -14,11 +14,19 @@ status_code: 201 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: - threescale_cicd_existing_activedocs: '{{ threescale_cicd_existing_activedocs|union([ threescale_cicd_tmpresponse.json.api_doc.system_name ]) }}' - threescale_cicd_existing_activedocs_details: '{{ threescale_cicd_existing_activedocs_details|union([ { ''id'': threescale_cicd_tmpresponse.json.api_doc.id, ''system_name'': threescale_cicd_tmpresponse.json.api_doc.system_name } ]) }}' +- name: Store the list of existing ActiveDocs as fact + set_fact: + threescale_cicd_existing_activedocs: >- + {{ threescale_cicd_existing_activedocs|union([ threescale_cicd_tmpresponse.json.api_doc.system_name ]) }} + threescale_cicd_existing_activedocs_details: >- + {{ threescale_cicd_existing_activedocs_details|union([ + { + 'id': threescale_cicd_tmpresponse.json.api_doc.id, + 'system_name': threescale_cicd_tmpresponse.json.api_doc.system_name + } + ]) }} - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/create_application.yml b/tasks/api-calls/create_application.yml index e906647..24e3074 100644 --- a/tasks/api-calls/create_application.yml +++ b/tasks/api-calls/create_application.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_create_application_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Create the application uri: @@ -14,9 +14,10 @@ status_code: 201 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: +- name: Store the default application details as fact + set_fact: threescale_cicd_default_application_details: '{{ threescale_cicd_tmpresponse.json.application }}' - name: Wait for a couple seconds diff --git a/tasks/api-calls/create_application_plan.yml b/tasks/api-calls/create_application_plan.yml index 0222baf..aee3449 100644 --- a/tasks/api-calls/create_application_plan.yml +++ b/tasks/api-calls/create_application_plan.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_create_application_plan_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Create the application plan uri: @@ -14,11 +14,19 @@ status_code: 201 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: - threescale_cicd_existing_application_plans: '{{ threescale_cicd_existing_application_plans|union([ threescale_cicd_application_plan.system_name ]) }}' - threescale_cicd_existing_application_plans_details: '{{ threescale_cicd_existing_application_plans_details|union([{ "system_name": threescale_cicd_application_plan.system_name, "id": threescale_cicd_tmpresponse.json.application_plan.id }]) }}' +- name: Store the list of existing Application Plans as fact + set_fact: + threescale_cicd_existing_application_plans: >- + {{ threescale_cicd_existing_application_plans|union([ threescale_cicd_application_plan.system_name ]) }} + threescale_cicd_existing_application_plans_details: >- + {{ threescale_cicd_existing_application_plans_details|union([ + { + "system_name": threescale_cicd_application_plan.system_name, + "id": threescale_cicd_tmpresponse.json.application_plan.id + } + ]) }} - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/create_mapping_rule.yml b/tasks/api-calls/create_mapping_rule.yml index 28daeaa..64a2ce9 100644 --- a/tasks/api-calls/create_mapping_rule.yml +++ b/tasks/api-calls/create_mapping_rule.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_create_mapping_rule_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Create the mapping rule uri: @@ -14,7 +14,7 @@ status_code: 201 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/create_method.yml b/tasks/api-calls/create_method.yml index 5ae20b8..dd67461 100644 --- a/tasks/api-calls/create_method.yml +++ b/tasks/api-calls/create_method.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_create_method_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Create the method uri: @@ -14,11 +14,19 @@ status_code: 201 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: - threescale_cicd_existing_metrics: '{{ threescale_cicd_existing_metrics|union([ threescale_cicd_api_operation.key ]) }}' - threescale_cicd_existing_metrics_details: '{{ threescale_cicd_existing_metrics_details|union([ { "system_name": threescale_cicd_api_operation.key, "id": threescale_cicd_tmpresponse.json|json_query("method.id") } ]) }}' +- name: Store the metrics details as fact + set_fact: + threescale_cicd_existing_metrics: >- + {{ threescale_cicd_existing_metrics|union([ threescale_cicd_api_operation.key ]) }} + threescale_cicd_existing_metrics_details: >- + {{ threescale_cicd_existing_metrics_details|union([ + { + "system_name": threescale_cicd_api_operation.key, + "id": threescale_cicd_tmpresponse.json|json_query("method.id") + } + ]) }} - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/create_service.yml b/tasks/api-calls/create_service.yml index aca8b23..3bfe945 100644 --- a/tasks/api-calls/create_service.yml +++ b/tasks/api-calls/create_service.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_create_service_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Create the service uri: @@ -14,11 +14,19 @@ status_code: 201 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: - threescale_cicd_existing_services: '{{ threescale_cicd_existing_services|union([ threescale_cicd_tmpresponse.json.service.system_name ]) }}' - threescale_cicd_existing_services_details: '{{ threescale_cicd_existing_services_details|union([ { ''id'': threescale_cicd_tmpresponse.json.service.id, ''system_name'': threescale_cicd_tmpresponse.json.service.system_name } ]) }}' +- name: Add the new service to the existing service list + set_fact: + threescale_cicd_existing_services: >- + {{ threescale_cicd_existing_services|union([ threescale_cicd_tmpresponse.json.service.system_name ]) }} + threescale_cicd_existing_services_details: >- + {{ threescale_cicd_existing_services_details|union([ + { + "id": threescale_cicd_tmpresponse.json.service.id, + "system_name": threescale_cicd_tmpresponse.json.service.system_name + } + ]) }} cacheable: true - name: Wait for a couple seconds diff --git a/tasks/api-calls/delete_mapping_rule.yml b/tasks/api-calls/delete_mapping_rule.yml index 3183c95..e63200f 100644 --- a/tasks/api-calls/delete_mapping_rule.yml +++ b/tasks/api-calls/delete_mapping_rule.yml @@ -1,14 +1,21 @@ --- +- debug: + msg: "Deleting unused mapping rule {{ threescale_cicd_mapping_rule }}..." + verbosity: 1 + - name: Delete the unused mapping rules uri: - url: "https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/mapping_rules/{{ threescale_cicd_existing_mapping_rules[threescale_cicd_mapping_rule] }}.json?access_token={{ threescale_cicd_access_token|urlencode }}" + url: "{{ service_url }}/proxy/mapping_rules/{{ rule_id }}.json?access_token={{ threescale_cicd_access_token|urlencode }}" validate_certs: no method: DELETE status_code: 200,404 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + rule_id: '{{ threescale_cicd_existing_mapping_rules[threescale_cicd_mapping_rule] }}' + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/delete_metric.yml b/tasks/api-calls/delete_metric.yml index 4b4b943..ea219e0 100644 --- a/tasks/api-calls/delete_metric.yml +++ b/tasks/api-calls/delete_metric.yml @@ -2,16 +2,20 @@ - debug: msg: "Deleting unused metric {{ threescale_cicd_metric.system_name }}..." + verbosity: 1 - name: Delete the metric uri: - url: "https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/metrics/{{ threescale_cicd_metric_id }}/methods/{{ threescale_cicd_metric.id }}.json?access_token={{ threescale_cicd_access_token|urlencode }}" + url: "{{ service_url }}{{ metric_path }}?access_token={{ threescale_cicd_access_token|urlencode }}" validate_certs: no method: DELETE status_code: 200,404 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + metric_path: /metrics/{{ threescale_cicd_metric_id }}/methods/{{ threescale_cicd_metric.id }}.json + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/find_application.yml b/tasks/api-calls/find_application.yml index c139bf3..ccee313 100644 --- a/tasks/api-calls/find_application.yml +++ b/tasks/api-calls/find_application.yml @@ -2,13 +2,14 @@ - name: Check if the default application exists uri: - url: 'https://{{ inventory_hostname }}/admin/api/applications/find.json?{{ threescale_cicd_find_application_payload }}' + url: 'https://{{ inventory_hostname }}/admin/api/applications/find.json?{{ threescale_cicd_find_application_payload }}' validate_certs: no method: GET status_code: 200,404 register: threescale_cicd_tmpresponse - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: +- name: Set the default application id as a fact + set_fact: threescale_cicd_default_application_id: '{{ threescale_cicd_tmpresponse.json.application.id }}' when: 'threescale_cicd_tmpresponse.status == 200' diff --git a/tasks/api-calls/find_first_account.yml b/tasks/api-calls/find_first_account.yml index 696b2c1..f25fa00 100644 --- a/tasks/api-calls/find_first_account.yml +++ b/tasks/api-calls/find_first_account.yml @@ -5,7 +5,8 @@ url: https://{{ inventory_hostname }}/admin/api/accounts.json?access_token={{ threescale_cicd_access_token|urlencode }}&state=approved&page=1&per_page=1 validate_certs: no register: threescale_cicd_tmpresponse - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: +- name: Set the default first account id as a fact + set_fact: threescale_cicd_default_account_id: '{{ threescale_cicd_tmpresponse.json.accounts[0].account.id }}' diff --git a/tasks/api-calls/get_proxy_version.yml b/tasks/api-calls/get_proxy_version.yml index 3ca9c5b..da5ed97 100644 --- a/tasks/api-calls/get_proxy_version.yml +++ b/tasks/api-calls/get_proxy_version.yml @@ -2,21 +2,36 @@ - name: Get the version of the staging proxy definition uri: - url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/configs/{{ threescale_cicd_staging_environment_name }}/latest.json?access_token={{ threescale_cicd_access_token|urlencode }}' + url: '{{ service_url }}{{ proxy_path }}?access_token={{ threescale_cicd_access_token|urlencode }}' validate_certs: no register: threescale_cicd_tmpresponse - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + proxy_path: /proxy/configs/{{ threescale_cicd_staging_environment_name }}/latest.json + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} -- set_fact: - threescale_cicd_staging_proxy_version: '{{ threescale_cicd_tmpresponse.json.proxy_config.version }}' +- name: Set the staging proxy version number as a fact + set_fact: + threescale_cicd_staging_proxy_version: >- + {{ threescale_cicd_tmpresponse.json.proxy_config.version }} + +- debug: # TODO + var: threescale_cicd_staging_proxy_version - name: Get the version of the production proxy definition uri: - url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/configs/{{ threescale_cicd_production_environment_name }}/latest.json?access_token={{ threescale_cicd_access_token|urlencode }}' + url: '{{ service_url }}{{ proxy_path }}?access_token={{ threescale_cicd_access_token|urlencode }}' validate_certs: no status_code: 200,404 register: threescale_cicd_tmpresponse - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + proxy_path: /proxy/configs/{{ threescale_cicd_production_environment_name }}/latest.json + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} -- set_fact: - threescale_cicd_production_proxy_version: '{{ threescale_cicd_tmpresponse.json.proxy_config.version if threescale_cicd_tmpresponse.status == 200 else ''NONE'' }}' +- name: Set the production proxy version number as a fact + set_fact: + threescale_cicd_production_proxy_version: >- + {{ threescale_cicd_tmpresponse.json.proxy_config.version + if threescale_cicd_tmpresponse.status == 200 + else 'NONE' }} diff --git a/tasks/api-calls/keycloak/authenticate.yml b/tasks/api-calls/keycloak/authenticate.yml index 9db1049..fefbc29 100644 --- a/tasks/api-calls/keycloak/authenticate.yml +++ b/tasks/api-calls/keycloak/authenticate.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_authenticate_to_keycloak_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Authenticate to RH-SSO uri: @@ -17,9 +17,9 @@ delay: '{{ threescale_cicd_delay }}' # temporary fix for https://github.com/ansible/ansible/issues/28078 until: 'threescale_cicd_tmpresponse is success' - no_log: '{{ threescale_cicd_nolog }}' - + no_log: '{{ threescale_cicd_nolog }}' + - name: Extract the access_token set_fact: threescale_cicd_keycloak_access_token: '{{ threescale_cicd_tmpresponse.json |json_query("access_token") }}' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' diff --git a/tasks/api-calls/keycloak/patch_client.yml b/tasks/api-calls/keycloak/patch_client.yml index 4968078..72d4c2d 100644 --- a/tasks/api-calls/keycloak/patch_client.yml +++ b/tasks/api-calls/keycloak/patch_client.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_patch_keycloak_client_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Patch the client in RH-SSO to support the "client_credentials" and "password" grant_type. uri: @@ -18,7 +18,7 @@ Content-Type: 'application/json' register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/keycloak/wait_for_client.yml b/tasks/api-calls/keycloak/wait_for_client.yml index 1c95203..63569a1 100644 --- a/tasks/api-calls/keycloak/wait_for_client.yml +++ b/tasks/api-calls/keycloak/wait_for_client.yml @@ -12,8 +12,9 @@ retries: '{{ threescale_cicd_retries }}' delay: '{{ threescale_cicd_delay }}' until: 'threescale_cicd_tmpresponse is success and threescale_cicd_tmpresponse.json|length > 0' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: +- name: Set the new client details and id as a fact + set_fact: threescale_cicd_default_application_sso_id: '{{ threescale_cicd_tmpresponse.json[0].id }}' threescale_cicd_default_application_sso_body: '{{ threescale_cicd_tmpresponse.json[0] }}' diff --git a/tasks/api-calls/promote_proxy.yml b/tasks/api-calls/promote_proxy.yml index 73ba44c..27de0bf 100644 --- a/tasks/api-calls/promote_proxy.yml +++ b/tasks/api-calls/promote_proxy.yml @@ -3,18 +3,21 @@ - debug: var: threescale_cicd_promote_proxy_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Promote to production uri: - url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/configs/{{ threescale_cicd_staging_environment_name }}/{{ threescale_cicd_staging_proxy_version }}/promote.json' + url: '{{ service_url }}{{ promote_path }}' body: '{{ threescale_cicd_promote_proxy_payload }}' status_code: 201 validate_certs: no method: POST register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 201' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} + promote_path: /proxy/configs/{{ threescale_cicd_staging_environment_name }}/{{ threescale_cicd_staging_proxy_version }}/promote.json - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/smoke_test.yml b/tasks/api-calls/smoke_test.yml index 933afeb..f1a3369 100644 --- a/tasks/api-calls/smoke_test.yml +++ b/tasks/api-calls/smoke_test.yml @@ -1,6 +1,6 @@ --- -- debug: +- debug: var: threescale_cicd_smoke_test_headers verbosity: 1 diff --git a/tasks/api-calls/update_activedoc.yml b/tasks/api-calls/update_activedoc.yml index e2bfb0f..e9a7eef 100644 --- a/tasks/api-calls/update_activedoc.yml +++ b/tasks/api-calls/update_activedoc.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_update_activedoc_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the ActiveDocs uri: @@ -14,7 +14,7 @@ status_code: 200 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/update_application.yml b/tasks/api-calls/update_application.yml index b1bfe1a..94f2d12 100644 --- a/tasks/api-calls/update_application.yml +++ b/tasks/api-calls/update_application.yml @@ -3,19 +3,22 @@ - debug: var: threescale_cicd_update_application_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the application uri: - url: https://{{ inventory_hostname }}/admin/api/accounts/{{ threescale_cicd_default_account_id }}/applications/{{ threescale_cicd_default_application_id }}.json + url: '{{ default_account_url }}/applications/{{ threescale_cicd_default_application_id }}.json' validate_certs: no method: PUT body: '{{ threescale_cicd_update_application_payload }}' status_code: 200 register: threescale_cicd_tmpresponse - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + default_account_url: https://{{ inventory_hostname }}/admin/api/accounts/{{ threescale_cicd_default_account_id }} -- set_fact: +- name: Set the default application details as a fact + set_fact: threescale_cicd_default_application_details: '{{ threescale_cicd_tmpresponse.json.application }}' - name: Wait for a couple seconds diff --git a/tasks/api-calls/update_application_plan.yml b/tasks/api-calls/update_application_plan.yml index 3b80e7e..c1232d3 100644 --- a/tasks/api-calls/update_application_plan.yml +++ b/tasks/api-calls/update_application_plan.yml @@ -3,18 +3,22 @@ - debug: var: threescale_cicd_update_application_plan_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the application plan uri: - url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/application_plans/{{ (threescale_cicd_existing_application_plans_details|selectattr("system_name", "equalto", threescale_cicd_application_plan.system_name)|first).id }}.json' + url: '{{ service_url }}/application_plans/{{ application_plan_id }}.json' validate_certs: no method: PUT body: '{{ threescale_cicd_update_application_plan_payload }}' status_code: 200 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} + application_plan_id: >- + {{ (threescale_cicd_existing_application_plans_details|selectattr("system_name", "equalto", threescale_cicd_application_plan.system_name)|first).id }} - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/update_mapping_rule.yml b/tasks/api-calls/update_mapping_rule.yml index f8ab30a..ca2097c 100644 --- a/tasks/api-calls/update_mapping_rule.yml +++ b/tasks/api-calls/update_mapping_rule.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_update_mapping_rule_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the mapping rule uri: @@ -16,7 +16,7 @@ changed_when: 'threescale_cicd_tmpresponse.status == 200' vars: threescale_cicd_mapping_rule_id: '{{ threescale_cicd_existing_mapping_rules[threescale_cicd_mapping_rule] }}' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/update_method.yml b/tasks/api-calls/update_method.yml index c37cca3..7f84eb3 100644 --- a/tasks/api-calls/update_method.yml +++ b/tasks/api-calls/update_method.yml @@ -3,17 +3,20 @@ - debug: var: threescale_cicd_update_method_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the method uri: - url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/metrics/{{ threescale_cicd_metric_id }}/methods/{{ (threescale_cicd_existing_metrics_details|selectattr('system_name', 'equalto', threescale_cicd_api_operation.key)|first).id }}.json + url: '{{ service_url }}/metrics/{{ threescale_cicd_metric_id }}/methods/{{ method_id }}.json' validate_certs: no method: PATCH body: '{{ threescale_cicd_update_method_payload }}' register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} + method_id: "{{ (threescale_cicd_existing_metrics_details|selectattr('system_name', 'equalto', threescale_cicd_api_operation.key)|first).id }}" - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/update_policies.yml b/tasks/api-calls/update_policies.yml index d882e6a..e2ad6ec 100644 --- a/tasks/api-calls/update_policies.yml +++ b/tasks/api-calls/update_policies.yml @@ -7,7 +7,7 @@ - debug: var: threescale_cicd_update_policies_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the policies chain uri: @@ -18,7 +18,7 @@ status_code: 200 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Wait for a couple seconds pause: diff --git a/tasks/api-calls/update_proxy.yml b/tasks/api-calls/update_proxy.yml index de24b2e..b6daf14 100644 --- a/tasks/api-calls/update_proxy.yml +++ b/tasks/api-calls/update_proxy.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_update_proxy_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the proxy definition uri: @@ -13,7 +13,7 @@ body: '{{ threescale_cicd_update_proxy_payload }}' register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Extract the staging and production gateway endpoint from the proxy definition set_fact: diff --git a/tasks/api-calls/update_service.yml b/tasks/api-calls/update_service.yml index 7355398..6044e12 100644 --- a/tasks/api-calls/update_service.yml +++ b/tasks/api-calls/update_service.yml @@ -3,7 +3,7 @@ - debug: var: threescale_cicd_update_service_payload verbosity: 1 - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Update the service uri: @@ -14,7 +14,7 @@ status_code: 200 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' - name: Wait for a couple seconds pause: diff --git a/tasks/cleanup.yaml b/tasks/cleanup.yaml index 02355d4..8161321 100644 --- a/tasks/cleanup.yaml +++ b/tasks/cleanup.yaml @@ -2,22 +2,26 @@ - name: Delete the created service and any dependent object uri: - url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}.json?access_token={{ threescale_cicd_access_token|urlencode }}' + url: '{{ service_url }}?access_token={{ threescale_cicd_access_token|urlencode }}' validate_certs: no method: DELETE status_code: 200,404 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' when: 'threescale_cicd_api_service_id is defined' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}.json - name: Delete the created ActiveDocs uri: - url: 'https://{{ inventory_hostname }}/admin/api/active_docs/{{ threescale_cicd_api_activedocs_id }}.json?access_token={{ threescale_cicd_access_token|urlencode }}' + url: '{{ activedocs_url }}?access_token={{ threescale_cicd_access_token|urlencode }}' validate_certs: no method: DELETE status_code: 200,404 register: threescale_cicd_tmpresponse changed_when: 'threescale_cicd_tmpresponse.status == 200' when: 'threescale_cicd_api_activedocs_id is defined' - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + activedocs_url: https://{{ inventory_hostname }}/admin/api/active_docs/{{ threescale_cicd_api_activedocs_id }}.json diff --git a/tasks/main.yml b/tasks/main.yml index 9af0609..037358e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -43,7 +43,7 @@ - include_tasks: steps/smoke_test.yml vars: threescale_cicd_smoke_test_env: staging - when: > + when: >- threescale_cicd_openapi_smoketest_operation|length > 0 and threescale_cicd_application_plans is defined and threescale_cicd_apicast_sandbox_endpoint != threescale_cicd_apicast_production_endpoint diff --git a/tasks/steps/ansible_requirements.yml b/tasks/steps/ansible_requirements.yml index 13a3d76..1e4ec08 100644 --- a/tasks/steps/ansible_requirements.yml +++ b/tasks/steps/ansible_requirements.yml @@ -3,20 +3,20 @@ - name: Verify that Ansible version is >= 2.4.6 assert: that: "ansible_version.full is version_compare('2.4.6', '>=')" - msg: > + msg: >- This module requires at least Ansible 2.4.6. The version that comes with RHEL and CentOS by default (2.4.2) has a known bug that prevent this role from running properly. - name: Check if jmespath is installed locally - debug: msg={{dummy|json_query('@')}} + debug: msg={{ dummy|json_query('@') }} register: check_jmespath ignore_errors: yes vars: dummy: Hello World - name: Check if jinja 2.8 is installed locally - debug: msg={{(dummy|selectattr("id", "equalto", "hello")|first)['value']}} + debug: msg={{ (dummy|selectattr("id", "equalto", "hello")|first)['value'] }} vars: dummy: - id: hello @@ -31,17 +31,20 @@ register: check_jinja_do_ext ignore_errors: yes -- assert: +- name: Ensure JMESPath is installed + assert: that: - 'check_jmespath is success' msg: "The JMESPath library is required by this role. Please install the JMESPath library with 'pip install jmespath'." -- assert: +- name: Ensure at least Jinja 2.8 is installed + assert: that: - 'check_jinja28 is success' msg: "At least Jinja v2.8 is required by this role. Please update Jinja with 'pip install -U Jinja2'." -- assert: +- name: Ensure the "do" extension of Jinja is enabled + assert: that: - 'check_jinja_do_ext is success' msg: |- diff --git a/tasks/steps/application_plan.yml b/tasks/steps/application_plan.yml index 0953092..ab6ebfd 100644 --- a/tasks/steps/application_plan.yml +++ b/tasks/steps/application_plan.yml @@ -5,4 +5,3 @@ - include_tasks: api-calls/create_application_plan.yml when: 'threescale_cicd_application_plan.system_name not in threescale_cicd_existing_application_plans' - diff --git a/tasks/steps/default_application.yml b/tasks/steps/default_application.yml index 860032b..b0fc537 100644 --- a/tasks/steps/default_application.yml +++ b/tasks/steps/default_application.yml @@ -17,7 +17,7 @@ ## - include_tasks: api-calls/keycloak/authenticate.yml - when: 'threescale_cicd_api_security_scheme.type == ''oauth2''' + when: "threescale_cicd_api_security_scheme.type == 'oauth2'" vars: oauth_payload: client_id: '{{ threescale_cicd_sso_issuer_endpoint|urlsplit(''username'') }}' @@ -26,7 +26,7 @@ grant_type: 'client_credentials' - include_tasks: api-calls/keycloak/wait_for_client.yml - when: 'threescale_cicd_api_security_scheme.type == ''oauth2''' + when: "threescale_cicd_api_security_scheme.type == 'oauth2'" - include_tasks: api-calls/keycloak/patch_client.yml - when: 'threescale_cicd_api_security_scheme.type == ''oauth2''' + when: "threescale_cicd_api_security_scheme.type == 'oauth2'" diff --git a/tasks/steps/discover.yml b/tasks/steps/discover.yml index 877ec75..878e5b3 100644 --- a/tasks/steps/discover.yml +++ b/tasks/steps/discover.yml @@ -6,11 +6,14 @@ validate_certs: no register: threescale_cicd_tmpresponse when: threescale_cicd_existing_services is not defined - no_log: '{{ threescale_cicd_nolog }}' - -- set_fact: - threescale_cicd_existing_services: '{{ threescale_cicd_tmpresponse.json|json_query(''services[*].service.system_name'') }}' - threescale_cicd_existing_services_details: '{{ threescale_cicd_tmpresponse.json|json_query(''services[].{"system_name": service.system_name, "id": service.id}'') }}' + no_log: '{{ threescale_cicd_nolog }}' + +- name: Set the list of existing service as a fact + set_fact: + threescale_cicd_existing_services: >- + {{ threescale_cicd_tmpresponse.json|json_query('services[*].service.system_name') }} + threescale_cicd_existing_services_details: >- + {{ threescale_cicd_tmpresponse.json|json_query('services[].{"system_name": service.system_name, "id": service.id}') }} cacheable: true when: threescale_cicd_existing_services is not defined @@ -24,15 +27,24 @@ - name: Get the list of existing application plans uri: - url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/application_plans.json?access_token={{ threescale_cicd_access_token|urlencode }} + url: '{{ service_url }}/application_plans.json?access_token={{ threescale_cicd_access_token|urlencode }}' validate_certs: no register: threescale_cicd_tmpresponse when: threescale_cicd_api_system_name in threescale_cicd_existing_services - no_log: '{{ threescale_cicd_nolog }}' - -- set_fact: - threescale_cicd_existing_application_plans: '{{ threescale_cicd_tmpresponse.json|json_query(''plans[*].application_plan.system_name'') if threescale_cicd_api_system_name in threescale_cicd_existing_services else [] }}' - threescale_cicd_existing_application_plans_details: '{{ threescale_cicd_tmpresponse.json|json_query(''plans[].{"system_name": application_plan.system_name, "id": application_plan.id}'') if threescale_cicd_api_system_name in threescale_cicd_existing_services else [] }}' + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} + +- name: Set the list of existing application plans as a fact + set_fact: + threescale_cicd_existing_application_plans: >- + {{ threescale_cicd_tmpresponse.json|json_query('plans[*].application_plan.system_name') + if threescale_cicd_api_system_name in threescale_cicd_existing_services + else [] }} + threescale_cicd_existing_application_plans_details: >- + {{ threescale_cicd_tmpresponse.json|json_query('plans[].{"system_name": application_plan.system_name, "id": application_plan.id}') + if threescale_cicd_api_system_name in threescale_cicd_existing_services + else [] }} - debug: msg: "Found {{ threescale_cicd_existing_application_plans|length }} application plans" @@ -47,11 +59,14 @@ url: "https://{{ inventory_hostname }}/admin/api/active_docs.json?access_token={{ threescale_cicd_access_token|urlencode }}" validate_certs: no register: threescale_cicd_tmp_allactivedocs - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' -- set_fact: - threescale_cicd_existing_activedocs: '{{ threescale_cicd_tmp_allactivedocs.json|json_query(''api_docs[*].api_doc.system_name'') }}' - threescale_cicd_existing_activedocs_details: '{{ threescale_cicd_tmp_allactivedocs.json|json_query(''api_docs[].{"system_name": api_doc.system_name, "id": api_doc.id}'') }}' +- name: Set the list of existing active docs as a fact + set_fact: + threescale_cicd_existing_activedocs: >- + {{ threescale_cicd_tmp_allactivedocs.json|json_query('api_docs[*].api_doc.system_name') }} + threescale_cicd_existing_activedocs_details: >- + {{ threescale_cicd_tmp_allactivedocs.json|json_query('api_docs[].{"system_name": api_doc.system_name, "id": api_doc.id}') }} - debug: msg: "Found {{ threescale_cicd_existing_activedocs|length }} active docs" @@ -68,7 +83,7 @@ status_code: 200,404 register: threescale_cicd_tmp_policy_response changed_when: false - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' when: threescale_cicd_capabilities is not defined - name: Poke around for the OIDC Configuration Show API @@ -78,10 +93,11 @@ status_code: 404 register: threescale_cicd_tmp_oidc_config_response changed_when: false - no_log: '{{ threescale_cicd_nolog }}' + no_log: '{{ threescale_cicd_nolog }}' when: threescale_cicd_capabilities is not defined -- set_fact: +- name: Set the list of 3scale capabilities as a fact + set_fact: threescale_cicd_capabilities: policy_registry_api: '{{ threescale_cicd_tmp_policy_response.status == 200 }}' oidc_configuration_api: '{{ threescale_cicd_tmp_oidc_config_response.content_type.startswith(''application/json'') }}' diff --git a/tasks/steps/find_goswagger.yml b/tasks/steps/find_goswagger.yml index 2d85ed4..595fbc1 100644 --- a/tasks/steps/find_goswagger.yml +++ b/tasks/steps/find_goswagger.yml @@ -6,8 +6,10 @@ changed_when: false ignore_errors: yes -- set_fact: +- name: Set the 'swagger' command path as fact + set_fact: threescale_cicd_goswagger_command: 'swagger' + cacheable: true when: check_global_goswagger_version is success - name: Check if go-swagger is installed locally @@ -17,6 +19,8 @@ ignore_errors: yes when: check_global_goswagger_version is failed -- set_fact: +- name: Set the 'swagger' command path as fact + set_fact: threescale_cicd_goswagger_command: '{{ threescale_cicd_local_bin_path }}/swagger' + cacheable: true when: check_local_goswagger_version is success and check_local_goswagger_version is not skipped diff --git a/tasks/steps/install_goswagger.yml b/tasks/steps/install_goswagger.yml index 450c255..951c9ee 100644 --- a/tasks/steps/install_goswagger.yml +++ b/tasks/steps/install_goswagger.yml @@ -14,7 +14,7 @@ - name: Create the folder to download go-swagger file: - path: '{{ threescale_cicd_local_bin_path }}' + path: '{{ threescale_cicd_local_bin_path }}' state: directory - name: Download go-swagger @@ -23,14 +23,16 @@ dest: '{{ threescale_cicd_local_bin_path }}/swagger' mode: 0755 vars: - goswagger_download_url: '{{ goswagger_asset.browser_download_url }}' + goswagger_download_url: '{{ goswagger_asset.browser_download_url }}' goswagger_asset: '{{ goswagger_assets|selectattr(''name'', ''equalto'', artifact_name)|first }}' goswagger_assets: '{{ latest_goswagger_version.json.assets }}' artifact_name: 'swagger_{{ ansible_system|lower }}_{{ swagger_architecture }}' swagger_architecture: '{{ swagger_architecture_mapping[ansible_architecture] }}' - swagger_architecture_mapping: + swagger_architecture_mapping: x86_64: amd64 armv7l: arm -- set_fact: +- name: Set the 'swagger' command path as fact + set_fact: threescale_cicd_goswagger_command: '{{ threescale_cicd_local_bin_path }}/swagger' + cacheable: true diff --git a/tasks/steps/mapping_rules.yml b/tasks/steps/mapping_rules.yml index 299cbe7..5af4ebd 100644 --- a/tasks/steps/mapping_rules.yml +++ b/tasks/steps/mapping_rules.yml @@ -2,12 +2,17 @@ - name: Retrieve existing mapping rules from the 3scale Admin Portal uri: - url: "https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/mapping_rules.json?access_token={{ threescale_cicd_access_token|urlencode }}" + url: "{{ service_url }}/proxy/mapping_rules.json?access_token={{ threescale_cicd_access_token|urlencode }}" validate_certs: no register: threescale_cicd_tmpresponse + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} -- set_fact: - threescale_cicd_existing_mapping_rules_details: '{{ threescale_cicd_tmpresponse.json|json_query(''mapping_rules[].{"metric_id": mapping_rule.metric_id, "id": mapping_rule.id}'') }}' +- name: Set the list of existing mapping rules as a fact + set_fact: + threescale_cicd_existing_mapping_rules_details: >- + {{ threescale_cicd_tmpresponse.json|json_query('mapping_rules[].{"metric_id": mapping_rule.metric_id, "id": mapping_rule.id}') }} - include_tasks: "api-calls/create_mapping_rule.yml" with_items: '{{ threescale_cicd_mapping_rules_to_create }}' diff --git a/tasks/steps/methods.yml b/tasks/steps/methods.yml index abb9db8..86ae9e2 100644 --- a/tasks/steps/methods.yml +++ b/tasks/steps/methods.yml @@ -2,13 +2,19 @@ - name: Retrieve existing metrics from the 3scale Admin Portal uri: - url: "https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/metrics.json?access_token={{ threescale_cicd_access_token|urlencode }}" + url: "{{ service_url }}/metrics.json?access_token={{ threescale_cicd_access_token|urlencode }}" validate_certs: no register: threescale_cicd_tmpresponse + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} -- set_fact: - threescale_cicd_existing_metrics: '{{ threescale_cicd_tmpresponse.json|json_query(''metrics[*].metric.system_name'') }}' - threescale_cicd_existing_metrics_details: '{{ threescale_cicd_tmpresponse.json|json_query(''metrics[].{"system_name": metric.system_name, "id": metric.id}'') }}' +- name: Set the list of existing metrics as facts + set_fact: + threescale_cicd_existing_metrics: >- + {{ threescale_cicd_tmpresponse.json|json_query('metrics[*].metric.system_name') }} + threescale_cicd_existing_metrics_details: >- + {{ threescale_cicd_tmpresponse.json|json_query('metrics[].{"system_name": metric.system_name, "id": metric.id}') }} - include_tasks: "steps/method.yml" with_dict: '{{ threescale_cicd_api_operations }}' diff --git a/tasks/steps/policies.yml b/tasks/steps/policies.yml index 0baead2..7ea3d95 100644 --- a/tasks/steps/policies.yml +++ b/tasks/steps/policies.yml @@ -2,11 +2,15 @@ - name: Retrieve existing policies from the 3scale Admin Portal uri: - url: "https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/policies.json?access_token={{ threescale_cicd_access_token|urlencode }}" + url: "{{ service_url }}/proxy/policies.json?access_token={{ threescale_cicd_access_token|urlencode }}" validate_certs: no register: threescale_cicd_tmpresponse + no_log: '{{ threescale_cicd_nolog }}' + vars: + service_url: https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }} -- set_fact: +- name: Set the list of existing policies as a fact + set_fact: threescale_cicd_existing_policies_details: '{{ threescale_cicd_tmpresponse.json|json_query(''policies_config[]'') }}' - include_tasks: "api-calls/update_policies.yml" diff --git a/tasks/steps/read_openapi.yml b/tasks/steps/read_openapi.yml index a7fbfd1..979725f 100644 --- a/tasks/steps/read_openapi.yml +++ b/tasks/steps/read_openapi.yml @@ -10,29 +10,37 @@ assert: that: - 'threescale_cicd_api_security_requirements|length == 1' - msg: 'You have {{ threescale_cicd_api_security_requirements|length }} global security requirements. There must be one and only one security requirement.' + msg: >- + You have {{ threescale_cicd_api_security_requirements|length }} global security requirements. + There must be one and only one security requirement. - name: Make sure the security scheme is consistent with 3scale assert: that: - - '''type'' in threescale_cicd_api_security_scheme and threescale_cicd_api_security_scheme.type == ''apiKey'' or (threescale_cicd_api_security_scheme.type == ''oauth2'' and threescale_cicd_sso_issuer_endpoint is defined)' - msg: |- + - >- + 'type' in threescale_cicd_api_security_scheme and threescale_cicd_api_security_scheme.type == 'apiKey' + or (threescale_cicd_api_security_scheme.type == 'oauth2' and threescale_cicd_sso_issuer_endpoint is defined) + msg: >- The embedded security definition {{ threescale_cicd_api_security_scheme_name }} is not compatible with 3scale. Please make sure you chose an "apiKey" or "oauth2" scheme. Also, if you chose "oauth2", you will need to pass the threescale_cicd_sso_issuer_endpoint extra variable. The security definition you chose: {{ threescale_cicd_api_security_scheme|to_nice_json }} -- assert: +- name: Make sure the Private Base URL is defined + assert: that: - 'threescale_cicd_private_base_url is defined' - msg: 'Either the private base url or the tuple backend hostname/scheme must be declared as extra variables (either threescale_cicd_private_base_url or threescale_cicd_api_backend_scheme / threescale_cicd_api_backend_hostname)' + msg: >- + Either the private base url or the tuple backend hostname/scheme must be declared as extra variables + (either threescale_cicd_private_base_url or threescale_cicd_api_backend_scheme / threescale_cicd_api_backend_hostname) -- assert: +- name: Smoketests consistency + assert: that: # Operation must exists - 'threescale_cicd_openapi_smoketest_operation in threescale_cicd_api_operations' # Must be a GET - - 'threescale_cicd_api_operations[threescale_cicd_openapi_smoketest_operation].verb == ''get''' + - "threescale_cicd_api_operations[threescale_cicd_openapi_smoketest_operation].verb == 'get'" # Must NOT have a placeholder in the path - 'threescale_cicd_api_operations[threescale_cicd_openapi_smoketest_operation].path.find("{") == -1' msg: "The smoketest operation {{ threescale_cicd_openapi_smoketest_operation }} must be a GET and cannot have a placeholder in its path." diff --git a/tasks/steps/requirements.yml b/tasks/steps/requirements.yml index 6271e20..fbb619a 100644 --- a/tasks/steps/requirements.yml +++ b/tasks/steps/requirements.yml @@ -7,8 +7,10 @@ - "threescale_cicd_openapi_file is defined" msg: |- This module requires at least two variables: - - threescale_cicd_access_token that contains an Access Token with Read/Write privileges on the 3scale Account Management API. This variable is usually set in your inventory file. - - threescale_cicd_openapi_file that is the path to the OpenAPI file you want to deploy in 3scale. This variable is usually passed as an extra variable (-e threescale_cicd_openapi_file=...) + - threescale_cicd_access_token that contains an Access Token with Read/Write privileges on the 3scale Account Management API. + This variable is usually set in your inventory file. + - threescale_cicd_openapi_file that is the path to the OpenAPI file you want to deploy in 3scale. + This variable is usually passed as an extra variable (-e threescale_cicd_openapi_file=...) - name: Make sure the OpenAPI File Format is YAML or JSON assert: diff --git a/tasks/steps/smoke_test.yml b/tasks/steps/smoke_test.yml index aaa181a..0ffc6e4 100644 --- a/tasks/steps/smoke_test.yml +++ b/tasks/steps/smoke_test.yml @@ -2,7 +2,7 @@ # Retrieve a valid access token if the API is secured with OAuth/OIDC - include_tasks: api-calls/keycloak/authenticate.yml - when: 'threescale_cicd_api_security_scheme.type == ''oauth2''' + when: "threescale_cicd_api_security_scheme.type == 'oauth2'" vars: oauth_payload: client_id: '{{ threescale_cicd_default_application_details.client_id }}' diff --git a/tasks/steps/validate_openapi.yml b/tasks/steps/validate_openapi.yml index 1c12d6a..8d9f911 100644 --- a/tasks/steps/validate_openapi.yml +++ b/tasks/steps/validate_openapi.yml @@ -1,7 +1,7 @@ --- - debug: - msg: > + msg: >- Will use go-swagger at '{{ threescale_cicd_goswagger_command }}' as instructed. Auto-detection and download is DISABLED. when: threescale_cicd_goswagger_command is defined diff --git a/tasks/steps/variables_from_inventory.yml b/tasks/steps/variables_from_inventory.yml index 5c94bea..99b3e91 100644 --- a/tasks/steps/variables_from_inventory.yml +++ b/tasks/steps/variables_from_inventory.yml @@ -2,27 +2,34 @@ - name: Abort on deprecated feature -> the "sso" inventory group fail: - msg: > + msg: >- You are currently using a deprecated feature (the 'sso' group in your inventory). Please replace it with the 'threescale_cicd_sso_issuer_endpoint' variable. Alternatively, you can also bypass this warning by setting the 'threescale_cicd_deprecated_features' extra variable to 'true'. - when: 'threescale_cicd_sso_issuer_endpoint|default("")|length > 0 and ''sso'' in groups and groups[''sso''] > 0 and threescale_cicd_api_backend_version == ''oidc'' and not threescale_cicd_deprecated_features|default(false)|bool' + when: >- + threescale_cicd_sso_issuer_endpoint|default("")|length > 0 and 'sso' in groups + and groups['sso'] > 0 and threescale_cicd_api_backend_version == 'oidc' + and not threescale_cicd_deprecated_features|default(false)|bool - name: Abort on deprecated feature -> the "apicast-sandbox" inventory group fail: - msg: > + msg: >- You are currently using a deprecated feature (the 'apicast-sandbox' group in your inventory). Please replace it with the 'threescale_cicd_apicast_sandbox_endpoint' variable. Alternatively, you can also bypass this warning by setting the 'threescale_cicd_deprecated_features' extra variable to 'true'. - when: 'threescale_cicd_apicast_sandbox_endpoint|default("")|length > 0 and ''apicast-sandbox'' in groups and groups[''apicast-sandbox''] > 0 and not threescale_cicd_deprecated_features|default(false)|bool' + when: >- + threescale_cicd_apicast_sandbox_endpoint|default("")|length > 0 and 'apicast-sandbox' in groups + and groups['apicast-sandbox'] > 0 and not threescale_cicd_deprecated_features|default(false)|bool - name: Abort on deprecated feature -> the "apicast-production" inventory group fail: - msg: > + msg: >- You are currently using a deprecated feature (the 'apicast-production' group in your inventory). Please replace it with the 'threescale_cicd_apicast_production_endpoint' variable. Alternatively, you can also bypass this warning by setting the 'threescale_cicd_deprecated_features' extra variable to 'true'. - when: 'threescale_cicd_apicast_production_endpoint|default("")|length > 0 and ''apicast-production'' in groups and groups[''apicast-production''] > 0 and not threescale_cicd_deprecated_features|default(false)|bool' + when: >- + threescale_cicd_apicast_production_endpoint|default("")|length > 0 and 'apicast-production' in groups + and groups['apicast-production'] > 0 and not threescale_cicd_deprecated_features|default(false)|bool diff --git a/tests/setup/delete-travis-logs.yml b/tests/setup/delete-travis-logs.yml index 967308c..cfd9044 100644 --- a/tests/setup/delete-travis-logs.yml +++ b/tests/setup/delete-travis-logs.yml @@ -53,4 +53,3 @@ with_items: '{{ travis_jobs }}' vars: travis_jobs: '{{ get_build_response.json|json_query(''@.matrix[].id'') }}' -