diff --git a/apricot/models/ldap_attribute_adaptor.py b/apricot/models/ldap_attribute_adaptor.py index a559f9d..059a5d8 100644 --- a/apricot/models/ldap_attribute_adaptor.py +++ b/apricot/models/ldap_attribute_adaptor.py @@ -4,7 +4,7 @@ if TYPE_CHECKING: from apricot.models import LDAPObjectClass - from apricot.types import JSONDict, LDAPAttributeDict + from apricot.typedefs import JSONDict, LDAPAttributeDict class LDAPAttributeAdaptor: diff --git a/apricot/oauth/__init__.py b/apricot/oauth/__init__.py index c5d6268..3591f58 100644 --- a/apricot/oauth/__init__.py +++ b/apricot/oauth/__init__.py @@ -1,4 +1,4 @@ -from apricot.types import LDAPAttributeDict, LDAPControlTuple +from apricot.typedefs import LDAPAttributeDict, LDAPControlTuple from .enums import OAuthBackend from .keycloak_client import KeycloakClient diff --git a/apricot/oauth/keycloak_client.py b/apricot/oauth/keycloak_client.py index 54ddaaa..660553d 100644 --- a/apricot/oauth/keycloak_client.py +++ b/apricot/oauth/keycloak_client.py @@ -3,7 +3,9 @@ import operator from typing import Any, Self, cast -from apricot.types import JSONDict +from twisted.python import log + +from apricot.typedefs import JSONDict from .oauth_client import OAuthClient @@ -99,8 +101,9 @@ def groups(self: Self) -> list[JSONDict]: user["username"] for user in cast(list[JSONDict], members) ] output.append(attributes) - except KeyError: - pass + except KeyError as exc: + msg = f"Failed to process group {group_dict} due to a missing key {exc}." + log.msg(msg) return output def users(self: Self) -> list[JSONDict]: @@ -170,6 +173,7 @@ def users(self: Self) -> list[JSONDict]: attributes["uid"] = username attributes["uidNumber"] = user_dict["attributes"]["uid"][0] output.append(attributes) - except KeyError: - pass + except KeyError as exc: + msg = f"Failed to process user {user_dict} due to a missing key {exc}." + log.msg(msg) return output diff --git a/apricot/oauth/microsoft_entra_client.py b/apricot/oauth/microsoft_entra_client.py index 0970347..3444d92 100644 --- a/apricot/oauth/microsoft_entra_client.py +++ b/apricot/oauth/microsoft_entra_client.py @@ -5,7 +5,7 @@ from twisted.python import log -from apricot.types import JSONDict +from apricot.typedefs import JSONDict from .oauth_client import OAuthClient @@ -114,6 +114,7 @@ def users(self: Self) -> list[JSONDict]: attributes["uid"] = uid or None attributes["uidNumber"] = user_uid output.append(attributes) - except KeyError: - pass + except KeyError as exc: + msg = f"Failed to process user {user_dict} due to a missing key {exc}." + log.msg(msg) return output diff --git a/apricot/oauth/oauth_client.py b/apricot/oauth/oauth_client.py index 34eddba..8536f46 100644 --- a/apricot/oauth/oauth_client.py +++ b/apricot/oauth/oauth_client.py @@ -17,7 +17,7 @@ if TYPE_CHECKING: from apricot.cache import UidCache - from apricot.types import JSONDict + from apricot.typedefs import JSONDict class OAuthClient(ABC): @@ -162,8 +162,8 @@ def query_(*args: Any, **kwargs: Any) -> requests.Response: try: result = query_(*args, **kwargs) result.raise_for_status() - except (TokenExpiredError, requests.exceptions.HTTPError): - log.msg("Authentication token has expired.") + except (TokenExpiredError, requests.exceptions.HTTPError) as exc: + log.msg(f"Authentication token is invalid.\n{exc!s}") self.bearer_token_ = None result = query_(*args, **kwargs) if result.status_code == HTTPStatus.NO_CONTENT: @@ -181,7 +181,7 @@ def verify(self: Self, username: str, password: str) -> bool: client_secret=self.client_secret, ) except InvalidGrantError as exc: - log.msg(f"Authentication failed for user '{username}'.\n{exc}") + log.msg(f"Authentication failed for user '{username}'.\n{exc!s}") return False else: return True diff --git a/apricot/oauth/oauth_data_adaptor.py b/apricot/oauth/oauth_data_adaptor.py index 0545319..274190f 100644 --- a/apricot/oauth/oauth_data_adaptor.py +++ b/apricot/oauth/oauth_data_adaptor.py @@ -18,7 +18,7 @@ if TYPE_CHECKING: - from apricot.types import JSONDict + from apricot.typedefs import JSONDict from .oauth_client import OAuthClient diff --git a/apricot/types.py b/apricot/typedefs.py similarity index 75% rename from apricot/types.py rename to apricot/typedefs.py index 5cc0617..e93f9ea 100644 --- a/apricot/types.py +++ b/apricot/typedefs.py @@ -1,6 +1,5 @@ from typing import Any JSONDict = dict[str, Any] -JSONKey = list[Any] | dict[str, Any] | Any LDAPAttributeDict = dict[str, list[str]] LDAPControlTuple = tuple[str, bool, Any] diff --git a/pyproject.toml b/pyproject.toml index 3fdf026..319d97b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ detached = true dependencies = [ "black~=24.2", "mypy~=1.8", - "ruff~=0.3", + "ruff~=0.7", "types-oauthlib~=3.2", "types-redis~=4.6", "types-requests~=2.31",