summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/bonafide
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-04-25 18:00:12 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-27 19:33:28 +0200
commit9f95446a55533c8cdceec7c4430be5cad752ecb1 (patch)
tree4265c127ee9b2c5f1e038836ad2e7b92ea0cad80 /src/leap/bitmask/bonafide
parent9a1548aa01996ce93febe0272f1f8e4dd5e130ff (diff)
[bug] unify logging style using class attr
I changed most of the logger statements to use a class attribute, in this way it's easier to identify which class it's logging them. in some cases I leave a module-level logger, when we're either using functions or when the module it's too small. at the same time I did a general review and cleanup of the logging statements.
Diffstat (limited to 'src/leap/bitmask/bonafide')
-rw-r--r--src/leap/bitmask/bonafide/_protocol.py14
-rw-r--r--src/leap/bitmask/bonafide/config.py25
-rw-r--r--src/leap/bitmask/bonafide/service.py7
-rw-r--r--src/leap/bitmask/bonafide/session.py15
4 files changed, 31 insertions, 30 deletions
diff --git a/src/leap/bitmask/bonafide/_protocol.py b/src/leap/bitmask/bonafide/_protocol.py
index 391aa8d..674634d 100644
--- a/src/leap/bitmask/bonafide/_protocol.py
+++ b/src/leap/bitmask/bonafide/_protocol.py
@@ -38,8 +38,6 @@ from twisted.logger import Logger
# TODO [ ] enable-disable services
# TODO [ ] read provider info
-logger = Logger()
-
COMMANDS = 'signup', 'authenticate', 'logout', 'stats'
_preffix = get_path_prefix()
@@ -53,6 +51,8 @@ class BonafideProtocol(object):
_apis = defaultdict(None)
_sessions = defaultdict(None)
+ log = Logger()
+
def _get_api(self, provider):
# TODO should get deferred
if provider.domain in self._apis:
@@ -85,7 +85,7 @@ class BonafideProtocol(object):
# Service public methods
def do_signup(self, full_id, password, invite=None, autoconf=False):
- logger.debug('SIGNUP for %s' % full_id)
+ self.log.debug('SIGNUP for %s' % full_id)
_, provider_id = config.get_username_and_provider(full_id)
provider = config.Provider(provider_id, autoconf=autoconf)
@@ -132,7 +132,7 @@ class BonafideProtocol(object):
# TODO -- turn this into JSON response
return str(_session.token), str(_session.uuid)
- logger.debug('AUTH for %s' % full_id)
+ self.log.debug('AUTH for %s' % full_id)
# XXX get deferred?
session = self._get_session(provider, full_id, password)
@@ -143,7 +143,7 @@ class BonafideProtocol(object):
def do_logout(self, full_id):
# XXX use the AVATAR here
- logger.debug('LOGOUT for %s' % full_id)
+ self.log.debug('LOGOUT for %s' % full_id)
if (full_id not in self._sessions or
not self._sessions[full_id].is_authenticated):
return fail(RuntimeError("There is no session for such user"))
@@ -162,7 +162,7 @@ class BonafideProtocol(object):
return users
def do_change_password(self, full_id, current_password, new_password):
- logger.debug('change password for %s' % full_id)
+ self.log.debug('Change password for %s' % full_id)
if (full_id not in self._sessions or
not self._sessions[full_id].is_authenticated):
return fail(RuntimeError("There is no session for such user"))
@@ -208,7 +208,7 @@ class BonafideProtocol(object):
pass
def do_stats(self):
- logger.debug('calculating Bonafide Service STATS')
+ self.log.debug('Calculating Bonafide Service STATS')
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
return {'sessions': len(self._sessions),
'mem': '%s KB' % (mem / 1024)}
diff --git a/src/leap/bitmask/bonafide/config.py b/src/leap/bitmask/bonafide/config.py
index 1002edb..b3c35ba 100644
--- a/src/leap/bitmask/bonafide/config.py
+++ b/src/leap/bitmask/bonafide/config.py
@@ -40,8 +40,6 @@ from leap.common.check import leap_assert
from leap.common.config import get_path_prefix as common_get_path_prefix
from leap.common.files import mkdir_p
-logger = Logger()
-
APPNAME = "bonafide"
if platform.system() == 'Windows':
@@ -158,6 +156,7 @@ def delete_provider(domain):
class Provider(object):
+
# TODO add validation
SERVICES_MAP = {
@@ -168,6 +167,8 @@ class Provider(object):
ongoing_bootstrap = defaultdict(None)
stuck_bootstrap = defaultdict(None)
+ log = Logger()
+
def __init__(self, domain, autoconf=False, basedir=None,
check_certificate=True):
# TODO: I need a way to know if it was already configured
@@ -196,7 +197,7 @@ class Provider(object):
if not is_configured:
if autoconf:
- logger.debug(
+ self.log.debug(
'provider %s not configured: downloading files...' %
domain)
self.bootstrap()
@@ -204,7 +205,7 @@ class Provider(object):
raise NotConfiguredError("Provider %s is not configured"
% (domain,))
else:
- logger.debug('provider already initialized')
+ self.log.debug('Provider already initialized')
self.first_bootstrap[self._domain] = defer.succeed(
'already_initialized')
self.ongoing_bootstrap[self._domain] = defer.succeed(
@@ -251,10 +252,10 @@ class Provider(object):
def bootstrap(self):
domain = self._domain
- logger.debug("bootstrapping provider %s" % domain)
+ self.log.debug('Bootstrapping provider %s' % domain)
ongoing = self.ongoing_bootstrap.get(domain)
if ongoing:
- logger.debug('already bootstrapping this provider...')
+ self.log.debug('Already bootstrapping this provider...')
return
self.first_bootstrap[self._domain] = defer.Deferred()
@@ -359,7 +360,7 @@ class Provider(object):
# See: # https://leap.se/code/issues/7906
def further_bootstrap_needs_auth(ignored):
- logger.warn('cannot download services config yet, need auth')
+ self.log.warn('Cannot download services config yet, need auth')
pending_deferred = defer.Deferred()
self.stuck_bootstrap[self._domain] = pending_deferred
return defer.succeed('ok for now')
@@ -382,9 +383,8 @@ class Provider(object):
def workaround_for_config_fetch(failure):
# FIXME --- configs.json raises 500, see #7914.
# This is a workaround until that's fixed.
- logger.error(failure)
- logger.debug(
- "COULD NOT VERIFY CONFIGS.JSON, WORKAROUND: DIRECT DOWNLOAD")
+ self.log.debug(
+ 'COULD NOT VERIFY CONFIGS.JSON, WORKAROUND: DIRECT DOWNLOAD')
if 'mx' in self._provider_config.services:
soledad_uri = '/1/config/soledad-service.json'
@@ -412,7 +412,6 @@ class Provider(object):
if stuck:
d = self._get_config_for_all_services(session)
d.addCallback(lambda _: stuck.callback('continue!'))
- d.addErrback(logger.error)
return d
if not self.has_fetched_services_config():
@@ -497,7 +496,7 @@ class Provider(object):
def _load_provider_json(self):
path = self._get_provider_json_path()
if not is_file(path):
- logger.debug("cannot LOAD provider config path %s" % path)
+ self.log.debug('cannot LOAD provider config path %s' % path)
return
with open(path, 'r') as config:
@@ -535,7 +534,7 @@ class Provider(object):
return services_dict
def _fetch_provider_configs_unauthenticated(self, uri, path):
- logger.info('downloading config for %s...' % uri)
+ self.log.info('Downloading config for %s...' % uri)
d = downloadPage(uri, path, method='GET')
return d
diff --git a/src/leap/bitmask/bonafide/service.py b/src/leap/bitmask/bonafide/service.py
index 0f9c628..b9aaf1a 100644
--- a/src/leap/bitmask/bonafide/service.py
+++ b/src/leap/bitmask/bonafide/service.py
@@ -30,12 +30,13 @@ from twisted.internet import defer
from twisted.logger import Logger
-logger = Logger()
_preffix = get_path_prefix()
class BonafideService(HookableService):
+ log = Logger()
+
def __init__(self, basedir=None):
if not basedir:
basedir = os.path.join(_preffix, 'leap')
@@ -44,7 +45,7 @@ class BonafideService(HookableService):
self.service_hooks = defaultdict(list)
def startService(self):
- logger.debug('starting Bonafide Service')
+ self.log.debug('Starting Bonafide Service')
super(BonafideService, self).startService()
# Commands
@@ -58,7 +59,7 @@ class BonafideService(HookableService):
def notify_bonafide_auth(result):
if not result:
msg = "authentication hook did not return anything"
- logger.debug(msg)
+ self.log.debug(msg)
raise RuntimeError(msg)
token, uuid = result
diff --git a/src/leap/bitmask/bonafide/session.py b/src/leap/bitmask/bonafide/session.py
index 732afe5..551bfa2 100644
--- a/src/leap/bitmask/bonafide/session.py
+++ b/src/leap/bitmask/bonafide/session.py
@@ -24,7 +24,6 @@ from leap.bitmask.bonafide import _srp
from leap.bitmask.bonafide import provider
from leap.bitmask.bonafide._http import httpRequest, cookieAgentFactory
-logger = Logger()
OK = 'ok'
@@ -45,6 +44,8 @@ def _auth_required(func):
class Session(object):
+ log = Logger()
+
def __init__(self, credentials, api, provider_cert):
# TODO check if an anonymous credentials is passed.
# TODO move provider_cert to api object.
@@ -91,7 +92,7 @@ class Session(object):
def authenticate(self):
uri = self._api.get_handshake_uri()
met = self._api.get_handshake_method()
- logger.debug("%s to %s" % (met, uri))
+ self.log.debug('%s to %s' % (met, uri))
params = self._srp_auth.get_handshake_params()
handshake = yield self._request(self._agent, uri, values=params,
@@ -101,7 +102,7 @@ class Session(object):
uri = self._api.get_authenticate_uri(login=self.username)
met = self._api.get_authenticate_method()
- logger.debug("%s to %s" % (met, uri))
+ self.log.debug('%s to %s' % (met, uri))
params = self._srp_auth.get_authentication_params()
auth = yield self._request(self._agent, uri, values=params,
@@ -119,9 +120,7 @@ class Session(object):
def logout(self):
uri = self._api.get_logout_uri()
met = self._api.get_logout_method()
- auth = yield self._request(self._agent, uri, method=met)
- print 'AUTH', auth
- print 'resetting user/pass'
+ yield self._request(self._agent, uri, method=met)
self.username = None
self.password = None
self._initialize_session()
@@ -211,6 +210,8 @@ if __name__ == "__main__":
import sys
from twisted.cred.credentials import UsernamePassword
+ log = Logger()
+
if len(sys.argv) != 4:
print "Usage:", sys.argv[0], "provider", "username", "password"
sys.exit()
@@ -229,7 +230,7 @@ if __name__ == "__main__":
reactor.stop()
def auth_eb(failure):
- logger.error(failure)
+ log.error(failure)
d = session.authenticate()
d.addCallback(print_result)