From dc39099730fbffb47cddffe74d80aaaba919533f Mon Sep 17 00:00:00 2001
From: nuex <nx@nu-ex.com>
Date: Mon, 17 Jun 2013 11:05:23 -0400
Subject: [PATCH] __postgres_role: make state parameter optional, fix password
 parameter checking in gencode-remote

---
 cdist/conf/type/__postgres_role/gencode-remote    |  3 ++-
 cdist/conf/type/__postgres_role/man.text          | 15 ++++++---------
 .../conf/type/__postgres_role/parameter/optional  |  1 +
 .../conf/type/__postgres_role/parameter/required  |  1 -
 4 files changed, 9 insertions(+), 11 deletions(-)
 delete mode 100644 cdist/conf/type/__postgres_role/parameter/required

diff --git a/cdist/conf/type/__postgres_role/gencode-remote b/cdist/conf/type/__postgres_role/gencode-remote
index c9de4707..8fb2c91d 100755
--- a/cdist/conf/type/__postgres_role/gencode-remote
+++ b/cdist/conf/type/__postgres_role/gencode-remote
@@ -21,13 +21,14 @@
 name="$__object_id"
 state_is="$(cat "$__object/explorer/state")"
 state_should="$(cat "$__object/parameter/state")"
+[ ! "$state_should" ] && state_should="present"
 
 [ "$state_is" = "$state_should" ] && exit 0
 
 case "$state_should" in
     present)
         if [ -f "$__object/parameter/password" ]; then
-            password="$(cat "$__object/parameter/$parameter")"
+            password="$(cat "$__object/parameter/password")"
         fi
         booleans=""
         for boolean in login createdb createrole superuser; do
diff --git a/cdist/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.text
index 904f0831..ac87754b 100644
--- a/cdist/conf/type/__postgres_role/man.text
+++ b/cdist/conf/type/__postgres_role/man.text
@@ -13,15 +13,12 @@ DESCRIPTION
 This cdist type allows you to create or drop postgres roles.
 
 
-REQUIRED PARAMETERS
+OPTIONAL PARAMETERS
 -------------------
 state::
     Either "present" or "absent", defaults to "present"
 
-
-OPTIONAL PARAMETERS
--------------------
-All parameter map directly to the corresponding postgres createrole
+All other parameters map directly to the corresponding postgres createrole
 parameters.
 
 password::
@@ -41,13 +38,13 @@ EXAMPLES
 --------
 
 --------------------------------------------------------------------------------
-__postgres_role myrole --state present
+__postgres_role myrole
 
-__postgres_role myrole --state present --password 'secret'
+__postgres_role myrole --password 'secret'
 
-__postgres_role admin --state present --password 'very-secret' --superuser
+__postgres_role admin --password 'very-secret' --superuser
 
-__postgres_role dbcustomer --state present --password 'bla' --createdb
+__postgres_role dbcustomer --password 'bla' --createdb
 --------------------------------------------------------------------------------
 
 
diff --git a/cdist/conf/type/__postgres_role/parameter/optional b/cdist/conf/type/__postgres_role/parameter/optional
index f3097ab1..cb9b2c48 100644
--- a/cdist/conf/type/__postgres_role/parameter/optional
+++ b/cdist/conf/type/__postgres_role/parameter/optional
@@ -1 +1,2 @@
+state
 password
diff --git a/cdist/conf/type/__postgres_role/parameter/required b/cdist/conf/type/__postgres_role/parameter/required
deleted file mode 100644
index ff72b5c7..00000000
--- a/cdist/conf/type/__postgres_role/parameter/required
+++ /dev/null
@@ -1 +0,0 @@
-state