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. --- files/couch-doc-diff | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 files/couch-doc-diff (limited to 'files') diff --git a/files/couch-doc-diff b/files/couch-doc-diff new file mode 100644 index 0000000..964d312 --- /dev/null +++ b/files/couch-doc-diff @@ -0,0 +1,2 @@ +#!/bin/bash +diff -w <(curl -s --netrc-file /etc/couchdb/couchdb.netrc $1 ) <(echo '$2') -- 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. --- files/couch-doc-diff | 2 +- files/couch-doc-update | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'files') diff --git a/files/couch-doc-diff b/files/couch-doc-diff index 964d312..5438eab 100644 --- a/files/couch-doc-diff +++ b/files/couch-doc-diff @@ -1,2 +1,2 @@ #!/bin/bash -diff -w <(curl -s --netrc-file /etc/couchdb/couchdb.netrc $1 ) <(echo '$2') +diff -w <(curl -s --netrc-file /etc/couchdb/couchdb.netrc $1 ) <(echo $2) diff --git a/files/couch-doc-update b/files/couch-doc-update index 45d9f87..e4adfbe 100644 --- a/files/couch-doc-update +++ b/files/couch-doc-update @@ -14,7 +14,7 @@ # # USAGE # -# couch-doc-update --port --db --id --data +# couch-doc-update --host --db --id --data # # EXAMPLE # @@ -35,13 +35,13 @@ def main # # parse options # - @port = "5984" + @host = "127.0.0.1:5984" @db_name = nil @doc_id = nil @new_data = nil loop do case ARGV[0] - when '--port' then ARGV.shift; @port = ARGV.shift + when '--host' then ARGV.shift; @host = ARGV.shift when '--db' then ARGV.shift; @db_name = ARGV.shift when '--id' then ARGV.shift; @doc_id = ARGV.shift when '--data' then ARGV.shift; @new_data = ARGV.shift @@ -56,7 +56,7 @@ def main # update document # begin - @db = CouchRest.database(connection_string(@db_name, @port)) + @db = CouchRest.database(connection_string(@db_name, @host)) @doc = get_document(@db, @doc_id) result = if @doc update_document(@db, @doc, @new_data) @@ -91,10 +91,10 @@ def create_document(db, doc_id, data) db.save_doc(data) end -def connection_string(database, port) +def connection_string(database, host) protocol = "http" - hostname = "127.0.0.1" - #port = "5984" + #hostname = "127.0.0.1" + port = "5984" username = "admin" password = "" @@ -102,18 +102,18 @@ def connection_string(database, port) netrc.scan(/\w+ [\w\.]+/).each do |key_value| key, value = key_value.split ' ' case key - when "machine" then hostname = value + when "machine" then host = value + ':' + port when "login" then username = value when "password" then password = value end end - "%s://%s:%s@%s:%s/%s" % [protocol, username, password, hostname, port, database] + "%s://%s:%s@%s/%s" % [protocol, username, password, host, database] end def usage(s) $stderr.puts(s) - $stderr.puts("Usage: #{File.basename($0)} --port --db --id --data ") + $stderr.puts("Usage: #{File.basename($0)} --host --db --id --data ") exit(2) end -- 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 --- files/couch-doc-update | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'files') diff --git a/files/couch-doc-update b/files/couch-doc-update index e4adfbe..3cdf6ce 100644 --- a/files/couch-doc-update +++ b/files/couch-doc-update @@ -35,7 +35,7 @@ def main # # parse options # - @host = "127.0.0.1:5984" + @host = nil @db_name = nil @doc_id = nil @new_data = nil @@ -102,12 +102,14 @@ def connection_string(database, host) netrc.scan(/\w+ [\w\.]+/).each do |key_value| key, value = key_value.split ' ' case key - when "machine" then host = value + ':' + port + when "machine" then host ||= value + ':' + port when "login" then username = value when "password" then password = value end end + host ||= '127.0.0.1:5984' + "%s://%s:%s@%s/%s" % [protocol, username, password, host, database] end -- 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) --- files/couch-doc-update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files') diff --git a/files/couch-doc-update b/files/couch-doc-update index 3cdf6ce..f448046 100644 --- a/files/couch-doc-update +++ b/files/couch-doc-update @@ -51,7 +51,7 @@ def main end usage("Missing required option") unless @db_name && @doc_id && @new_data @new_data = JSON.parse(@new_data) - + # # update document # -- cgit v1.2.3