From 41f60e24a90606455eeaa030d7ab2d1e1e637dd6 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 21 Aug 2013 21:39:38 -0700 Subject: switch to using identities db --- lib/nickserver/couch/fetch_key.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3