From cd70af0641009cb51758c5506fa7eff5c3977de7 Mon Sep 17 00:00:00 2001 From: Omer Abuddi Date: Wed, 30 Aug 2023 15:24:57 +0300 Subject: [PATCH] Fix linter --- jwthenticator/client.py | 2 +- jwthenticator/schemas.py | 2 +- jwthenticator/tokens.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jwthenticator/client.py b/jwthenticator/client.py index 8b08d5a..35ee580 100644 --- a/jwthenticator/client.py +++ b/jwthenticator/client.py @@ -129,7 +129,7 @@ async def authenticate(self) -> None: :return: None or raises exception if fails. """ if self._key is None: - raise Exception("Missing key") + raise ValueError("Missing key") url = urljoin(self.jwthenticator_server, "authenticate") request = schemas.AuthRequest(self._key, self.identifier) diff --git a/jwthenticator/schemas.py b/jwthenticator/schemas.py index f9622d8..12a0810 100644 --- a/jwthenticator/schemas.py +++ b/jwthenticator/schemas.py @@ -37,7 +37,7 @@ class KeyData: created: datetime expires_at: datetime key_hash: str - key: Optional[str] = field(default=None, repr=False, metadata=dict(load_only=True)) + key: Optional[str] = field(default=None, repr=False, metadata={"load_only": True}) async def is_valid(self) -> bool: return self.expires_at > datetime.utcnow() diff --git a/jwthenticator/tokens.py b/jwthenticator/tokens.py index ff9fd1a..84afff0 100644 --- a/jwthenticator/tokens.py +++ b/jwthenticator/tokens.py @@ -28,7 +28,7 @@ def __init__(self, public_key: str, private_key: Optional[str] = None, algorithm """ # This is done to avoid an "exploit" where algorithm=none leaving the jwt tokens unsecure. if not algorithm or algorithm.lower() == "none": - raise Exception("Algorithm can't be empty!") + raise ValueError("Algorithm can't be empty!") self.public_key = public_key self.private_key = private_key @@ -49,7 +49,7 @@ async def create_access_token(self, identifier: UUID) -> str: :return: The new JWT token string """ if self.private_key is None: - raise Exception("Private key required for JWT token creation") + raise RuntimeError("Private key required for JWT token creation") utc_now = datetime.utcnow() payload = JWTPayloadData( token_id=uuid4(), @@ -84,7 +84,7 @@ async def create_refresh_token(self, key_id: int, expires_at: Optional[datetime] if expires_at is None: expires_at = expires_at = datetime.utcnow() + timedelta(seconds=REFRESH_TOKEN_EXPIRY) if expires_at <= datetime.utcnow(): - raise Exception("Refresh token can't be created in the past") + raise RuntimeError("Refresh token can't be created in the past") refresh_token_str = sha512(uuid4().bytes).hexdigest() async with self.async_session_factory() as session: