summaryrefslogtreecommitdiff
path: root/apifw/bottleapp.py
diff options
context:
space:
mode:
Diffstat (limited to 'apifw/bottleapp.py')
-rw-r--r--apifw/bottleapp.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/apifw/bottleapp.py b/apifw/bottleapp.py
index b204884..9a907f0 100644
--- a/apifw/bottleapp.py
+++ b/apifw/bottleapp.py
@@ -79,6 +79,10 @@ class BottleAuthorizationPlugin:
self.iss = None
self.aud = None
self._authz_routes = set()
+ self._logger = lambda **kwags: None
+
+ def set_logger(self, logger):
+ self._logger = logger
def set_token_signing_public_key(self, pubkey):
self.pubkey = Crypto.PublicKey.RSA.importKey(pubkey)
@@ -93,9 +97,13 @@ class BottleAuthorizationPlugin:
key = self.route_key(route)
if route.get('needs-authorization', True):
self._authz_routes.add(key)
- logging.info('Route %r does DOES need authorization', key)
+ self._logger(
+ msg_type='info', msg_text='Route does DOES need authorization',
+ route=key)
else:
- logging.info('Route %r does NOT need authorization', key)
+ self._logger(
+ msg_type='info', msg_text='Route does NOT need authorization',
+ route=key)
def route_key(self, route):
# route can be a dict (from find_missing_route), or a
@@ -164,8 +172,11 @@ class BottleAuthorizationPlugin:
route_scope = self.get_scope_for_route(route['method'], route['rule'])
if route_scope in scopes:
return True
- logging.error(
- 'Route scope %s is NOT in scopes %r', route_scope, scopes)
+ self._logger(
+ msg_type='error',
+ msg_text='Route scope is NOT in scopes',
+ route_scope=route_scope,
+ scopes=scopes)
return False
def get_scope_for_route(self, method, rule):
@@ -285,6 +296,8 @@ def create_bottle_application(
app.add_plugin(plugin)
authz = BottleAuthorizationPlugin()
+ if logger:
+ authz.set_dict_logger(logger)
authz.set_token_signing_public_key(config['token-public-key'])
authz.set_expected_issuer(config['token-issuer'])
authz.set_expected_audience(config['token-audience'])