diff options
author | Kali Kaneko <kali@leap.se> | 2013-08-21 20:35:18 +0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2013-08-21 20:35:18 +0200 |
commit | 42741614d8a68033c0cc28273a3279fc09e22f85 (patch) | |
tree | 3f4fcddb2767de468866b5299f38dc5bfbd62da7 /src/leap/mx/couchdbhelper.py | |
parent | 92e1115f6aa76ec656972820021f24387bac117d (diff) | |
parent | 53bc81a863351cdf7bfb7a252bffdd8870e71742 (diff) |
Merge remote-tracking branch 'chiiph/bug/migrate_couch' into develop
Diffstat (limited to 'src/leap/mx/couchdbhelper.py')
-rw-r--r-- | src/leap/mx/couchdbhelper.py | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index 02ef088..147e6f9 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -97,7 +97,7 @@ class ConnectedCouchDB(client.CouchDB): """ pass - def queryByLoginOrAlias(self, alias): + def queryByAddress(self, address): """ Check to see if a particular email or alias exists. @@ -106,47 +106,56 @@ class ConnectedCouchDB(client.CouchDB): @return: a deferred for this query @rtype twisted.defer.Deferred """ - assert isinstance(alias, str), "Email or alias queries must be string" + assert isinstance(address, (str, unicode)), "Email or alias queries must be string" # TODO: Cache results - d = self.openView(docId="User", - viewId="by_login_or_alias/", - key=alias, + d = self.openView(docId="Identity", + viewId="by_address/", + key=address, reduce=False, include_docs=True) - d.addCallbacks(partial(self._get_uuid, alias), log.err) + d.addCallbacks(partial(self._get_uuid, address), log.err) return d - def _get_uuid(self, alias, result): + def _get_uuid(self, address, result): """ - Parses the result of the by_login_or_alias query and gets the - uuid + Parses the result of the by_address query and gets the uuid - @param alias: alias looked up - @type alias: string + @param address: alias looked up + @type address: string @param result: result dictionary @type result: dict @return: The uuid for alias if available @rtype: str """ for row in result["rows"]: - if row["key"] == alias: - uuid = row["id"] - self._cache[uuid] = row["doc"].get("public_key", None) + if row["key"] == address: + uuid = row["doc"].get("user_id", None) + if uuid is None: + log.msg("ERROR: Found doc for %s but there's not user_id!" + % (address,)) return uuid return None - def getPubKey(self, uuid): - pubkey = None - try: - pubkey = self._cache[uuid] - except: - pass - return pubkey + def getPubKey(self, address): + d = self.openView(docId="Identity", + viewId="pgp_key_by_email/", + key=address, + reduce=False, + include_docs=True) + d.addCallbacks(partial(self._get_pgp_key, address), log.err) + + return d + + def _get_pgp_key(self, address, result): + for row in result["rows"]: + if row["key"] == address: + return row["value"] + return None if __name__ == "__main__": from twisted.internet import reactor |