From 3c52710763a3f8537f732e716e53439d1b6af494 Mon Sep 17 00:00:00 2001
From: Daniel Heule <hda@sfs.biz>
Date: Mon, 3 Feb 2014 21:43:39 +0100
Subject: [PATCH] little changes for using default parameters correctly

---
 cdist/conf/type/__git/gencode-remote              | 15 +++++----------
 cdist/conf/type/__git/manifest                    |  3 +--
 cdist/conf/type/__git/parameter/default/branch    |  1 +
 cdist/conf/type/__git/parameter/default/group     |  1 +
 cdist/conf/type/__git/parameter/default/mode      |  1 +
 cdist/conf/type/__git/parameter/default/owner     |  1 +
 cdist/conf/type/__git/parameter/default/state     |  1 +
 cdist/conf/type/__jail/gencode-local              | 12 ++----------
 cdist/conf/type/__jail/gencode-remote             | 13 +++----------
 cdist/conf/type/__jail/manifest                   |  6 +-----
 .../type/__jail/parameter/default/devfs-ruleset   |  1 +
 cdist/conf/type/__jail/parameter/default/jailbase |  1 +
 cdist/conf/type/__jail/parameter/default/jaildir  |  1 +
 cdist/conf/type/__package_yum/gencode-remote      |  6 +-----
 .../type/__package_yum/parameter/default/state    |  1 +
 cdist/conf/type/__package_zypper/gencode-remote   | 13 ++-----------
 .../type/__package_zypper/parameter/default/state |  1 +
 cdist/conf/type/__user_groups/gencode-remote      |  2 +-
 .../type/__user_groups/parameter/default/state    |  1 +
 19 files changed, 27 insertions(+), 54 deletions(-)
 create mode 100644 cdist/conf/type/__git/parameter/default/branch
 create mode 100644 cdist/conf/type/__git/parameter/default/group
 create mode 100644 cdist/conf/type/__git/parameter/default/mode
 create mode 100644 cdist/conf/type/__git/parameter/default/owner
 create mode 100644 cdist/conf/type/__git/parameter/default/state
 create mode 100644 cdist/conf/type/__jail/parameter/default/devfs-ruleset
 create mode 100644 cdist/conf/type/__jail/parameter/default/jailbase
 create mode 100644 cdist/conf/type/__jail/parameter/default/jaildir
 create mode 100644 cdist/conf/type/__package_yum/parameter/default/state
 create mode 100644 cdist/conf/type/__package_zypper/parameter/default/state
 create mode 100644 cdist/conf/type/__user_groups/parameter/default/state

diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote
index d719a492..c4fc1ef2 100644
--- a/cdist/conf/type/__git/gencode-remote
+++ b/cdist/conf/type/__git/gencode-remote
@@ -23,22 +23,17 @@ state_is="$(cat "$__object/explorer/state")"
 owner_is="$(cat "$__object/explorer/owner")"
 group_is="$(cat "$__object/explorer/group")"
 
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
+state_should="$(cat "$__object/parameter/state")"
 
-branch=master
-[ -f "$__object/parameter/branch" ] && branch="$(cat "$__object/parameter/branch")"
+branch="$(cat "$__object/parameter/branch")"
 
 source="$(cat "$__object/parameter/source")"
 
 destination="/$__object_id"
 
-owner=""
-[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")"
-group=""
-[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")"
-mode=""
-[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")"
+owner="$(cat "$__object/parameter/owner")"
+group="$(cat "$__object/parameter/group")"
+mode="$(cat "$__object/parameter/mode")"
 
 [  "$state_should" = "$state_is" -a \
    "$owner" = "$owner_is" -a \
diff --git a/cdist/conf/type/__git/manifest b/cdist/conf/type/__git/manifest
index 8d6a29e4..7f6fee84 100644
--- a/cdist/conf/type/__git/manifest
+++ b/cdist/conf/type/__git/manifest
@@ -23,8 +23,7 @@
 
 __package git --state present
 
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
+state_should="$(cat "$__object/parameter/state")"
 
 # Let __directory handle removal of git repos
 
diff --git a/cdist/conf/type/__git/parameter/default/branch b/cdist/conf/type/__git/parameter/default/branch
new file mode 100644
index 00000000..1f7391f9
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/branch
@@ -0,0 +1 @@
+master
diff --git a/cdist/conf/type/__git/parameter/default/group b/cdist/conf/type/__git/parameter/default/group
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/group
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__git/parameter/default/mode b/cdist/conf/type/__git/parameter/default/mode
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/mode
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__git/parameter/default/owner b/cdist/conf/type/__git/parameter/default/owner
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/owner
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__git/parameter/default/state b/cdist/conf/type/__git/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__jail/gencode-local b/cdist/conf/type/__jail/gencode-local
index d6384156..08c7b7bf 100755
--- a/cdist/conf/type/__jail/gencode-local
+++ b/cdist/conf/type/__jail/gencode-local
@@ -22,17 +22,9 @@
 #  virtual machines.
 #
 
-if [ -f "$__object/parameter/jaildir" ]; then
-   jaildir="$(cat "$__object/parameter/jaildir")"
-else
-   jaildir="/usr/jail"
-fi
+jaildir="$(cat "$__object/parameter/jaildir")"
 
-if [ -f "$__object/parameter/jailbase" ]; then
-   jailbase="$(cat "$__object/parameter/jailbase")"
-else
-   jailbase=""
-fi
+jailbase="$(cat "$__object/parameter/jailbase")"
 
 state="$(cat "$__object/parameter/state")"
 
diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail/gencode-remote
index afbb81a5..141c8150 100755
--- a/cdist/conf/type/__jail/gencode-remote
+++ b/cdist/conf/type/__jail/gencode-remote
@@ -66,11 +66,7 @@ else
    devfsenable="true"
 fi
 
-if [ -f "$__object/parameter/devfs-ruleset" ]; then
-   devfsruleset="$(cat "$__object/parameter/devfs-ruleset")"
-else
-   devfsruleset="jailrules"
-fi
+devfsruleset="$(cat "$__object/parameter/devfs-ruleset")"
 
 # devfs_ruleset being defined without devfs_enable being true
 #     is pointless. Treat this as an error.
@@ -84,14 +80,11 @@ if [ -f "$__object/parameter/onboot" ]; then
    onboot="true"
 fi
 
-if [ -f "$__object/parameter/jaildir" ]; then
-   jaildir="$(cat "$__object/parameter/jaildir")"
-else
-   jaildir="/usr/jail"
-fi
+jaildir="$(cat "$__object/parameter/jaildir")"
 
 present="$(cat "$__object/explorer/present")"
 status="$(cat "$__object/explorer/status")"
+
 # Handle ip="iface|addr, iface|addr" format
 if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then
    # If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it
diff --git a/cdist/conf/type/__jail/manifest b/cdist/conf/type/__jail/manifest
index cf5b7938..6a953241 100755
--- a/cdist/conf/type/__jail/manifest
+++ b/cdist/conf/type/__jail/manifest
@@ -33,11 +33,7 @@ if [ ! "$os" = "freebsd" ]; then
 	exit 1
 fi
 
-if [ -f "$__object/parameter/jaildir" ]; then
-   jaildir="$(cat "$__object/parameter/jaildir")"
-else
-   jaildir="/usr/jail"
-fi
+jaildir="$(cat "$__object/parameter/jaildir")"
 
 __directory ${jaildir} --parents
 
diff --git a/cdist/conf/type/__jail/parameter/default/devfs-ruleset b/cdist/conf/type/__jail/parameter/default/devfs-ruleset
new file mode 100644
index 00000000..f602aa0a
--- /dev/null
+++ b/cdist/conf/type/__jail/parameter/default/devfs-ruleset
@@ -0,0 +1 @@
+jailrules
diff --git a/cdist/conf/type/__jail/parameter/default/jailbase b/cdist/conf/type/__jail/parameter/default/jailbase
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__jail/parameter/default/jailbase
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__jail/parameter/default/jaildir b/cdist/conf/type/__jail/parameter/default/jaildir
new file mode 100644
index 00000000..ec7d86c6
--- /dev/null
+++ b/cdist/conf/type/__jail/parameter/default/jaildir
@@ -0,0 +1 @@
+/usr/jail
diff --git a/cdist/conf/type/__package_yum/gencode-remote b/cdist/conf/type/__package_yum/gencode-remote
index 9c98c257..5f0e8ac8 100755
--- a/cdist/conf/type/__package_yum/gencode-remote
+++ b/cdist/conf/type/__package_yum/gencode-remote
@@ -27,11 +27,7 @@ else
    name="$__object_id"
 fi
 
-if [ -f "$__object/parameter/state" ]; then
-   state_should="$(cat "$__object/parameter/state")"
-else
-   state_should="present"
-fi
+state_should="$(cat "$__object/parameter/state")"
 
 if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then
     opts="-y --quiet"
diff --git a/cdist/conf/type/__package_yum/parameter/default/state b/cdist/conf/type/__package_yum/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__package_yum/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__package_zypper/gencode-remote b/cdist/conf/type/__package_zypper/gencode-remote
index 51713590..d9f16f8d 100644
--- a/cdist/conf/type/__package_zypper/gencode-remote
+++ b/cdist/conf/type/__package_zypper/gencode-remote
@@ -34,17 +34,8 @@ else
     name="$__object_id"
 fi
 
-if [ -f "$__object/parameter/state" ]; then
-    state_should="$(cat "$__object/parameter/state")"
-else
-    state_should="present"
-fi
-
-if [ -f "$__object/parameter/ptype" ]; then
-    ptype="$(cat "$__object/parameter/ptype")"
-else
-    ptype="package"
-fi
+state_should="$(cat "$__object/parameter/state")"
+ptype="$(cat "$__object/parameter/ptype")"
 
 if [ -f "$__object/parameter/version" ]; then
     version_should="$(cat "$__object/parameter/version")"
diff --git a/cdist/conf/type/__package_zypper/parameter/default/state b/cdist/conf/type/__package_zypper/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__package_zypper/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote
index c5e4a35e..9f11dd16 100755
--- a/cdist/conf/type/__user_groups/gencode-remote
+++ b/cdist/conf/type/__user_groups/gencode-remote
@@ -19,7 +19,7 @@
 #
 
 user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")"
-state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
+state_should="$(cat "$__object/parameter/state")"
 
 mkdir "$__object/files"
 # file has to be sorted for comparison with `comm`
diff --git a/cdist/conf/type/__user_groups/parameter/default/state b/cdist/conf/type/__user_groups/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__user_groups/parameter/default/state
@@ -0,0 +1 @@
+present