Skip to content

Commit

Permalink
Turn Down Logging for Auth Failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Oct 18, 2024
1 parent 61bc6ee commit 879df3f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions rest_tools/server/handler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""RestHandler and related classes."""


# fmt:off
# pylint: skip-file

import base64
import functools
Expand All @@ -14,24 +12,30 @@
from collections import defaultdict
from typing import Any, Dict, Union

import rest_tools
import tornado.escape
import tornado.gen
import tornado.httpclient
import tornado.httputil
import tornado.web
from tornado.auth import OAuth2Mixin

import rest_tools
from .decorators import catch_error
from .stats import RouteStats
from .. import telemetry as wtt
from ..utils.auth import Auth, OpenIDAuth
from ..utils.json_util import json_decode
from ..utils.pkce import PKCEMixin
from .decorators import catch_error
from .stats import RouteStats

LOGGER = logging.getLogger('rest')


def _log_auth_failed(e: Exception):
LOGGER.warning('failed auth')
if LOGGER.isEnabledFor(logging.DEBUG):
LOGGER.exception(e)


def RestHandlerSetup(config={}):
"""Default RestHandler setup. Returns the default arguments for passing to
the route setup.
Expand Down Expand Up @@ -148,10 +152,10 @@ def get_current_user(self):
self.auth_key = token
return data['sub']
# Auth Failed
except Exception:
except Exception as e:
if self.debug and 'Authorization' in self.request.headers:
LOGGER.info('Authorization: %r', self.request.headers['Authorization'])
LOGGER.info('failed auth', exc_info=True)
_log_auth_failed(e)

return None

Expand Down Expand Up @@ -282,8 +286,8 @@ def get_current_user(self):
self.auth_refresh_token = refresh_token
return data['sub']
# Auth Failed
except Exception:
LOGGER.debug('failed auth', exc_info=True)
except Exception as e:
_log_auth_failed(e)

return None

Expand Down

0 comments on commit 879df3f

Please sign in to comment.