__postgres_role: switch to boolean, use shortcut version
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
03d224c74c
commit
b6f61a632f
5 changed files with 38 additions and 34 deletions
|
@ -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
|
|
||||||
present)
|
case "$state_should" in
|
||||||
optional="password
|
present)
|
||||||
login
|
if [ -f "$__object/parameter/password" ]; then
|
||||||
createdb
|
password="$(cat "$__object/parameter/$parameter")"
|
||||||
createrole
|
fi
|
||||||
superuser"
|
booleans=""
|
||||||
for parameter in $optional; do
|
for boolean in login createdb createrole superuser; do
|
||||||
if [ -f "$__object/parameter/$parameter" ]; then
|
if [ ! -f "$__object/parameter/$boolean" ]; then
|
||||||
value="$(cat "$__object/parameter/$parameter")"
|
boolean="no${boolean}"
|
||||||
eval $parameter=$value
|
|
||||||
fi
|
fi
|
||||||
done
|
upper=$(echo $boolean | tr '[a-z]' '[A-Z]')
|
||||||
|
booleans="$booleans $upper"
|
||||||
|
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
|
|
||||||
|
|
|
@ -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
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
5
cdist/conf/type/__postgres_role/parameter/boolean
Normal file
5
cdist/conf/type/__postgres_role/parameter/boolean
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
login
|
||||||
|
createdb
|
||||||
|
createrole
|
||||||
|
superuser
|
||||||
|
inherit
|
|
@ -1,6 +1 @@
|
||||||
password
|
password
|
||||||
login
|
|
||||||
createdb
|
|
||||||
createrole
|
|
||||||
superuser
|
|
||||||
inherit
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue