diff options
author | Kali Kaneko <kali@leap.se> | 2013-10-28 12:33:58 -0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2013-10-28 12:33:58 -0200 |
commit | 74714c305ca40e910e4776d7e3cea21925bc1eb4 (patch) | |
tree | 35ee62215f358c30d468aa2eaa0e5d77ca917630 /src/leap/mx/couchdbhelper.py | |
parent | cd550b38686d6772aa7b1ae64c1fcdac5a22251d (diff) | |
parent | a2c88d23c5b34926a3e9f9efbf005b2b4806094d (diff) |
Merge remote-tracking branch 'chiiph/bug/support_mailing_lists_and_encodings' into develop
Diffstat (limited to 'src/leap/mx/couchdbhelper.py')
-rw-r--r-- | src/leap/mx/couchdbhelper.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index b500f17..41604ba 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -29,7 +29,6 @@ except ImportError: print "for instructions on getting required dependencies." try: - from twisted.internet import defer from twisted.python import log except ImportError: print "This software requires Twisted. Please see the README file" @@ -140,20 +139,39 @@ class ConnectedCouchDB(client.CouchDB): return uuid return None - def getPubKey(self, address): + def getPubKey(self, uuid): + """ + Returns a deferred that will return the pubkey for the uuid provided + + :param uuid: uuid for the user to query + :type uuid: str + + :rtype: Deferred + """ d = self.openView(docId="Identity", viewId="pgp_key_by_email/", - key=address, + user_id=uuid, reduce=False, include_docs=True) - d.addCallbacks(partial(self._get_pgp_key, address), log.err) + d.addCallbacks(partial(self._get_pgp_key, uuid), log.err) return d - def _get_pgp_key(self, address, result): + def _get_pgp_key(self, uuid, result): + """ + Callback used to filter the correct pubkey from the result of + the query to the couchdb + + :param uuid: uuid for the user that was queried + :type uuid: str + :param result: result dictionary for the db query + :type result: dict + + :rtype: str or None + """ for row in result["rows"]: - if row["key"] == address: + if row["doc"]["user_id"] == uuid: return row["value"] return None |