From 929fcdea37f92f6b175482c6e0d1b8ff3229854f Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 11 Sep 2013 08:58:13 +0200 Subject: use password and username from the config file --- lib/tapicero/config.rb | 14 +++++++++----- lib/tapicero/couch_database_creator.rb | 4 ++-- lib/tapicero_daemon.rb | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'lib') 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| -- cgit v1.2.3