summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-08-21 21:39:38 -0700
committerelijah <elijah@riseup.net>2013-08-21 21:39:38 -0700
commit41f60e24a90606455eeaa030d7ab2d1e1e637dd6 (patch)
tree481d40faf34d221e7e5c10253a727267b6fe750d /lib
parentbe90709b114b6f1cd84b70b58b989a3f46712da4 (diff)
switch to using identities db
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver/couch/fetch_key.rb25
1 files changed, 13 insertions, 12 deletions
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