From 10ccc63ea5b374290236bfd264151b57ee68f745 Mon Sep 17 00:00:00 2001 From: James Kachel Date: Wed, 6 Mar 2024 15:22:05 -0600 Subject: [PATCH] Found a couple of spots that didn't have log.debug or that didn't combine into a single line --- authentication/api.py | 3 +-- authentication/backends.py | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/authentication/api.py b/authentication/api.py index 8d5ee436..3d22a406 100644 --- a/authentication/api.py +++ b/authentication/api.py @@ -151,8 +151,7 @@ def keycloak_get_user(user: User): f"realms/{settings.KEYCLOAK_ADMIN_REALM}/users/" ) - log_str = f"Trying to get user info for {user.username}" - log.debug(log_str) + log.debug("Trying to get user info for %s", {user.username}) if user.keycloak_user_tokens.exists(): params = {"id": user.keycloak_user_tokens.first().keycloak_id} diff --git a/authentication/backends.py b/authentication/backends.py index 4b11c453..375171d0 100644 --- a/authentication/backends.py +++ b/authentication/backends.py @@ -26,8 +26,7 @@ class KeycloakRemoteUserBackend(RemoteUserBackend): def authenticate(self, request, remote_user): """Authenticate the user, using Keycloak to grab their ID first.""" - log_str = f"KeycloakRemoteUserBackend is running for {remote_user}" - log.warning(log_str) + log.debug("KeycloakRemoteUserBackend is running for %s", {remote_user}) userinfo_url = ( f"{settings.KEYCLOAK_ADMIN_URL}/auth/admin/" @@ -35,7 +34,7 @@ def authenticate(self, request, remote_user): ) if not remote_user: - log.warning("No remote_user provided") + log.debug("No remote_user provided") return None userinfo = keycloak_session_init( @@ -43,18 +42,17 @@ def authenticate(self, request, remote_user): ) if len(userinfo) == 0: - log.warning("Keycloak didn't return anything") + log.debug("Keycloak didn't return anything") # User may have changed their email, so let's see if we can find an # existing user existing_user = User.objects.get(email=remote_user) if existing_user is not None: - log_str = ( - f"Found existing user {existing_user}, trying to get " - "Keycloak info for them" + log.debug( + "Found existing user %s, trying to get Keycloak info for them", + {existing_user}, ) - log.warning(log_str) userinfo = [ keycloak_session_init( f"{userinfo_url}{existing_user.username}/", verify=False @@ -62,14 +60,13 @@ def authenticate(self, request, remote_user): ] if len(userinfo) == 0: - log_str = ( - "Keycloak still returned nothing for ID " - f"{existing_user.username}, so giving up." + log.debug( + "Keycloak still returned nothing for ID %s, so giving up.", + {existing_user.username}, ) - log.warning(log_str) return None else: - log.warning( + log.debug( "Keycloak still returned nothing and we didn't find a user to" " check, so giving up." )