[type/__postgres_role] Lint

This commit is contained in:
Dennis Camera 2020-12-15 18:40:39 +01:00
parent 71f2283117
commit 932e2496ed
2 changed files with 58 additions and 52 deletions

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
@ -18,23 +18,23 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
case "$("${__explorer}/os")"
case $("${__explorer:?}/os")
in
netbsd)
(netbsd)
postgres_user='pgsql'
;;
openbsd)
(openbsd)
postgres_user='_postgresql'
;;
*)
(*)
postgres_user='postgres'
;;
esac
name="$__object_id"
rolename=${__object_id:?}
if test -n "$(su - "$postgres_user" -c "psql postgres -twAc \"SELECT 1 FROM pg_roles WHERE rolname='$name'\"")"
if test -n "$(su - "${postgres_user}" -c "psql postgres -twAc \"SELECT 1 FROM pg_roles WHERE rolname='${rolename}'\"")"
then
echo 'present'
else

View file

@ -18,48 +18,54 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
case "$(cat "${__global}/explorer/os")"
case $(cat "${__global:?}/explorer/os")
in
netbsd)
(netbsd)
postgres_user='pgsql'
;;
openbsd)
(openbsd)
postgres_user='_postgresql'
;;
*)
(*)
postgres_user='postgres'
;;
esac
name="$__object_id"
state_is="$(cat "$__object/explorer/state")"
state_should="$(cat "$__object/parameter/state")"
rolename=${__object_id:?}
state_is=$(cat "${__object:?}/explorer/state")
state_should=$(cat "${__object:?}/parameter/state")
[ "$state_is" = "$state_should" ] && exit 0
case "$state_should" in
present)
if [ -f "$__object/parameter/password" ]; then
password="$(cat "$__object/parameter/password")"
if test "${state_is}" = "${state_should}"
then
exit 0
fi
booleans=""
for boolean in login createdb createrole superuser; do
if [ ! -f "$__object/parameter/$boolean" ]; then
case ${state_should}
in
(present)
if test -f "${__object:?}/parameter/password"
then
password=$(cat "${__object:?}/parameter/password")
fi
booleans=
for boolean in login createdb createrole superuser
do
if test ! -f "${__object:?}/parameter/${boolean}"
then
boolean="no${boolean}"
fi
upper=$(echo $boolean | tr '[:lower:]' '[:upper:]')
booleans="$booleans $upper"
booleans="${booleans} $(echo ${boolean} | tr '[:lower:]' '[:upper:]')"
done
[ -n "$password" ] && password="PASSWORD '$password'"
[ -n "${password}" ] && password="PASSWORD '${password}'"
cat << EOF
su - '$postgres_user' -c "psql postgres -wc \"CREATE ROLE \\\\\"$name\\\\\" WITH $password $booleans;\""
su - '${postgres_user}' -c "psql postgres -wc 'CREATE ROLE \\"${rolename}\\" WITH ${password} ${booleans};'"
EOF
;;
absent)
(absent)
cat << EOF
su - '$postgres_user' -c "dropuser \"$name\""
su - '${postgres_user}' -c "dropuser '${rolename}'"
EOF
;;
esac