[type/__postgres_database] Proper quoting in state explorer

This commit is contained in:
Dennis Camera 2021-04-16 19:35:26 +02:00
parent 8296051653
commit 0d33407b18

View file

@ -21,9 +21,14 @@
postgres_user=$("${__type_explorer:?}/postgres_user") postgres_user=$("${__type_explorer:?}/postgres_user")
name=${__object_id:?} dbname=${__object_id:?}
if test -n "$(su - "${postgres_user}" -c "psql postgres -twAc \"SELECT 1 FROM pg_database WHERE datname='${name}'\"")" quote() { printf '%s\n' "$*" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"; }
psql_exec() {
su - "${postgres_user}" -c "psql $(quote "$1") -twAc $(quote "$2")"
}
if psql_exec postgres "SELECT datname FROM pg_database" | grep -qFx "${dbname}"
then then
echo 'present' echo 'present'
else else