diff --git a/pillar/__init__.py b/pillar/__init__.py index 3104d8d3..a6ae2571 100644 --- a/pillar/__init__.py +++ b/pillar/__init__.py @@ -210,14 +210,7 @@ class PillarServer(BlinkerCompatibleEve): self.sentry = sentry_extra.PillarSentry( self, logging=True, level=logging.WARNING, logging_exclusions=('werkzeug',)) - - # bugsnag.before_notify(bugsnag_extra.add_pillar_request_to_notification) - # got_request_exception.connect(self.__notify_bugsnag) - self.log.info('Sentry setup complete') - - def __notify_bugsnag(self, sender, exception, **extra): - import bugsnag - bugsnag.auto_notify(exception) + self.log.debug('Sentry setup complete') def _config_google_cloud_storage(self): # Google Cloud project diff --git a/pillar/api/blender_id.py b/pillar/api/blender_id.py index eb9e7537..6291c5e2 100644 --- a/pillar/api/blender_id.py +++ b/pillar/api/blender_id.py @@ -209,14 +209,19 @@ def fetch_blenderid_user() -> dict: :raises LogoutUser: when Blender ID tells us the current token is invalid, and the user should be logged out. """ - import httplib2 # used by the oauth2 package + my_log = log.getChild('fetch_blenderid_user') + bid_url = '%s/api/user' % blender_id_endpoint() - log.debug('Fetching user info from %s', bid_url) + my_log.debug('Fetching user info from %s', bid_url) credentials = current_app.config['OAUTH_CREDENTIALS']['blender-id'] - oauth_token = session['blender_id_oauth_token'] + oauth_token = session.get('blender_id_oauth_token') + if not oauth_token: + my_log.warning('no Blender ID oauth token found in user session') + return {} + assert isinstance(oauth_token, str), f'oauth token must be str, not {type(oauth_token)}' oauth_session = OAuth2Session( @@ -226,23 +231,23 @@ def fetch_blenderid_user() -> dict: try: bid_resp = oauth_session.get(bid_url) except httplib2.HttpLib2Error: - log.exception('Error getting %s from BlenderID', bid_url) + my_log.exception('Error getting %s from BlenderID', bid_url) return {} if bid_resp.status_code == 403: - log.warning('Error %i from BlenderID %s, logging out user', bid_resp.status_code, bid_url) + my_log.warning('Error %i from BlenderID %s, logging out user', bid_resp.status_code, bid_url) raise LogoutUser() if bid_resp.status_code != 200: - log.warning('Error %i from BlenderID %s: %s', bid_resp.status_code, bid_url, bid_resp.text) + my_log.warning('Error %i from BlenderID %s: %s', bid_resp.status_code, bid_url, bid_resp.text) return {} payload = bid_resp.json() if not payload: - log.warning('Empty data returned from BlenderID %s', bid_url) + my_log.warning('Empty data returned from BlenderID %s', bid_url) return {} - log.debug('BlenderID returned %s', payload) + my_log.debug('BlenderID returned %s', payload) return payload diff --git a/pillar/api/users/hooks.py b/pillar/api/users/hooks.py index f918e5aa..49c91b70 100644 --- a/pillar/api/users/hooks.py +++ b/pillar/api/users/hooks.py @@ -168,8 +168,8 @@ def grant_org_roles(user_doc): email = user_doc.get('email') if not email: - log.warning('Unable to check new user for organization membership, no email address! %r', - user_doc) + log.info('Unable to check new user for organization membership, no email address: %r', + user_doc) return org_roles = current_app.org_manager.unknown_member_roles(email) diff --git a/pillar/api/utils/authorization.py b/pillar/api/utils/authorization.py index bdac5d5c..569020e1 100644 --- a/pillar/api/utils/authorization.py +++ b/pillar/api/utils/authorization.py @@ -345,13 +345,13 @@ def require_login(*, require_roles=set(), return render_error() if require_roles and not current_user.matches_roles(require_roles, require_all): - log.warning('User %s is authenticated, but does not have required roles %s to ' - 'access %s', current_user.user_id, require_roles, func) + log.info('User %s is authenticated, but does not have required roles %s to ' + 'access %s', current_user.user_id, require_roles, func) return render_error() if require_cap and not current_user.has_cap(require_cap): - log.warning('User %s is authenticated, but does not have required capability %s to ' - 'access %s', current_user.user_id, require_cap, func) + log.info('User %s is authenticated, but does not have required capability %s to ' + 'access %s', current_user.user_id, require_cap, func) return render_error() return func(*args, **kwargs) diff --git a/pillar/sdk.py b/pillar/sdk.py index 119e33e7..647e528f 100644 --- a/pillar/sdk.py +++ b/pillar/sdk.py @@ -41,8 +41,8 @@ class FlaskInternalApi(pillarsdk.Api): try: content = self.handle_response(response, response.data) except: - log.warning("%s: Response[%s]: %s", url, response.status_code, - response.data) + log.debug("%s: Response[%s]: %s", url, response.status_code, + response.data, exc_info=True) raise return content