diff options
author | Azul <azul@riseup.net> | 2013-08-14 12:19:27 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2013-08-14 12:35:53 +0200 |
commit | 4310152ba3a2a86c9ef72250cd9e1d30f86bbb0f (patch) | |
tree | 398edeb6433343132aca44722e91f017ab15eaba | |
parent | f317163e8aa6abfc992df5ef65d99b0861488d41 (diff) |
only create or update a user record if needed
We test the user account by trying to use it to retrieve / on the couch which prints a welcome message if the user is valid and returns a 401 otherwise.
-rw-r--r-- | manifests/add_user.pp | 4 | ||||
-rw-r--r-- | manifests/update.pp | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/manifests/add_user.pp b/manifests/add_user.pp index 9c8e5d4..73cfbf1 100644 --- a/manifests/add_user.pp +++ b/manifests/add_user.pp @@ -23,10 +23,12 @@ define couchdb::add_user ( $roles, $pw, $salt = '' ) { $data = "{\"type\": \"user\", \"name\": \"${name}\", \"roles\": ${roles}, \"password_sha\": \"${sha}\", \"salt\": \"${salt}\"}" } + # update the user with the given password unless they already work couchdb::update { "update_user_${name}": port => $port, db => '_users', id => "org.couchdb.user:${name}", - data => $data + data => $data, + unless => "curl -f ${name}:${pw}@127.0.0.1:${port}/" } } diff --git a/manifests/update.pp b/manifests/update.pp index b7e6fc1..bbd2591 100644 --- a/manifests/update.pp +++ b/manifests/update.pp @@ -1,6 +1,7 @@ -define couchdb::update ($db, $id, $data, $port='5984') { +define couchdb::update ($db, $id, $data, $port='5984', $unless='/bin/false') { exec { "couch-doc-update --port ${port} --db ${db} --id ${id} --data \'${data}\'": - require => Exec['wait_for_couchdb'] + require => Exec['wait_for_couchdb'], + unless => $unless } } |