Fix authenticator and crawler names

Now, the "auth:" and "crawl:" parts are considered part of the name. This fixes
crawlers not being able to find their authenticators.
This commit is contained in:
Joscha 2021-05-15 15:18:16 +02:00
parent a6fdf05ee9
commit 595de88d96
3 changed files with 10 additions and 12 deletions

View File

@ -139,19 +139,17 @@ class Config:
def crawler_sections(self) -> List[Tuple[str, SectionProxy]]: def crawler_sections(self) -> List[Tuple[str, SectionProxy]]:
result = [] result = []
for section_name, section_proxy in self._parser.items(): for name, proxy in self._parser.items():
if section_name.startswith("crawler:"): if name.startswith("crawler:"):
crawler_name = section_name[8:] result.append((name, proxy))
result.append((crawler_name, section_proxy))
return result return result
def authenticator_sections(self) -> List[Tuple[str, SectionProxy]]: def authenticator_sections(self) -> List[Tuple[str, SectionProxy]]:
result = [] result = []
for section_name, section_proxy in self._parser.items(): for name, proxy in self._parser.items():
if section_name.startswith("auth:"): if name.startswith("auth:"):
crawler_name = section_name[5:] result.append((name, proxy))
result.append((crawler_name, section_proxy))
return result return result

View File

@ -180,7 +180,7 @@ class CrawlerSection(Section):
value = self.s.get("auth") value = self.s.get("auth")
if value is None: if value is None:
self.missing_value("auth") self.missing_value("auth")
auth = authenticators.get(f"auth:{value}") auth = authenticators.get(value)
if auth is None: if auth is None:
self.invalid_value("auth", value, "No such auth section exists") self.invalid_value("auth", value, "No such auth section exists")
return auth return auth

View File

@ -25,7 +25,7 @@ class Pferd:
def _load_authenticators(self) -> None: def _load_authenticators(self) -> None:
abort = False abort = False
for name, section in self._config.authenticator_sections(): for name, section in self._config.authenticator_sections():
print(f"[bold bright_cyan]Loading[/] auth:{escape(name)}") print(f"[bold bright_cyan]Loading[/] {escape(name)}")
authenticator_type = section.get("type") authenticator_type = section.get("type")
authenticator_constructor = AUTHENTICATORS.get(authenticator_type) authenticator_constructor = AUTHENTICATORS.get(authenticator_type)
if authenticator_constructor is None: if authenticator_constructor is None:
@ -48,7 +48,7 @@ class Pferd:
def _load_crawlers(self) -> None: def _load_crawlers(self) -> None:
abort = False abort = False
for name, section in self._config.crawler_sections(): for name, section in self._config.crawler_sections():
print(f"[bold bright_cyan]Loading[/] crawler:{escape(name)}") print(f"[bold bright_cyan]Loading[/] {escape(name)}")
crawler_type = section.get("type") crawler_type = section.get("type")
crawler_constructor = CRAWLERS.get(crawler_type) crawler_constructor = CRAWLERS.get(crawler_type)
if crawler_constructor is None: if crawler_constructor is None:
@ -79,6 +79,6 @@ class Pferd:
for name, crawler in self._crawlers.items(): for name, crawler in self._crawlers.items():
print() print()
print(f"[bold bright_cyan]Running[/] crawler:{escape(name)}") print(f"[bold bright_cyan]Running[/] {escape(name)}")
await crawler.run() await crawler.run()