[WIP] Configure SQL Proxy

This commit is contained in:
Kevin Baensch 2022-12-21 19:30:38 +01:00
parent 566c56c423
commit cfb82fd78a
4 changed files with 74 additions and 37 deletions

View file

@ -4,16 +4,29 @@ set -e
WRAP_START='[\n'
if ${EXCLUDE_USERPASS}
then
TEMPLATE=' { "type": "${LOCAL_DB_TYPE}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}" }'
TEMPLATE=' { "ip": "${LOCAL_IP}", "type": "${LOCAL_DB_TYPE}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}" }'
else
TEMPLATE=' { "type": "${LOCAL_DB_TYPE}", "user": "${LOCAL_DB_USER}", "password": "${LOCAL_DB_PASSWORD}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}" }'
TEMPLATE=' { "ip": "${LOCAL_IP}", "type": "${LOCAL_DB_TYPE}", "user": "${LOCAL_DB_USER}", "password": "${LOCAL_DB_PASSWORD}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}" }'
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}" = "psql" ]
then
LOCAL_DB_PORT='5432'
fi
fi
}
template_hook() {
if grep -q '"type": "(?mysql|psql)".*"host": ".+", port: "\d+"' <<< "${PARTIAL_RESULT}"
if [ "$(jq '((.type == "mysql") or (.type == "psql")) and (.host != "")' <<< "${PARTIAL_RESULT}" 2> /dev/null)" = true ]
then
return 0
fi