diff options
author | elijah <elijah@riseup.net> | 2013-08-21 21:39:38 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-08-21 21:39:38 -0700 |
commit | 41f60e24a90606455eeaa030d7ab2d1e1e637dd6 (patch) | |
tree | 481d40faf34d221e7e5c10253a727267b6fe750d | |
parent | be90709b114b6f1cd84b70b58b989a3f46712da4 (diff) |
switch to using identities db
-rw-r--r-- | config/default.yml | 2 | ||||
-rw-r--r-- | lib/nickserver/couch/fetch_key.rb | 25 | ||||
-rw-r--r-- | test/test_helper.rb | 2 |
3 files changed, 14 insertions, 15 deletions
diff --git a/config/default.yml b/config/default.yml index c31b504..8ddadce 100644 --- a/config/default.yml +++ b/config/default.yml @@ -13,7 +13,7 @@ domains: ~ # couch_host: 'localhost' couch_port: 5984 -couch_database: 'users' +couch_database: 'identities' couch_user: ~ couch_password: ~ diff --git a/lib/nickserver/couch/fetch_key.rb b/lib/nickserver/couch/fetch_key.rb index db1e390..c671515 100644 --- a/lib/nickserver/couch/fetch_key.rb +++ b/lib/nickserver/couch/fetch_key.rb @@ -5,13 +5,13 @@ module Nickserver; module Couch class FetchKey include EM::Deferrable + VIEW = "_design/Identity/_view/pgp_key_by_email" + def initialize(options={}) @timeout = 5 end def get(uid) - uid = uid.split('@').first # TEMPORARY HACK FOR NOW. in the future - # the database should be able to be searchable by full address couch_request(uid) self end @@ -19,11 +19,12 @@ module Nickserver; module Couch protected # - # curl http://localhost:5984/users/_design/User/_view/pgp_key_by_handle?key=%22bla%22\&reduce=false + # For example: + # curl "$COUCH/identities/_design/Identity/_view/pgp_key_by_email?key=\"test1@bitmask.net\"" # def couch_request(uid) query = {"reduce" => "false", "key" => "\"#{uid}\""} - request = EventMachine::HttpRequest.new("#{FetchKey.couch_url}/#{FetchKey.couch_view}").get(:timeout => @timeout, :query => query) + request = EventMachine::HttpRequest.new(FetchKey.couch_url).get(:timeout => @timeout, :query => query) request.callback {|http| if http.response_header.status != 200 self.fail http.response_header.status, 'Unknown Error' @@ -46,15 +47,15 @@ module Nickserver; module Couch self.fail 0, "Error parsing CouchDB reply" end - def self.couch_view - "_design/User/_view/pgp_key_by_handle" - end - def self.couch_url - if Config.couch_user - ['http://', Config.couch_user, ':', Config.couch_password, '@', Config.couch_host, ':', Config.couch_port, '/', Config.couch_database].join - else - ['http://', Config.couch_host, ':', Config.couch_port, '/', Config.couch_database].join + @couch_url ||= begin + url = ['http://'] + if Config.couch_user + url.push Config.couch_user, ':', Config.couch_password, '@' + end + url.push Config.couch_host, ':', Config.couch_port, '/', Config.couch_database + url.push '/', VIEW + url.join end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 5d95cfd..ec19753 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -46,8 +46,6 @@ class MiniTest::Unit::TestCase def stub_couch_response(uid, opts = {}) # can't stub localhost, so set couch_host to anything else Nickserver::Config.stub :couch_host, 'notlocalhost' do - uid = uid.split('@').first # TEMPORARY HACK FOR NOW. in the future - # the database should be able to be searchable by full address options = {:status => 200, :body => ""}.merge(opts) query = "\?key=#{"%22#{uid}%22"}&reduce=false" stub_http_request(:get, /#{Regexp.escape(Nickserver::Couch::FetchKey.couch_url)}.*#{query}/).to_return(options) |