#!/usr/bin/env bash EXCLUDE_USERPASS="${EXCLUDE_USERPASS:-false}" set -e WRAP_START='[\n' if ${EXCLUDE_USERPASS} then TEMPLATE=' { "ip": "${LOCAL_IP}", "type": "${LOCAL_DB_TYPE}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}", "dbname": "${LOCAL_DB_DBNAME}" }' else TEMPLATE=' { "ip": "${LOCAL_IP}", "type": "${LOCAL_DB_TYPE}", "user": "${LOCAL_DB_USER}", "port": "${LOCAL_DB_PORT}", "dbname": "${LOCAL_DB_DBNAME}", "password": "${LOCAL_DB_PASSWORD}", "host": "${LOCAL_DB_HOST}" }' fi SEPARATOR=',\n' WRAP_END='\n]' OUT="/config/sqlproxy.json" label_hook() { if [ -z "${LOCAL_DB_PORT}" ] then if [ "${LOCAL_DB_TYPE}" = "mysql" ] then LOCAL_DB_PORT='3306' elif [ "${LOCAL_DB_TYPE}" = "postgres" ] then LOCAL_DB_PORT='5432' fi fi } template_hook() { if [ "$(jq '((.type == "mysql") or (.type == "postgres")) and (.host != "")' <<< "${PARTIAL_RESULT}" 2> /dev/null)" = true ] then return 0 fi return 1 }