diff --git a/scripts/src/hwlab-node/secret-scripts.ts b/scripts/src/hwlab-node/secret-scripts.ts index ac9bf1e0..9100de2f 100644 --- a/scripts/src/hwlab-node/secret-scripts.ts +++ b/scripts/src/hwlab-node/secret-scripts.ts @@ -1381,6 +1381,30 @@ export function cloudApiDbSecretScript(options: NodeSecretOptions, spec: Runtime "secret_b64_key() { kubectl -n \"$namespace\" get secret \"$1\" -o \"go-template={{ index .data \\\"$2\\\" }}\" 2>/dev/null || true; }", "decoded_value() { if [ -n \"$1\" ]; then printf '%s' \"$1\" | base64 -d 2>/dev/null || true; fi; }", "decoded_length() { if [ -n \"$1\" ]; then printf '%s' \"$1\" | base64 -d 2>/dev/null | wc -c | tr -d ' '; else printf '0'; fi; }", + "parse_database_url() {", + " uri=$1", + " uri_host= uri_user= uri_database= uri_sslmode= uri_password_present=no", + " if [ -n \"$uri\" ]; then", + " rest=${uri#*://}", + " rest_no_query=${rest%%\\?*}", + " auth=${rest_no_query%@*}", + " host_path=${rest_no_query#*@}", + " if [ \"$host_path\" != \"$rest_no_query\" ]; then", + " uri_user=${auth%%:*}", + " if [ \"$auth\" != \"$uri_user\" ]; then uri_password_present=yes; fi", + " else", + " host_path=$rest_no_query", + " fi", + " host_port=${host_path%%/*}", + " uri_host=${host_port%%:*}", + " uri_database=${host_path#*/}", + " if [ \"$uri_database\" = \"$host_path\" ]; then uri_database=; fi", + " uri_database=${uri_database%%\\?*}", + " case \"$uri\" in", + " *sslmode=*) uri_sslmode=${uri#*sslmode=}; uri_sslmode=${uri_sslmode%%\\&*} ;;", + " esac", + " fi", + "}", "psql_scalar() { kubectl -n \"$namespace\" exec \"statefulset/$postgres_statefulset\" -c postgres -- env PGPASSWORD=\"$postgres_admin_password\" psql -U \"$postgres_admin_user\" -d postgres -tAc \"$1\" 2>/dev/null | tr -d '[:space:]'; }", "probe_db() {", " role_result=unknown",