mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Add simple authenticator
... including some required authenticator infrastructure
This commit is contained in:
@ -3,6 +3,8 @@ from typing import Dict
|
||||
from rich import print
|
||||
from rich.markup import escape
|
||||
|
||||
from .authenticator import Authenticator
|
||||
from .authenticators import AUTHENTICATORS
|
||||
from .conductor import TerminalConductor
|
||||
from .config import Config
|
||||
from .crawler import Crawler
|
||||
@ -17,8 +19,32 @@ class Pferd:
|
||||
def __init__(self, config: Config):
|
||||
self._config = config
|
||||
self._conductor = TerminalConductor()
|
||||
self._authenticators: Dict[str, Authenticator] = {}
|
||||
self._crawlers: Dict[str, Crawler] = {}
|
||||
|
||||
def _load_authenticators(self) -> None:
|
||||
abort = False
|
||||
for name, section in self._config.authenticator_sections():
|
||||
print(f"[bold bright_cyan]Loading[/] auth:{escape(name)}")
|
||||
authenticator_type = section.get("type")
|
||||
authenticator_constructor = AUTHENTICATORS.get(authenticator_type)
|
||||
if authenticator_constructor is None:
|
||||
abort = True
|
||||
t = escape(repr(authenticator_type))
|
||||
print(f"[red]Error: Unknown authenticator type {t}")
|
||||
continue
|
||||
|
||||
authenticator = authenticator_constructor(
|
||||
name,
|
||||
section,
|
||||
self._config,
|
||||
self._conductor,
|
||||
)
|
||||
self._authenticators[name] = authenticator
|
||||
|
||||
if abort:
|
||||
raise PferdLoadException()
|
||||
|
||||
def _load_crawlers(self) -> None:
|
||||
abort = False
|
||||
for name, section in self._config.crawler_sections():
|
||||
@ -44,6 +70,7 @@ class Pferd:
|
||||
|
||||
async def run(self) -> None:
|
||||
try:
|
||||
self._load_authenticators()
|
||||
self._load_crawlers()
|
||||
except PferdLoadException:
|
||||
print("[bold red]Could not initialize PFERD properly")
|
||||
|
Reference in New Issue
Block a user