From dfd53e55512cba6a8b7e69ac5bf7bea172dfe6b1 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Fri, 30 Dec 2016 02:29:39 -0800 Subject: [PATCH] Limit deprecated token message to single warning The current behavior of a deprecation warning on every single request is making the logs very difficult to scan for other problems. One deprecation warning per run should be enough to get the message across. This patch ensures only one warning per lifetime of the middleware object. Change-Id: I481a1b11305cc1c90edf7e26c686824c32fe781f Closes-Bug: #1652929 --- keystonemiddleware/auth_token/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/keystonemiddleware/auth_token/__init__.py b/keystonemiddleware/auth_token/__init__.py index a136a65d..5ac66dc2 100644 --- a/keystonemiddleware/auth_token/__init__.py +++ b/keystonemiddleware/auth_token/__init__.py @@ -324,6 +324,7 @@ class BaseAuthProtocol(object): self._enforce_token_bind = enforce_token_bind self._service_token_roles = set(service_token_roles or []) self._service_token_roles_required = service_token_roles_required + self._service_token_warning_emitted = False @webob.dec.wsgify(RequestClass=_request._AuthTokenRequest) def __call__(self, req): @@ -381,12 +382,15 @@ class BaseAuthProtocol(object): if self._service_token_roles_required: request.service_token_valid = role_check_passed else: - self.log.warning(_LW('A valid token was submitted as a ' - 'service token, but it was not a ' - 'valid service token. This is ' - 'incorrect but backwards compatible ' - 'behaviour. This will be removed in ' - 'future releases.')) + if not self._service_token_warning_emitted: + self.log.warning(_LW('A valid token was submitted as ' + 'a service token, but it was not ' + 'a valid service token. This is ' + 'incorrect but backwards ' + 'compatible behaviour. This will ' + 'be removed in future releases.')) + # prevent log spam on every single request + self._service_token_warning_emitted = True request.service_token_valid = True