summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-03-12 21:33:44 +0100
committerRuben Pollan <meskio@sindominio.net>2017-03-13 21:09:11 +0100
commit64f6e4b0b95e86144480c0daebba7a189afebe8a (patch)
tree3e2f43261619742eecea2f0e0344f88fb6f71025 /src
parent6e4dd9f900407b11ac91e02046be34a59dc96d65 (diff)
[feat] report the status of keymanager in the mail status
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/core/mail_services.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index c087607..22c3195 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -217,20 +217,35 @@ class KeymanagerContainer(Container):
def __init__(self, service=None, basedir=DEFAULT_BASEDIR):
self._basedir = os.path.expanduser(basedir)
+ self._status = {}
super(KeymanagerContainer, self).__init__(service=service)
def add_instance(self, userid, token, uuid, soledad):
+
+ def _set_status_on(passthrough):
+ self._status[userid]["status"] = "on"
+ self._status[userid]["keys"] = "found"
+ return passthrough
+
logger.debug("adding Keymanager instance for: %s" % userid)
+ self._status[userid] = {"status": "starting",
+ "error": None, "keys": None}
keymanager = self._create_keymanager_instance(
userid, token, uuid, soledad)
super(KeymanagerContainer, self).add_instance(userid, keymanager)
d = self._get_or_generate_keys(keymanager, userid)
d.addCallback(self._on_keymanager_ready_cb, userid, soledad)
+ d.addCallback(_set_status_on)
return d
def set_remote_auth_token(self, userid, token):
self.get_instance(userid).token = token
+ def status(self, userid):
+ if userid not in self._status:
+ return {'status': 'off', 'error': None, 'keys': None}
+ return self._status[userid]
+
def _on_keymanager_ready_cb(self, keymanager, userid, soledad):
data = {'userid': userid, 'soledad': soledad, 'keymanager': keymanager}
self.service.trigger_hook('on_new_keymanager_instance', **data)
@@ -247,6 +262,7 @@ class KeymanagerContainer(Container):
def _if_not_found_generate(failure):
failure.trap(KeyNotFound)
logger.info("key not found, generating key for %s" % (userid,))
+ self._status[userid]["keys"] = "generating"
d = keymanager.gen_key()
d.addCallbacks(_send_key, _log_key_error("generating"))
return d
@@ -276,6 +292,9 @@ class KeymanagerContainer(Container):
def log_error(failure):
logger.error("Error while %s key!" % step)
logger.error(failure)
+ self._status[userid]["status"] = "failure"
+ self._status[userid]["error"] = "Error generating key: %s" \
+ % (failure.getErrorMessage(),)
return failure
return log_error
@@ -285,6 +304,7 @@ class KeymanagerContainer(Container):
return defer.succeed(None)
logger.debug("soledad has never synced")
+ self._status[userid]["keys"] = "sync"
if not keymanager.token:
logger.debug("no token to sync now, scheduling a new check")
@@ -427,6 +447,9 @@ class KeymanagerService(HookableService):
km.delete_key(key)
defer.returnValue(key.fingerprint)
+ def status(self, userid):
+ return self._container.status(userid)
+
class StandardMailService(service.MultiService, HookableService):
"""
@@ -570,19 +593,21 @@ class StandardMailService(service.MultiService, HookableService):
def do_status(self, userid):
smtp = self.getServiceNamed('smtp')
imap = self.getServiceNamed('imap')
+ keymanager = self.parent.getServiceNamed('keymanager')
incoming = self.getServiceNamed('incoming_mail')
incoming_status = yield incoming.status(userid)
childrenStatus = {
'smtp': smtp.status(),
'imap': imap.status(),
+ 'keymanager': keymanager.status(userid),
'incoming': incoming_status
}
def key(service):
status = childrenStatus[service]
level = {
- "on": 0,
- "starting": 1,
+ "starting": 0,
+ "on": 1,
"off": 10,
"stopping": 11,
"failure": 100