summaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2014-06-20 18:08:02 +0200
committerAzul <azul@riseup.net>2014-06-20 18:08:02 +0200
commit630ae0d3a9e80c189f485b3e79fbbe0aecd21d7c (patch)
tree1e4b5bbed1c5c2681fa59a2ce7005699b0dedcff /manifests
parent75e62f1aa97b6702b82d28ddc768a92c0a831b5c (diff)
allow setting custom netrc in query and document defines
We need to perform some actions as the replication user for plain couch.
Diffstat (limited to 'manifests')
-rw-r--r--manifests/document.pp7
-rw-r--r--manifests/mirror_db.pp12
-rw-r--r--manifests/query.pp8
3 files changed, 18 insertions, 9 deletions
diff --git a/manifests/document.pp b/manifests/document.pp
index 1153296..3ecc05d 100644
--- a/manifests/document.pp
+++ b/manifests/document.pp
@@ -10,6 +10,7 @@ define couchdb::document(
$id,
$host = '127.0.0.1:5984',
$data = '{}',
+ $netrc = '/etc/couchdb/couchdb.netrc',
$ensure = 'content') {
$url = "${host}/${db}/${id}"
@@ -17,7 +18,7 @@ define couchdb::document(
case $ensure {
default: { err ( "unknown ensure value '${ensure}'" ) }
content: {
- exec { "couch-doc-update --host ${host} --db ${db} --id ${id} --data \'${data}\'":
+ exec { "couch-doc-update --netrc-file ${netrc} --host ${host} --db ${db} --id ${id} --data \'${data}\'":
require => Exec['wait_for_couchdb'],
unless => "couch-doc-diff $url '$data'"
}
@@ -28,7 +29,7 @@ define couchdb::document(
cmd => 'PUT',
host => $host,
path => "${db}/${id}",
- unless => "/usr/bin/curl -s -f --netrc-file /etc/couchdb/couchdb.netrc ${url}"
+ unless => "/usr/bin/curl -s -f --netrc-file ${netrc} ${url}"
}
}
@@ -37,7 +38,7 @@ define couchdb::document(
cmd => 'DELETE',
host => $host,
path => "${db}/${id}",
- unless => "/usr/bin/curl -s -f --netrc-file /etc/couchdb/couchdb.netrc ${url}"
+ unless => "/usr/bin/curl -s -f --netrc-file ${netrc} ${url}"
}
}
}
diff --git a/manifests/mirror_db.pp b/manifests/mirror_db.pp
index c2e5b21..06007e0 100644
--- a/manifests/mirror_db.pp
+++ b/manifests/mirror_db.pp
@@ -3,14 +3,18 @@ define couchdb::mirror_db (
$from='',
$to='' )
{
- $source = "$from$name"
- $target = "$to$name"
+ $source = "$from/$name"
+ if $to == '' { $target = $name }
+ else { $target = "$to/$name" }
+
+ $replication_user = "replication"
+ $replication_role = "replication"
couchdb::document { "${name}_replication":
- db => "_replicate",
+ db => "_replicator",
id => "${name}_replication",
host => $host,
- data => "{ \"source\": ${source}, \"target\": ${target}, \"continuous\": true }",
+ data => "{ \"source\": \"${source}\", \"target\": \"${target}\", \"continuous\": true, \"user_ctx\": { \"name\": \"${replication_user}\", \"roles\": [\"${replication_role}\"] } }",
require => Couchdb::Query["create_db_${name}"]
}
}
diff --git a/manifests/query.pp b/manifests/query.pp
index 72ae4d2..9507ca1 100644
--- a/manifests/query.pp
+++ b/manifests/query.pp
@@ -1,7 +1,11 @@
define couchdb::query (
- $cmd, $path, $host='127.0.0.1:5984', $data = '{}', $unless = undef) {
+ $cmd, $path,
+ $netrc='/etc/couchdb/couchdb.netrc',
+ $host='127.0.0.1:5984',
+ $data = '{}',
+ $unless = undef) {
- exec { "/usr/bin/curl -s --netrc-file /etc/couchdb/couchdb.netrc -X ${cmd} ${host}/${path} --data \'${data}\'":
+ exec { "/usr/bin/curl -s --netrc-file ${netrc} -X ${cmd} ${host}/${path} --data \'${data}\'":
require => [ Package['curl'], Exec['wait_for_couchdb'] ],
unless => $unless
}