From fbe74fd5aef6e26070e9b10357604dda3bd2d842 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 15 Aug 2013 09:25:37 +0200 Subject: couch-doc-diff: diff of a document on the couch (feature 3485) Added the bash script couch-doc-diff. It runs a diff between the content of the couch document specified as the first parameter and the second parameter. Diff returns 0 if there is no difference. This way you can tell the data is already on the couch. The diff will ignore changes to whitespaces as these are usually irrelevant for security json docs. --- manifests/base.pp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'manifests') diff --git a/manifests/base.pp b/manifests/base.pp index fb87ae9..f1e33f1 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -32,6 +32,7 @@ class couchdb::base { } File['/usr/local/bin/couch-doc-update'] -> Couchdb::Update <| |> + File['/usr/local/bin/couch-doc-diff'] -> Couchdb::Update <| |> file { '/usr/local/bin/couch-doc-update': @@ -41,6 +42,13 @@ class couchdb::base { group => 'root', require => Package['couchrest']; + '/usr/local/bin/couch-doc-diff': + source => 'puppet:///modules/couchdb/couch-doc-diff', + mode => '0755', + owner => 'root', + group => 'root', + require => Package['couchrest']; + '/etc/couchdb/local.ini': source => [ "puppet:///modules/site_couchdb/${::fqdn}/local.ini", 'puppet:///modules/site_couchdb/local.ini', -- cgit v1.2.3 From 16a3583c359cd57ff52866a8dfd933726d120d30 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 15 Aug 2013 11:44:18 +0200 Subject: couch:document - ensure state of a couch document - (feature #3485) also made the use of host, hostname and port a bit more consistent. --- manifests/bigcouch/add_node.pp | 2 +- manifests/bigcouch/query.pp | 4 ++-- manifests/create_db.pp | 10 +++++----- manifests/document.pp | 39 +++++++++++++++++++++++++++++++++++++++ manifests/query.pp | 4 ++-- 5 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 manifests/document.pp (limited to 'manifests') 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 } -- cgit v1.2.3 From 8a0f585cbdb8f54d495f636e36b812a3d5b8b804 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 15 Aug 2013 12:52:45 +0200 Subject: use couchdb::document to create bigcouch node config (feature #3485) fixes the use of couch-doc-update with non standart hosts replaces couchdb::bigcouch::query with couchdb::bigcouch::document --- manifests/bigcouch/add_node.pp | 7 ++++--- manifests/bigcouch/document.pp | 9 +++++++++ manifests/bigcouch/query.pp | 10 ---------- manifests/document.pp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 manifests/bigcouch/document.pp delete mode 100644 manifests/bigcouch/query.pp (limited to 'manifests') diff --git a/manifests/bigcouch/add_node.pp b/manifests/bigcouch/add_node.pp index 66ac9b6..ed9db94 100644 --- a/manifests/bigcouch/add_node.pp +++ b/manifests/bigcouch/add_node.pp @@ -1,7 +1,8 @@ define couchdb::bigcouch::add_node { - couchdb::bigcouch::query { "add_${name}": - cmd => 'PUT', - path => "nodes/bigcouch@${name}" + couchdb::bigcouch::document { "add_${name}": + db => 'nodes', + id => "bigcouch@${name}", + ensure => 'present' } } diff --git a/manifests/bigcouch/document.pp b/manifests/bigcouch/document.pp new file mode 100644 index 0000000..f72f205 --- /dev/null +++ b/manifests/bigcouch/document.pp @@ -0,0 +1,9 @@ +define couchdb::bigcouch::document ( $host='127.0.0.1:5986', $db, $id, $data='{}', $ensure='content') { + couchdb::document { "${name}": + host => $host, + db => $db, + id => $id, + data => $data, + ensure => $ensure + } +} diff --git a/manifests/bigcouch/query.pp b/manifests/bigcouch/query.pp deleted file mode 100644 index 8228e82..0000000 --- a/manifests/bigcouch/query.pp +++ /dev/null @@ -1,10 +0,0 @@ -define couchdb::bigcouch::query ( - $cmd, $path, $host='127.0.0.1:5986', $data = '{}' ) { - - couchdb::query { "${name}": - cmd => $cmd, - host => $host, - path => $path, - data => $data - } -} diff --git a/manifests/document.pp b/manifests/document.pp index 1b27d44..afbd37a 100644 --- a/manifests/document.pp +++ b/manifests/document.pp @@ -5,7 +5,7 @@ # ensure => {absent,present,*content*} # } # -define couchdb::document ( $host='127.0.0.1:5984', $db, $id, $data, $ensure='content') { +define couchdb::document ( $host='127.0.0.1:5984', $db, $id, $data='{}', $ensure='content') { $url = "${host}/${db}/${id}" -- cgit v1.2.3 From 321d463b43dc44a4f313aa6dabef1a8bdce27122 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 28 Aug 2013 12:47:40 +0200 Subject: minor: cleanup spacing (feature #3485) --- manifests/document.pp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'manifests') diff --git a/manifests/document.pp b/manifests/document.pp index afbd37a..77296dc 100644 --- a/manifests/document.pp +++ b/manifests/document.pp @@ -5,7 +5,12 @@ # ensure => {absent,present,*content*} # } # -define couchdb::document ( $host='127.0.0.1:5984', $db, $id, $data='{}', $ensure='content') { +define couchdb::document( + $db, + $id, + $host = '127.0.0.1:5984', + $data = '{}', + $ensure = 'content') { $url = "${host}/${db}/${id}" @@ -20,18 +25,18 @@ define couchdb::document ( $host='127.0.0.1:5984', $db, $id, $data='{}', $ensure present: { couchdb::query { "create_${db}_${id}": - cmd => 'PUT', - host => $host, - path => "${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}", + cmd => 'DELETE', + host => $host, + path => "${db}/${id}", onlyif => "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc ${url}" } } -- cgit v1.2.3