mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Clean up authenticator exceptions
- Renamed to *Error for consistency - Treating AuthError like CrawlError
This commit is contained in:
parent
c15a1aecdf
commit
22c2259adb
@ -2,7 +2,7 @@ from configparser import SectionProxy
|
|||||||
from typing import Callable, Dict
|
from typing import Callable, Dict
|
||||||
|
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
from .authenticator import Authenticator, AuthSection
|
from .authenticator import Authenticator, AuthError, AuthSection # noqa: F401
|
||||||
from .keyring import KeyringAuthenticator, KeyringAuthSection
|
from .keyring import KeyringAuthenticator, KeyringAuthSection
|
||||||
from .simple import SimpleAuthenticator, SimpleAuthSection
|
from .simple import SimpleAuthenticator, SimpleAuthSection
|
||||||
from .tfa import TfaAuthenticator
|
from .tfa import TfaAuthenticator
|
||||||
|
@ -4,11 +4,11 @@ from typing import Tuple
|
|||||||
from ..config import Config, Section
|
from ..config import Config, Section
|
||||||
|
|
||||||
|
|
||||||
class AuthLoadException(Exception):
|
class AuthLoadError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AuthException(Exception):
|
class AuthError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class Authenticator(ABC):
|
|||||||
If you are writing your own constructor for your own authenticator,
|
If you are writing your own constructor for your own authenticator,
|
||||||
make sure to call this constructor first (via super().__init__).
|
make sure to call this constructor first (via super().__init__).
|
||||||
|
|
||||||
May throw an AuthLoadException.
|
May throw an AuthLoadError.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -56,7 +56,7 @@ class Authenticator(ABC):
|
|||||||
(e. g. prompting the user).
|
(e. g. prompting the user).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise AuthException("Invalid credentials")
|
raise AuthError("Invalid credentials")
|
||||||
|
|
||||||
def invalidate_username(self) -> None:
|
def invalidate_username(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -67,7 +67,7 @@ class Authenticator(ABC):
|
|||||||
(e. g. prompting the user).
|
(e. g. prompting the user).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise AuthException("Invalid username")
|
raise AuthError("Invalid username")
|
||||||
|
|
||||||
def invalidate_password(self) -> None:
|
def invalidate_password(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -78,4 +78,4 @@ class Authenticator(ABC):
|
|||||||
(e. g. prompting the user).
|
(e. g. prompting the user).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise AuthException("Invalid password")
|
raise AuthError("Invalid password")
|
||||||
|
@ -6,7 +6,7 @@ from ..config import Config
|
|||||||
from ..logging import log
|
from ..logging import log
|
||||||
from ..utils import agetpass
|
from ..utils import agetpass
|
||||||
from ..version import NAME
|
from ..version import NAME
|
||||||
from .authenticator import Authenticator, AuthException, AuthSection
|
from .authenticator import Authenticator, AuthError, AuthSection
|
||||||
|
|
||||||
|
|
||||||
class KeyringAuthSection(AuthSection):
|
class KeyringAuthSection(AuthSection):
|
||||||
@ -53,4 +53,4 @@ class KeyringAuthenticator(Authenticator):
|
|||||||
self.invalidate_password()
|
self.invalidate_password()
|
||||||
|
|
||||||
def invalidate_password(self) -> None:
|
def invalidate_password(self) -> None:
|
||||||
raise AuthException("Invalid password")
|
raise AuthError("Invalid password")
|
||||||
|
@ -3,7 +3,7 @@ from typing import Optional, Tuple
|
|||||||
from ..config import Config
|
from ..config import Config
|
||||||
from ..logging import log
|
from ..logging import log
|
||||||
from ..utils import agetpass, ainput
|
from ..utils import agetpass, ainput
|
||||||
from .authenticator import Authenticator, AuthException, AuthSection
|
from .authenticator import Authenticator, AuthError, AuthSection
|
||||||
|
|
||||||
|
|
||||||
class SimpleAuthSection(AuthSection):
|
class SimpleAuthSection(AuthSection):
|
||||||
@ -48,7 +48,7 @@ class SimpleAuthenticator(Authenticator):
|
|||||||
|
|
||||||
def invalidate_credentials(self) -> None:
|
def invalidate_credentials(self) -> None:
|
||||||
if self._username_fixed and self._password_fixed:
|
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:
|
if not self._username_fixed:
|
||||||
self._username = None
|
self._username = None
|
||||||
@ -57,12 +57,12 @@ class SimpleAuthenticator(Authenticator):
|
|||||||
|
|
||||||
def invalidate_username(self) -> None:
|
def invalidate_username(self) -> None:
|
||||||
if self._username_fixed:
|
if self._username_fixed:
|
||||||
raise AuthException("Configured username is invalid")
|
raise AuthError("Configured username is invalid")
|
||||||
else:
|
else:
|
||||||
self._username = None
|
self._username = None
|
||||||
|
|
||||||
def invalidate_password(self) -> None:
|
def invalidate_password(self) -> None:
|
||||||
if self._password_fixed:
|
if self._password_fixed:
|
||||||
raise AuthException("Configured password is invalid")
|
raise AuthError("Configured password is invalid")
|
||||||
else:
|
else:
|
||||||
self._password = None
|
self._password = None
|
||||||
|
@ -3,7 +3,7 @@ from typing import Tuple
|
|||||||
from ..config import Config
|
from ..config import Config
|
||||||
from ..logging import log
|
from ..logging import log
|
||||||
from ..utils import ainput
|
from ..utils import ainput
|
||||||
from .authenticator import Authenticator, AuthException, AuthSection
|
from .authenticator import Authenticator, AuthError, AuthSection
|
||||||
|
|
||||||
|
|
||||||
class TfaAuthenticator(Authenticator):
|
class TfaAuthenticator(Authenticator):
|
||||||
@ -16,7 +16,7 @@ class TfaAuthenticator(Authenticator):
|
|||||||
super().__init__(name, section, config)
|
super().__init__(name, section, config)
|
||||||
|
|
||||||
async def username(self) -> str:
|
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 def password(self) -> str:
|
||||||
async with log.exclusive_output():
|
async with log.exclusive_output():
|
||||||
@ -24,10 +24,10 @@ class TfaAuthenticator(Authenticator):
|
|||||||
return code
|
return code
|
||||||
|
|
||||||
async def credentials(self) -> Tuple[str, str]:
|
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:
|
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:
|
def invalidate_password(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
@ -3,7 +3,7 @@ from typing import Dict, List, Optional
|
|||||||
|
|
||||||
from rich.markup import escape
|
from rich.markup import escape
|
||||||
|
|
||||||
from .auth import AUTHENTICATORS, Authenticator
|
from .auth import AUTHENTICATORS, Authenticator, AuthError
|
||||||
from .config import Config, ConfigOptionError
|
from .config import Config, ConfigOptionError
|
||||||
from .crawl import CRAWLERS, Crawler, CrawlError, KitIliasWebCrawler
|
from .crawl import CRAWLERS, Crawler, CrawlError, KitIliasWebCrawler
|
||||||
from .logging import log
|
from .logging import log
|
||||||
@ -117,7 +117,7 @@ class Pferd:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await crawler.run()
|
await crawler.run()
|
||||||
except CrawlError as e:
|
except (CrawlError, AuthError) as e:
|
||||||
log.error(str(e))
|
log.error(str(e))
|
||||||
except Exception:
|
except Exception:
|
||||||
log.unexpected_exception()
|
log.unexpected_exception()
|
||||||
|
Loading…
Reference in New Issue
Block a user