Skip to content

Commit

Permalink
refactor(auth): remove cache_device_data option from OtfAuthConfig fo…
Browse files Browse the repository at this point in the history
…r simplification

fix(auth): update type hints from Cognito to OtfCognito for consistency

docs(auth_examples): remove outdated comments related to cache_device_data option
  • Loading branch information
NodeJSmith committed Jan 7, 2025
1 parent bc8428c commit ac80f8c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
4 changes: 1 addition & 3 deletions examples/auth_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/otf_api/auth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions src/otf_api/auth/user.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ac80f8c

Please sign in to comment.