[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) # 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# #
@ -11,32 +11,32 @@
# #
# cdist is distributed in the hope that it will be useful, # cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
case "$("${__explorer}/os")" case $("${__explorer:?}/os")
in in
netbsd) (netbsd)
postgres_user='pgsql' postgres_user='pgsql'
;; ;;
openbsd) (openbsd)
postgres_user='_postgresql' postgres_user='_postgresql'
;; ;;
*) (*)
postgres_user='postgres' postgres_user='postgres'
;; ;;
esac 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 then
echo 'present' echo 'present'
else else
echo 'absent' echo 'absent'
fi fi

View File

@ -11,55 +11,61 @@
# #
# cdist is distributed in the hope that it will be useful, # cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
case "$(cat "${__global}/explorer/os")" case $(cat "${__global:?}/explorer/os")
in in
netbsd) (netbsd)
postgres_user='pgsql' postgres_user='pgsql'
;; ;;
openbsd) (openbsd)
postgres_user='_postgresql' postgres_user='_postgresql'
;; ;;
*) (*)
postgres_user='postgres' postgres_user='postgres'
;; ;;
esac esac
name="$__object_id" rolename=${__object_id:?}
state_is="$(cat "$__object/explorer/state")" state_is=$(cat "${__object:?}/explorer/state")
state_should="$(cat "$__object/parameter/state")" state_should=$(cat "${__object:?}/parameter/state")
[ "$state_is" = "$state_should" ] && exit 0 if test "${state_is}" = "${state_should}"
then
exit 0
fi
case "$state_should" in case ${state_should}
present) in
if [ -f "$__object/parameter/password" ]; then (present)
password="$(cat "$__object/parameter/password")" if test -f "${__object:?}/parameter/password"
fi then
booleans="" password=$(cat "${__object:?}/parameter/password")
for boolean in login createdb createrole superuser; do fi
if [ ! -f "$__object/parameter/$boolean" ]; then booleans=
boolean="no${boolean}" for boolean in login createdb createrole superuser
fi do
upper=$(echo $boolean | tr '[:lower:]' '[:upper:]') if test ! -f "${__object:?}/parameter/${boolean}"
booleans="$booleans $upper" then
done boolean="no${boolean}"
fi
booleans="${booleans} $(echo ${boolean} | tr '[:lower:]' '[:upper:]')"
done
[ -n "$password" ] && password="PASSWORD '$password'" [ -n "${password}" ] && password="PASSWORD '${password}'"
cat << EOF 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 EOF
;; ;;
absent) (absent)
cat << EOF cat << EOF
su - '$postgres_user' -c "dropuser \"$name\"" su - '${postgres_user}' -c "dropuser '${rolename}'"
EOF EOF
;; ;;
esac esac