diff options
author | Victor Shyba <victor.shyba@gmail.com> | 2015-08-04 14:28:48 -0300 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-08-11 17:00:31 +0200 |
commit | 5862cb1db30fe4b748427cae663d4f3be3dd7af8 (patch) | |
tree | 51d8716052fc3b4227018b562b7d5c8c300624b9 /service/pixelated | |
parent | a7c84d6faf5ddd7866ce4c0508e03c7c3779eaca (diff) |
[refactor] Extracts get_key logic, sharing it
This avoids direct access to keymanager and reuses logic from NickNym
class.
-- Issue #422
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/bitmask_libraries/nicknym.py | 5 | ||||
-rw-r--r-- | service/pixelated/config/services.py | 5 | ||||
-rw-r--r-- | service/pixelated/resources/keys_resource.py | 4 |
3 files changed, 6 insertions, 8 deletions
diff --git a/service/pixelated/bitmask_libraries/nicknym.py b/service/pixelated/bitmask_libraries/nicknym.py index 810161ee..826ecb58 100644 --- a/service/pixelated/bitmask_libraries/nicknym.py +++ b/service/pixelated/bitmask_libraries/nicknym.py @@ -40,11 +40,14 @@ class NickNym(object): @defer.inlineCallbacks def _key_exists(self, email): try: - yield self.keymanager.get_key(email, openpgp.OpenPGPKey, private=True, fetch_remote=False) + yield self.fetch_key(email, private=True, fetch_remote=False) defer.returnValue(True) except KeyNotFound: defer.returnValue(False) + def fetch_key(self, email, private=False, fetch_remote=True): + return self.keymanager.get_key(email, openpgp.OpenPGPKey, private=private, fetch_remote=fetch_remote) + def _gen_key(self): return self.keymanager.gen_key(openpgp.OpenPGPKey) diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py index 2b739acd..a45f9a99 100644 --- a/service/pixelated/config/services.py +++ b/service/pixelated/config/services.py @@ -35,7 +35,7 @@ class Services(object): self.search_engine, pixelated_mailboxes) - self.keymanager = self.setup_keymanager(leap_session) + self.keymanager = leap_session.nicknym self.draft_service = self.setup_draft_service(pixelated_mailboxes) yield self.post_setup(soledad_querier, leap_session) @@ -48,9 +48,6 @@ class Services(object): # yield soledad_querier.remove_duplicates() InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() - def setup_keymanager(self, leap_session): - return leap_session.nicknym.keymanager - @defer.inlineCallbacks def setup_search_engine(self, leap_home, soledad_querier): key = yield soledad_querier.get_index_masterkey() diff --git a/service/pixelated/resources/keys_resource.py b/service/pixelated/resources/keys_resource.py index 8afb2bf6..6df95b28 100644 --- a/service/pixelated/resources/keys_resource.py +++ b/service/pixelated/resources/keys_resource.py @@ -1,7 +1,5 @@ from email.utils import parseaddr -from leap.keymanager import OpenPGPKey from pixelated.resources import respond_json_deferred -from twisted.internet.threads import deferToThread from twisted.web import server from twisted.web.resource import Resource @@ -25,7 +23,7 @@ class KeysResource(Resource): respond_json_deferred(None, request, status_code=404) _, key_to_find = parseaddr(request.args.get('search')[0]) - d = deferToThread(lambda: self._keymanager.get_key_from_cache(key_to_find, OpenPGPKey)) + d = self._keymanager.fetch_key(key_to_find) d.addCallback(finish_request) d.addErrback(key_not_found) |