__postgres_role: switch to boolean, use shortcut version

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-11-02 22:56:45 +01:00
parent 03d224c74c
commit b6f61a632f
5 changed files with 38 additions and 34 deletions

View file

@ -22,33 +22,28 @@ name="$__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")"
if [ "$state_is" != "$state_should" ]; then [ "$state_is" = "$state_should" ] && exit 0
case "$state_should" in
case "$state_should" in
present) present)
optional="password if [ -f "$__object/parameter/password" ]; then
login password="$(cat "$__object/parameter/$parameter")"
createdb
createrole
superuser"
for parameter in $optional; do
if [ -f "$__object/parameter/$parameter" ]; then
value="$(cat "$__object/parameter/$parameter")"
eval $parameter=$value
fi fi
booleans=""
for boolean in login createdb createrole superuser; do
if [ ! -f "$__object/parameter/$boolean" ]; then
boolean="no${boolean}"
fi
upper=$(echo $boolean | tr '[a-z]' '[A-Z]')
booleans="$booleans $upper"
done done
[ -n "$password" ] && password="PASSWORD '$password'" [ -n "$password" ] && password="PASSWORD '$password'"
[ "$login" = "true" ] && login="LOGIN" || login="NOLOGIN"
[ "$createdb" = "true" ] && createdb="CREATEDB" || createdb="NOCREATEDB"
[ "$createrole" = "true" ] && createrole="CREATEROLE" || createrole="NOCREATEROLE"
[ "$superuser" = "true" ] && superuser="SUPERUSER" || superuser="NOSUPERUSER"
[ "$inherit" = "true" ] && inherit="INHERIT" || inherit="NOINHERIT"
cmd="CREATE ROLE $name WITH $password $login $createdb $createrole $superuser $inherit" cmd="CREATE ROLE $name WITH $password $booleans"
echo "su - postgres -c \"psql -c \\\"$cmd\\\"\"" echo "su - postgres -c \"psql -c \\\"$cmd\\\"\""
;; ;;
absent) absent)
echo "su - postgres -c \"dropuser \\\"$name\\\"\"" echo "su - postgres -c \"dropuser \\\"$name\\\"\""
;; ;;
esac esac
fi

View file

@ -21,17 +21,22 @@ state::
OPTIONAL PARAMETERS OPTIONAL PARAMETERS
------------------- -------------------
All optional parameter map directly to the corresponding postgres createrole All parameter map directly to the corresponding postgres createrole
parameters. parameters.
password:: password::
BOOLEAN PARAMETERS
------------------
All parameter map directly to the corresponding postgres createrole
parameters.
login:: login::
createdb:: createdb::
createrole:: createrole::
superuser:: superuser::
inherit:: inherit::
EXAMPLES EXAMPLES
-------- --------
@ -40,9 +45,9 @@ __postgres_role myrole --state present
__postgres_role myrole --state present --password 'secret' __postgres_role myrole --state present --password 'secret'
__postgres_role admin --state present --password 'very-secret' --superuser true __postgres_role admin --state present --password 'very-secret' --superuser
__postgres_role dbcustomer --state present --password 'bla' --createdb true __postgres_role dbcustomer --state present --password 'bla' --createdb
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -0,0 +1,5 @@
login
createdb
createrole
superuser
inherit

View file

@ -1,6 +1 @@
password password
login
createdb
createrole
superuser
inherit

View file

@ -10,6 +10,10 @@ Changelog
* Bugfix Type __rvm_ruby: Add clean package dependencies * Bugfix Type __rvm_ruby: Add clean package dependencies
* Bugfix Type __rvm_gem: Run rvm as user, not as root * Bugfix Type __rvm_gem: Run rvm as user, not as root
* Cleanup Type __rvm, __rvm_gemset: Use shortcut version * Cleanup Type __rvm, __rvm_gemset: Use shortcut version
* Bugfix __rvm_gemset: Correctly check for gemsets
* Cleanup Type __postgres_database, __postgres_role: Reference each other
in documentation
* Cleanp Type __postgres_role: Use boolean parameters where appropriate
2.1.0pre5: 2012-11-01 2.1.0pre5: 2012-11-01
* Core: First round of tests updated to work with multiple configuration directories * Core: First round of tests updated to work with multiple configuration directories