diff options
author | Azul <azul@riseup.net> | 2013-08-15 11:44:18 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2013-08-28 12:52:14 +0200 |
commit | 16a3583c359cd57ff52866a8dfd933726d120d30 (patch) | |
tree | 6cd32d441d50fab4edb33275b3fb9d55f52cf622 /manifests | |
parent | fbe74fd5aef6e26070e9b10357604dda3bd2d842 (diff) |
couch:document - ensure state of a couch document - (feature #3485)
also made the use of host, hostname and port a bit more consistent.
Diffstat (limited to 'manifests')
-rw-r--r-- | manifests/bigcouch/add_node.pp | 2 | ||||
-rw-r--r-- | manifests/bigcouch/query.pp | 4 | ||||
-rw-r--r-- | manifests/create_db.pp | 10 | ||||
-rw-r--r-- | manifests/document.pp | 39 | ||||
-rw-r--r-- | manifests/query.pp | 4 |
5 files changed, 49 insertions, 10 deletions
diff --git a/manifests/bigcouch/add_node.pp b/manifests/bigcouch/add_node.pp index da10db2..66ac9b6 100644 --- a/manifests/bigcouch/add_node.pp +++ b/manifests/bigcouch/add_node.pp @@ -2,6 +2,6 @@ define couchdb::bigcouch::add_node { couchdb::bigcouch::query { "add_${name}": cmd => 'PUT', - url => "nodes/bigcouch@${name}" + path => "nodes/bigcouch@${name}" } } diff --git a/manifests/bigcouch/query.pp b/manifests/bigcouch/query.pp index cecfe5a..8228e82 100644 --- a/manifests/bigcouch/query.pp +++ b/manifests/bigcouch/query.pp @@ -1,10 +1,10 @@ define couchdb::bigcouch::query ( - $cmd, $url, $host='127.0.0.1:5986', $data = '{}' ) { + $cmd, $path, $host='127.0.0.1:5986', $data = '{}' ) { couchdb::query { "${name}": cmd => $cmd, host => $host, - url => $url, + path => $path, data => $data } } diff --git a/manifests/create_db.pp b/manifests/create_db.pp index 91c4a1d..f0bed31 100644 --- a/manifests/create_db.pp +++ b/manifests/create_db.pp @@ -3,19 +3,19 @@ define couchdb::create_db ( $host='127.0.0.1:5984', $readers="{\"names\": [], \"roles\": [] }" ) { - Couchdb::Query["create_db_${name}"] -> Couchdb::Query["db_security_${name}"] + Couchdb::Query["create_db_${name}"] -> Couchdb::Document["${name}_security"] couchdb::query { "create_db_${name}": cmd => 'PUT', host => $host, - url => $name, + path => $name, unless => "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc ${host}/${name}" } - couchdb::query { "db_security_${name}": - cmd => 'PUT', + couchdb::document { "${name}_security": + db => $name, + id => '_security', host => $host, - url => "${name}/_security", data => "{ \"admins\": ${admins}, \"readers\": ${readers} }" } } diff --git a/manifests/document.pp b/manifests/document.pp new file mode 100644 index 0000000..1b27d44 --- /dev/null +++ b/manifests/document.pp @@ -0,0 +1,39 @@ +# Usage: +# couchdb::document { id: +# db => "database", +# data => "content", +# ensure => {absent,present,*content*} +# } +# +define couchdb::document ( $host='127.0.0.1:5984', $db, $id, $data, $ensure='content') { + + $url = "${host}/${db}/${id}" + + case $ensure { + default: { err ( "unknown ensure value '${ensure}'" ) } + content: { + exec { "couch-doc-update --host ${host} --db ${db} --id ${id} --data \'${data}\'": + require => Exec['wait_for_couchdb'], + unless => "couch-doc-diff $url '$data'" + } + } + + present: { + couchdb::query { "create_${db}_${id}": + cmd => 'PUT', + host => $host, + path => "${db}/${id}", + unless => "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc ${url}" + } + } + + absent: { + couchdb::query { "destroy_${db}_${id}": + cmd => 'DELETE', + host => $host, + path => "${db}/${id}", + onlyif => "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc ${url}" + } + } + } +} diff --git a/manifests/query.pp b/manifests/query.pp index 6d13c2b..0549ded 100644 --- a/manifests/query.pp +++ b/manifests/query.pp @@ -1,7 +1,7 @@ define couchdb::query ( - $cmd, $url, $host='127.0.0.1:5984', $data = '{}', $unless = undef) { + $cmd, $path, $host='127.0.0.1:5984', $data = '{}', $unless = undef) { - exec { "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc -X ${cmd} ${host}/${url} --data \'${data}\'": + exec { "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc -X ${cmd} ${host}/${path} --data \'${data}\'": require => [ Package['curl'], Exec['wait_for_couchdb'] ], unless => $unless } |