summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-09-11 08:58:13 +0200
committerAzul <azul@riseup.net>2013-09-11 08:58:13 +0200
commit929fcdea37f92f6b175482c6e0d1b8ff3229854f (patch)
tree999658e896f1fd5d6f8ac1d2909d8fb300d19482
parent21fb605e3a57455e4a46c495ffcf36502f8fd1b9 (diff)
use password and username from the config file
-rw-r--r--lib/tapicero/config.rb14
-rw-r--r--lib/tapicero/couch_database_creator.rb4
-rw-r--r--lib/tapicero_daemon.rb4
3 files changed, 13 insertions, 9 deletions
diff --git a/lib/tapicero/config.rb b/lib/tapicero/config.rb
index f760cca..6e0fdfe 100644
--- a/lib/tapicero/config.rb
+++ b/lib/tapicero/config.rb
@@ -15,11 +15,15 @@ module Tapicero
end
end
- # TODO: enable username and password
- def couch_host
- couch_connection[:protocol] + '://' +
- couch_connection[:host] + ':' +
- couch_connection[:port].to_s + '/'
+ def couch_host(conf = nil)
+ conf ||= couch_connection
+ userinfo = [conf[:username], conf[:password]].compact.join(':')
+ userinfo += '@' unless userinfo.empty?
+ "#{conf[:protocol]}://#{userinfo}#{conf[:host]}:#{conf[:port]}"
+ end
+
+ def couch_host_without_password
+ couch_host couch_connection.merge({:password => nil})
end
private
diff --git a/lib/tapicero/couch_database_creator.rb b/lib/tapicero/couch_database_creator.rb
index 5a2849b..4d39c1b 100644
--- a/lib/tapicero/couch_database_creator.rb
+++ b/lib/tapicero/couch_database_creator.rb
@@ -12,8 +12,8 @@ module Tapicero
def create(name, security = {})
db = @couch.create_db(name)
puts security.to_json
- puts "-> #{@host}#{name}/_security"
- CouchRest.put "#{@host}#{name}/_security", security
+ puts "-> #{@host}/#{name}/_security"
+ CouchRest.put "#{@host}/#{name}/_security", security
end
end
end
diff --git a/lib/tapicero_daemon.rb b/lib/tapicero_daemon.rb
index 330bba6..52e60e3 100644
--- a/lib/tapicero_daemon.rb
+++ b/lib/tapicero_daemon.rb
@@ -8,9 +8,9 @@
require 'tapicero'
module Tapicero
- puts " * Observing #{Config.couch_host}"
+ puts " * Observing #{Config.couch_host_without_password}"
puts " * Tracking #{Config.users_db_name}"
- stream = CouchStream.new(Config.couch_host + Config.users_db_name)
+ stream = CouchStream.new(Config.couch_host + '/' + Config.users_db_name)
users = CouchChanges.new(stream)
creator = CouchDatabaseCreator.new(Config.couch_host)
users.created do |hash|