#!/usr/bin/env bash ROOT="$(dirname $0)/.." SCHEME="https:" DOMAIN="services.inist.fr" allItems="" process () { SWAGGER_FILE=$1 LOGIN=$2 PASSW=$3 if [ ! -e "${SWAGGER_FILE}" ]; then echo "No swagger file !" return 1 fi SWAGGER_DIRECTORY=$(dirname "${SWAGGER_FILE}") SWAGGER_CONTENT=$() NAME=$(basename "${SWAGGER_DIRECTORY}") TITLE=$(cat "${SWAGGER_FILE}"|jq .info.title) if [ "${TITLE:-null}" = "null" ] then logger -s "${NAME} - ERROR: swagger has no title !" return 2 fi SUMMARY=$(cat "${SWAGGER_FILE}"|jq .info.summary) if [ "${SUMMARY:-null}" = "null" ] then logger -s "${NAME} - ERROR: swagger has no summary !" return 3 fi SERVERS=$(cat "${SWAGGER_FILE}"|jq -r ".servers") if [ "${SERVERS:-null}" = "null" ] then logger -s "${NAME} - ERROR: swagger has no servers!" return 4 fi URL=$(cat "${SWAGGER_FILE}"|jq -r ".servers[] | select(.\"x-profil\").url"|sed -e "s/^/ - url: /") if [ "${URL:-null}" = "null" ] then logger -s "${NAME} - ERROR: swagger has no url !" return 5 fi # First profil will be used for all url PROFIL=$(cat "${SWAGGER_FILE}"|jq -r ".servers[] | select(.\"x-profil\").\"x-profil\""|head -n 1) case ${PROFIL} in Standard | Deprecated | Reserved | Administrator ) echo -n "${NAME} - ${PROFIL} - " ;; * ) logger -s "${NAME} - ERROR: swagger has no valid x-profil !" return 6 ;; esac CURL_OUTFILE=$(tempfile) cat <<EOF | curl --silent --user "${LOGIN}:${PASSW}" -T - "http://vptdmservices.intra.inist.fr:35270/internal-proxy-2/data/${NAME}.yml" --digest --write-out %{http_code} --output /dev/null > ${CURL_OUTFILE} http: routers: Router-${NAME}: entryPoints: - "web" middlewares: - "Middleware-${PROFIL}" service: "Service-${NAME}" rule: "Host(\`${NAME}.${DOMAIN}\`) || HostRegexp(\`${NAME}-{id:[0-9]+}.${DOMAIN}\`)" services: Service-${NAME}: loadBalancer: servers: ${URL} EOF HTTP_CODE=$(cat ${CURL_OUTFILE}; rm ${CURL_OUTFILE}) echo "${HTTP_CODE}" allItems+="{ url: \"${SCHEME}//${NAME}.${DOMAIN}\", name: ${TITLE} }," return 0 } FILES=$(ls ${ROOT}/*/swagger.json) echo -n "Login: " read login echo -n "Password: " read -s passw echo " " for swagger in ${FILES} do process $swagger $login $passw done echo -n "www-home-4 - Index - " CURL_OUTFILE=$(tempfile) cat <<EOF | curl --silent --user "${login}:${passw}" -T - "http://vptdmservices.intra.inist.fr:35270/www-home-4/data/index.html" --digest --write-out %{http_code} --output /dev/null > ${CURL_OUTFILE} <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <title>OpenAPI - Web Services Inist-CNRS</title> <link rel="stylesheet" type="text/css" href="./swagger-ui@4.15.5/swagger-ui.css"> </head> <body> <div id="swagger-ui"></div> <script src="./swagger-ui@4.15.5/swagger-ui-standalone-preset.js"></script> <script src="./swagger-ui@4.15.5/swagger-ui-bundle.js"></script> <script> window.onload = function () { // Build a system const ui = SwaggerUIBundle({ urls: [ ${allItems} ], queryConfigEnabled: true, dom_id: '#swagger-ui', deepLinking: true, presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout", }) window.ui = ui } </script> </body> </html> EOF HTTP_CODE=$(cat ${CURL_OUTFILE}; rm ${CURL_OUTFILE}) echo "${HTTP_CODE}"