From ac80f8cea103c7612ab7edadbfa53988b66f1514 Mon Sep 17 00:00:00 2001 From: Jessica Smith <12jessicasmith34@gmail.com> Date: Tue, 7 Jan 2025 17:42:35 -0600 Subject: [PATCH] refactor(auth): remove cache_device_data option from OtfAuthConfig for simplification fix(auth): update type hints from Cognito to OtfCognito for consistency docs(auth_examples): remove outdated comments related to cache_device_data option --- examples/auth_examples.py | 4 +--- src/otf_api/auth/config.py | 1 - src/otf_api/auth/user.py | 15 +++++---------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/examples/auth_examples.py b/examples/auth_examples.py index 5a2312b..acf6c9f 100644 --- a/examples/auth_examples.py +++ b/examples/auth_examples.py @@ -10,8 +10,6 @@ def main(): """ OtfAuthConfig provides three options currently: - - cache_device_data: bool - Whether to register/cache device data with AWS Cognito - I'm not sure if there is any benefit to this at this point, but in general this is used to allow skipping MFA - cache_tokens_plaintext: bool - Whether to cache the tokens in plaintext in the config file - this is an obvious security risk, but it's useful for development purposes. If you want to do this, it is at your own risk. The benefit is that after you log in with your username/password once, you can use the cached tokens to log in @@ -20,7 +18,7 @@ def main(): # This is the most configurable way to access the API but also the most verbose - auth_config = OtfAuthConfig(cache_device_data=True, cache_tokens_plaintext=True) + auth_config = OtfAuthConfig(cache_tokens_plaintext=True) auth = OtfAuth.create(USERNAME, PASSWORD, config=auth_config) user = OtfUser(auth=auth) diff --git a/src/otf_api/auth/config.py b/src/otf_api/auth/config.py index 9285461..66a0dcb 100644 --- a/src/otf_api/auth/config.py +++ b/src/otf_api/auth/config.py @@ -12,7 +12,6 @@ class OtfAuthConfig: DEVICE_DATA_KEYS: ClassVar[list[str]] = ["device_key", "device_group_key", "device_password"] TOKEN_KEYS: ClassVar[list[str]] = ["access_token", "id_token", "refresh_token"] - cache_device_data: bool = True cache_tokens_plaintext: bool = False cache_path: Path = attrs.field(init=False) diff --git a/src/otf_api/auth/user.py b/src/otf_api/auth/user.py index 8490114..59f4950 100644 --- a/src/otf_api/auth/user.py +++ b/src/otf_api/auth/user.py @@ -1,15 +1,10 @@ -import typing from logging import getLogger import attrs -from otf_api.auth.auth import OTF_AUTH_TYPE, OtfAuth, OtfAuthConfig, OtfBasicAuth +from otf_api.auth.auth import OTF_AUTH_TYPE, OtfAuth, OtfAuthConfig, OtfBasicAuth, OtfCognito from otf_api.auth.utils import HttpxCognitoAuth -if typing.TYPE_CHECKING: - from pycognito import Cognito - - LOGGER = getLogger(__name__) @@ -42,7 +37,7 @@ def __init__(self, auth: OTF_AUTH_TYPE): self.httpx_auth = HttpxCognitoAuth(cognito=self.cognito) @property - def cognito(self) -> "Cognito": + def cognito(self) -> OtfCognito: """Get the Cognito instance.""" return self.otf_auth.cognito @@ -105,11 +100,11 @@ def from_tokens( return cls(auth) @classmethod - def from_cognito(cls, cognito: "Cognito", config: OtfAuthConfig | None = None) -> "OtfUser": - """Create a User instance from a Cognito instance. + def from_cognito(cls, cognito: OtfCognito, config: OtfAuthConfig | None = None) -> "OtfUser": + """Create a User instance from a OtfCognito instance. Args: - cognito (Cognito): The Cognito instance. + cognito (OtfCognito): The OtfCognito instance. config (OtfAuthConfig, optional): The configuration. Defaults to None. Returns: