2022-12-13 17:04:48 +01:00
|
|
|
#!/usr/bin/env bash
|
2022-12-16 14:17:11 +01:00
|
|
|
EXCLUDE_USERPASS="${EXCLUDE_USERPASS:-false}"
|
2022-12-13 17:04:48 +01:00
|
|
|
set -e
|
|
|
|
WRAP_START='[\n'
|
2022-12-16 14:17:11 +01:00
|
|
|
if ${EXCLUDE_USERPASS}
|
|
|
|
then
|
2023-01-18 16:54:30 +01:00
|
|
|
TEMPLATE=' { "ip": "${LOCAL_IP}", "type": "${LOCAL_DB_TYPE}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}", "dbname": "${LOCAL_DB_DBNAME}" }'
|
2022-12-16 14:17:11 +01:00
|
|
|
else
|
2023-01-18 16:54:30 +01:00
|
|
|
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}" }'
|
2022-12-16 14:17:11 +01:00
|
|
|
fi
|
2022-12-13 17:04:48 +01:00
|
|
|
SEPARATOR=',\n'
|
|
|
|
WRAP_END='\n]'
|
2022-12-16 14:17:11 +01:00
|
|
|
OUT="/config/sqlproxy.json"
|
|
|
|
|
2022-12-21 19:30:38 +01:00
|
|
|
label_hook() {
|
2022-12-23 11:14:55 +01:00
|
|
|
if [ -z "${LOCAL_DB_PORT}" ]
|
2022-12-21 19:30:38 +01:00
|
|
|
then
|
|
|
|
if [ "${LOCAL_DB_TYPE}" = "mysql" ]
|
|
|
|
then
|
|
|
|
LOCAL_DB_PORT='3306'
|
2023-01-05 09:48:19 +01:00
|
|
|
elif [ "${LOCAL_DB_TYPE}" = "postgres" ]
|
2022-12-21 19:30:38 +01:00
|
|
|
then
|
|
|
|
LOCAL_DB_PORT='5432'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-12-16 14:17:11 +01:00
|
|
|
template_hook() {
|
2023-01-05 09:48:19 +01:00
|
|
|
if [ "$(jq '((.type == "mysql") or (.type == "postgres")) and (.host != "")' <<< "${PARTIAL_RESULT}" 2> /dev/null)" = true ]
|
2022-12-16 14:17:11 +01:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|