From 22c2259adbf25bfc26bb312f1f91380f1a5461da Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 25 May 2021 14:21:12 +0200 Subject: [PATCH] Clean up authenticator exceptions - Renamed to *Error for consistency - Treating AuthError like CrawlError --- PFERD/auth/__init__.py | 2 +- PFERD/auth/authenticator.py | 12 ++++++------ PFERD/auth/keyring.py | 4 ++-- PFERD/auth/simple.py | 8 ++++---- PFERD/auth/tfa.py | 8 ++++---- PFERD/pferd.py | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/PFERD/auth/__init__.py b/PFERD/auth/__init__.py index 04ad587..af38859 100644 --- a/PFERD/auth/__init__.py +++ b/PFERD/auth/__init__.py @@ -2,7 +2,7 @@ from configparser import SectionProxy from typing import Callable, Dict from ..config import Config -from .authenticator import Authenticator, AuthSection +from .authenticator import Authenticator, AuthError, AuthSection # noqa: F401 from .keyring import KeyringAuthenticator, KeyringAuthSection from .simple import SimpleAuthenticator, SimpleAuthSection from .tfa import TfaAuthenticator diff --git a/PFERD/auth/authenticator.py b/PFERD/auth/authenticator.py index 9217dcd..5f09f92 100644 --- a/PFERD/auth/authenticator.py +++ b/PFERD/auth/authenticator.py @@ -4,11 +4,11 @@ from typing import Tuple from ..config import Config, Section -class AuthLoadException(Exception): +class AuthLoadError(Exception): pass -class AuthException(Exception): +class AuthError(Exception): pass @@ -30,7 +30,7 @@ class Authenticator(ABC): If you are writing your own constructor for your own authenticator, make sure to call this constructor first (via super().__init__). - May throw an AuthLoadException. + May throw an AuthLoadError. """ self.name = name @@ -56,7 +56,7 @@ class Authenticator(ABC): (e. g. prompting the user). """ - raise AuthException("Invalid credentials") + raise AuthError("Invalid credentials") def invalidate_username(self) -> None: """ @@ -67,7 +67,7 @@ class Authenticator(ABC): (e. g. prompting the user). """ - raise AuthException("Invalid username") + raise AuthError("Invalid username") def invalidate_password(self) -> None: """ @@ -78,4 +78,4 @@ class Authenticator(ABC): (e. g. prompting the user). """ - raise AuthException("Invalid password") + raise AuthError("Invalid password") diff --git a/PFERD/auth/keyring.py b/PFERD/auth/keyring.py index 413c7ad..326f629 100644 --- a/PFERD/auth/keyring.py +++ b/PFERD/auth/keyring.py @@ -6,7 +6,7 @@ from ..config import Config from ..logging import log from ..utils import agetpass from ..version import NAME -from .authenticator import Authenticator, AuthException, AuthSection +from .authenticator import Authenticator, AuthError, AuthSection class KeyringAuthSection(AuthSection): @@ -53,4 +53,4 @@ class KeyringAuthenticator(Authenticator): self.invalidate_password() def invalidate_password(self) -> None: - raise AuthException("Invalid password") + raise AuthError("Invalid password") diff --git a/PFERD/auth/simple.py b/PFERD/auth/simple.py index a12c359..7fbb60b 100644 --- a/PFERD/auth/simple.py +++ b/PFERD/auth/simple.py @@ -3,7 +3,7 @@ from typing import Optional, Tuple from ..config import Config from ..logging import log from ..utils import agetpass, ainput -from .authenticator import Authenticator, AuthException, AuthSection +from .authenticator import Authenticator, AuthError, AuthSection class SimpleAuthSection(AuthSection): @@ -48,7 +48,7 @@ class SimpleAuthenticator(Authenticator): def invalidate_credentials(self) -> None: if self._username_fixed and self._password_fixed: - raise AuthException("Configured credentials are invalid") + raise AuthError("Configured credentials are invalid") if not self._username_fixed: self._username = None @@ -57,12 +57,12 @@ class SimpleAuthenticator(Authenticator): def invalidate_username(self) -> None: if self._username_fixed: - raise AuthException("Configured username is invalid") + raise AuthError("Configured username is invalid") else: self._username = None def invalidate_password(self) -> None: if self._password_fixed: - raise AuthException("Configured password is invalid") + raise AuthError("Configured password is invalid") else: self._password = None diff --git a/PFERD/auth/tfa.py b/PFERD/auth/tfa.py index 670626d..3efabe1 100644 --- a/PFERD/auth/tfa.py +++ b/PFERD/auth/tfa.py @@ -3,7 +3,7 @@ from typing import Tuple from ..config import Config from ..logging import log from ..utils import ainput -from .authenticator import Authenticator, AuthException, AuthSection +from .authenticator import Authenticator, AuthError, AuthSection class TfaAuthenticator(Authenticator): @@ -16,7 +16,7 @@ class TfaAuthenticator(Authenticator): super().__init__(name, section, config) async def username(self) -> str: - raise AuthException("TFA authenticator does not support usernames") + raise AuthError("TFA authenticator does not support usernames") async def password(self) -> str: async with log.exclusive_output(): @@ -24,10 +24,10 @@ class TfaAuthenticator(Authenticator): return code async def credentials(self) -> Tuple[str, str]: - raise AuthException("TFA authenticator does not support usernames") + raise AuthError("TFA authenticator does not support usernames") def invalidate_username(self) -> None: - raise AuthException("TFA authenticator does not support usernames") + raise AuthError("TFA authenticator does not support usernames") def invalidate_password(self) -> None: pass diff --git a/PFERD/pferd.py b/PFERD/pferd.py index bed7c66..dbb8983 100644 --- a/PFERD/pferd.py +++ b/PFERD/pferd.py @@ -3,7 +3,7 @@ from typing import Dict, List, Optional from rich.markup import escape -from .auth import AUTHENTICATORS, Authenticator +from .auth import AUTHENTICATORS, Authenticator, AuthError from .config import Config, ConfigOptionError from .crawl import CRAWLERS, Crawler, CrawlError, KitIliasWebCrawler from .logging import log @@ -117,7 +117,7 @@ class Pferd: try: await crawler.run() - except CrawlError as e: + except (CrawlError, AuthError) as e: log.error(str(e)) except Exception: log.unexpected_exception()