From 95b2b6bbc259ac4d401d32e119441eda82771868 Mon Sep 17 00:00:00 2001 From: Tom Ridd Date: Tue, 9 Aug 2022 09:58:46 +0100 Subject: [PATCH] add swagger ui to cantabular-import stack on port 9000 --- cantabular-import/deps.yml | 26 +++++++++- .../swagger/dp-configuration.yaml | 50 ++++++++++++++++++ .../swagger/dp-configure-swagger.sh | 52 +++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 cantabular-import/swagger/dp-configuration.yaml create mode 100755 cantabular-import/swagger/dp-configure-swagger.sh diff --git a/cantabular-import/deps.yml b/cantabular-import/deps.yml index 91c40f50..912b9b81 100644 --- a/cantabular-import/deps.yml +++ b/cantabular-import/deps.yml @@ -1,4 +1,4 @@ -version: '3.3' +version: '3.5' services: mongodb: image: mongo:3.6 @@ -121,3 +121,27 @@ services: - kafka-1 - kafka-2 - kafka-3 + swagger-ui: + image: swaggerapi/swagger-ui + ports: + - "9000:8080" + volumes: + - ${PWD}/../../dp-cantabular-filter-flex-api/swagger.yaml:/services/dp-cantabular-filter-flex-api.yaml + - ${PWD}/../../dp-dataset-api/swagger.yaml:/services/dp-dataset-api.yaml + - ${PWD}/../../dp-filter-api/swagger.yaml:/services/dp-filter-api.yaml + - ${PWD}/../../dp-import-api/swagger.yaml:/services/dp-import-api.yaml + - ${PWD}/../../dp-population-types-api/swagger.yaml:/services/dp-population-types-api.yaml + - ${PWD}/../../dp-recipe-api/swagger.yaml:/services/dp-recipe-api.yaml + - ${PWD}/../../zebedee/zebedee.yaml:/services/zebedee.yaml + - ${PWD}/swagger/dp-configuration.yaml:/dp-configuration.yaml + - ${PWD}/swagger/dp-configure-swagger.sh:/docker-entrypoint.d/00-dp-configure-swagger.sh # mount custom configure script into swagger entrypoint directory + environment: + URLS: "[ + { url: \"./dp-cantabular-filter-flex-api.yaml\", name: \"dp-cantabular-filter-flex-api\" }, + { url: \"./dp-dataset-api.yaml\", name: \"dp-dataset-api\" }, + { url: \"./dp-filter-api.yaml\", name: \"dp-filter-api\" }, + { url: \"./dp-import-api.yaml\", name: \"dp-import-api\" }, + { url: \"./dp-population-types-api.yaml\", name: \"dp-population-types-api\" }, + { url: \"./dp-recipe-api.yaml\", name: \"dp-recipe-api\" }, + { url: \"./zebedee.yaml\", name: \"zebedee\" }, + ]" diff --git a/cantabular-import/swagger/dp-configuration.yaml b/cantabular-import/swagger/dp-configuration.yaml new file mode 100644 index 00000000..e9e489b0 --- /dev/null +++ b/cantabular-import/swagger/dp-configuration.yaml @@ -0,0 +1,50 @@ +services: + "dp-cantabular-filter-flex-api": + openapi: 3.0.0 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: http://api.localhost:23200/v1 + description: Local dp-cantabular-filter-flex-api + "dp-dataset-api": + openapi: 3.0.0 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: http://api.localhost:23200/v1 + description: Local dp-dataset-api + "dp-filter-api": + openapi: 3.0.0 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: http://api.localhost:23200/v1 + description: Local dp-filter-api + "dp-import-api": + openapi: 3.0.0 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: https://localhost:21800/v1 + description: Local dp-import-api + "dp-population-types-api": + openapi: 3.0.0 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: http://api.localhost:23200/v1 + description: Local dp-population-api + "dp-recipe-api": + openapi: 3.0.0 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: https://api.localhost:22300/v1 + description: Local dp-recipe-api + "zebedee": + openapi: 3.0.3 + servers: + - url: https://api.dp.aws.onsdigital.uk/v1 + description: Sandbox server + - url: https://localhost:8082 + description: Local zebedee \ No newline at end of file diff --git a/cantabular-import/swagger/dp-configure-swagger.sh b/cantabular-import/swagger/dp-configure-swagger.sh new file mode 100755 index 00000000..725cc1f3 --- /dev/null +++ b/cantabular-import/swagger/dp-configure-swagger.sh @@ -0,0 +1,52 @@ +#!/bin/sh +echo "installing yq" +apt-get update +apt-get install -y wget +VERSION=v4.26.1 +BINARY=yq_linux_386 +wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O /usr/bin/yq \ + && chmod +x /usr/bin/yq + + +CONFIG_FILE='/dp-configuration.yaml' + +configure_service() +{ + KEY=$1 + + ORIGIN=/services/${KEY}.yaml + SWAGGER_FILE=/usr/share/nginx/html/${KEY}.yaml + cp ${ORIGIN} ${SWAGGER_FILE} + + # Get new config + SERVERS=$(yq ".services.$KEY.servers" ${CONFIG_FILE}) + OPENAPI=$(yq ".services.$KEY.openapi" ${CONFIG_FILE}) + + # Remove config variables + yq -i 'del(.swagger)' ${SWAGGER_FILE} + yq -i 'del(.openapi)' ${SWAGGER_FILE} + yq -i 'del(.basePath)' ${SWAGGER_FILE} + yq -i 'del(.servers)' ${SWAGGER_FILE} + + # Add OpenApi 3.* config + yq -i ".openapi = \"$OPENAPI\"" ${SWAGGER_FILE} + yq -i ".servers = \"$SERVERS"\" ${SWAGGER_FILE} + sed -i 's/servers: |-/servers:/g' ${SWAGGER_FILE} + + yq -i ".components.securitySchemes.Authorization.type = \"apiKey\"" ${SWAGGER_FILE} + yq -i ".components.securitySchemes.Authorization.description = \"Service Auth Token\"" ${SWAGGER_FILE} + yq -i ".components.securitySchemes.Authorization.name = \"Authorization\"" ${SWAGGER_FILE} + yq -i ".components.securitySchemes.Authorization.in = \"header\"" ${SWAGGER_FILE} + yq -i ".security.Authorization = []" ${SWAGGER_FILE} + echo "- CONFIGURED ${KEY}" +} + +echo "----------------------------" + +echo "CONFIGURING SERVICES" +for SERVICE_FILE in $(ls /services/*.yaml) +do + configure_service $(basename $SERVICE_FILE .yaml) +done + +echo "----------------------------"