|
| 1 | +--- |
| 2 | +- name: Copy staging route template |
| 3 | + template: |
| 4 | + src: "{{ resources_dir }}/route.yml" |
| 5 | + dest: "{{ work_dir }}/route.yml" |
| 6 | + vars: |
| 7 | + name: "{{ service_name }}-staging" |
| 8 | + apicast_service: "{{ threescale_apicast_staging_svc }}" |
| 9 | + |
| 10 | +- name: Create staging route |
| 11 | + oc_obj: |
| 12 | + state: present |
| 13 | + oc_binary: "{{ openshift_cli }}" |
| 14 | + name: "{{ service_name }}-staging" |
| 15 | + kind: route |
| 16 | + namespace: "{{ namespace }}" |
| 17 | + files: |
| 18 | + - "{{ work_dir }}/route.yml" |
| 19 | + |
| 20 | +- name: Get staging route |
| 21 | + shell: oc get route {{ service_name }}-staging -n {{ namespace }} -o jsonpath='{.spec.host}' |
| 22 | + register: staging_route_result |
| 23 | + |
| 24 | +- set_fact: |
| 25 | + staging_route: "https://{{ staging_route_result.stdout }}" |
| 26 | + |
| 27 | +- name: Copy production route template |
| 28 | + template: |
| 29 | + src: "{{ resources_dir }}/route.yml" |
| 30 | + dest: "{{ work_dir }}/route.yml" |
| 31 | + vars: |
| 32 | + name: "{{ service_name }}-production" |
| 33 | + apicast_service: "{{ threescale_apicase_prod_svc }}" |
| 34 | + |
| 35 | +- name: Create production route |
| 36 | + oc_obj: |
| 37 | + state: present |
| 38 | + oc_binary: "{{ openshift_cli }}" |
| 39 | + name: "{{ service_name }}-production" |
| 40 | + kind: route |
| 41 | + namespace: "{{ namespace }}" |
| 42 | + files: |
| 43 | + - "{{ work_dir }}/route.yml" |
| 44 | + |
| 45 | +- name: Get production route |
| 46 | + shell: oc get route {{ service_name }}-production -n {{ namespace }} -o jsonpath='{.spec.host}' |
| 47 | + register: production_route_result |
| 48 | + |
| 49 | +- set_fact: |
| 50 | + production_route: "https://{{ production_route_result.stdout }}" |
| 51 | + |
| 52 | +- name: Create service |
| 53 | + uri: |
| 54 | + url: "{{ admin_route }}/admin/api/services.xml" |
| 55 | + method: POST |
| 56 | + return_content: yes |
| 57 | + headers: |
| 58 | + Content-Type: "application/x-www-form-urlencoded" |
| 59 | + body: "access_token={{ admintoken }}&name={{ service_name | urlencode }}&deployment_option=hosted&backend_version={{ '1' if backend_version == 'oidc' else backend_version }}&system_name={{ system_name }}" |
| 60 | + validate_certs: no |
| 61 | + status_code: [201, 422] |
| 62 | + register: create_svc_result |
| 63 | + |
| 64 | +- name: Get all services |
| 65 | + uri: |
| 66 | + url: "{{ admin_route }}/admin/api/services.xml?access_token={{ admintoken }}" |
| 67 | + method: GET |
| 68 | + return_content: yes |
| 69 | + validate_certs: no |
| 70 | + status_code: 200 |
| 71 | + register: list_svc_result |
| 72 | + |
| 73 | +- name: Get service Id |
| 74 | + xml: |
| 75 | + xmlstring: '{{ list_svc_result.content }}' |
| 76 | + xpath: //services//service//system_name[.='{{ system_name }}']/parent::service/id |
| 77 | + content: text |
| 78 | + register: xmlstring |
| 79 | + |
| 80 | +- debug: var=xmlstring.matches[0].id |
| 81 | + |
| 82 | +- set_fact: id={{ xmlstring.matches[0].id }} |
| 83 | + |
| 84 | +- set_fact: oidc_issuer={{ ( backend_version == 'oidc' and proxy_config.sso_endpoint is defined ) | ternary('&oidc_issuer_endpoint=' + ( proxy_config.sso_endpoint | default('') | urlencode ), '') }} |
| 85 | + |
| 86 | +- name: Config backend service proxy |
| 87 | + uri: |
| 88 | + url: "{{ admin_route }}/admin/api/services/{{ id }}/proxy.xml" |
| 89 | + method: PATCH |
| 90 | + return_content: yes |
| 91 | + headers: |
| 92 | + Content-Type: "application/x-www-form-urlencoded" |
| 93 | + body: "access_token={{ admintoken }}&endpoint={{ production_route | urlencode }}\ |
| 94 | + &sandbox_endpoint={{ staging_route | urlencode }}\ |
| 95 | + &api_backend={{ proxy_config.backend_endpoint | urlencode }}\ |
| 96 | + {{ oidc_issuer }}" |
| 97 | + validate_certs: no |
| 98 | + when: proxy_config is defined |
| 99 | + |
| 100 | +- name: Create application plan |
| 101 | + uri: |
| 102 | + url: "{{ admin_route }}/admin/api/services/{{ id }}/application_plans.xml" |
| 103 | + method: POST |
| 104 | + return_content: yes |
| 105 | + headers: |
| 106 | + Content-Type: "application/x-www-form-urlencoded" |
| 107 | + body: "access_token={{ admintoken }}&name={{ application_plan.name | urlencode }}&system_name={{ application_plan.system_name }}&state=published" |
| 108 | + validate_certs: no |
| 109 | + status_code: [201, 422] |
| 110 | + register: create_plan_result |
| 111 | + when: application_plan is defined |
| 112 | + |
| 113 | +- name: Get all application plans |
| 114 | + uri: |
| 115 | + url: "{{ admin_route }}/admin/api/services/{{ id }}/application_plans.xml?access_token={{ admintoken }}" |
| 116 | + method: GET |
| 117 | + return_content: yes |
| 118 | + validate_certs: no |
| 119 | + status_code: 200 |
| 120 | + register: list_app_plans_result |
| 121 | + |
| 122 | +- name: Get plan Id |
| 123 | + xml: |
| 124 | + xmlstring: '{{ list_app_plans_result.content }}' |
| 125 | + xpath: //plans//plan//service_id[.='{{ id }}']/parent::plan/id |
| 126 | + content: text |
| 127 | + register: xmlstring |
| 128 | + when: application_plan is defined |
| 129 | + |
| 130 | +- debug: var=xmlstring.matches[0].id |
| 131 | + when: application_plan is defined |
| 132 | + |
| 133 | +- set_fact: plan_id={{ xmlstring.matches[0].id }} |
| 134 | + when: application_plan is defined |
| 135 | + |
| 136 | +- set_fact: redirect_uri={{ ( app_config.redirect_uri is defined ) | ternary('&redirect_url=' + ( app_config.redirect_uri | default('') | urlencode ), '') }} |
| 137 | + when: app_config is defined |
| 138 | + |
| 139 | +- debug: var=redirect_uri |
| 140 | + |
| 141 | +- name: Create application |
| 142 | + uri: |
| 143 | + url: "{{ admin_route }}/admin/api/accounts/{{ account_id }}/applications.xml" |
| 144 | + method: POST |
| 145 | + return_content: yes |
| 146 | + headers: |
| 147 | + Content-Type: "application/x-www-form-urlencoded" |
| 148 | + body: "access_token={{ admintoken }}&plan_id={{ plan_id }}&name={{ app_config.name }}\ |
| 149 | + &description={{ app_config.description }}&application_id={{ app_config.id }}\ |
| 150 | + &user_key=12345{{ redirect_uri }}" |
| 151 | + validate_certs: no |
| 152 | + status_code: [201, 422] |
| 153 | + register: create_app_result |
| 154 | + when: app_config is defined |
| 155 | + |
| 156 | +- name: Get policy chain template |
| 157 | + shell: 'cat {{ resources_dir }}/policy-config.json' |
| 158 | + register: get_policies |
| 159 | + when: proxy_config is defined |
| 160 | + |
| 161 | +- debug: var=get_policies.stdout |
| 162 | + when: proxy_config is defined |
| 163 | + |
| 164 | +- name: Enable CORS |
| 165 | + uri: |
| 166 | + url: "{{ admin_route }}/admin/api/services/{{ id }}/proxy/policies.json" |
| 167 | + method: PUT |
| 168 | + return_content: yes |
| 169 | + headers: |
| 170 | + Content-Type: "application/x-www-form-urlencoded" |
| 171 | + body: "access_token={{ admintoken }}&policies_config={{ get_policies.stdout | urlencode }}" |
| 172 | + validate_certs: no |
| 173 | + status_code: 200 |
| 174 | + register: update_policies_result |
| 175 | + when: proxy_config is defined |
| 176 | + |
| 177 | +- set_fact: |
| 178 | + config_key: "APICAST_{{ service_name | replace('-', '_') | upper }}" |
| 179 | + |
| 180 | +- name: Set config |
| 181 | + shell: oc set env dc/{{ config_deployment_name }} -n {{ config_deployment_namespace }} {{ config_key }}={{ production_route }} |
0 commit comments