Load credential file from correct path

This commit is contained in:
Joscha 2021-06-01 09:18:08 +00:00
parent f6b26f4ead
commit e1bda94329
3 changed files with 5 additions and 3 deletions

View File

@ -16,7 +16,7 @@ AuthConstructor = Callable[[
AUTHENTICATORS: Dict[str, AuthConstructor] = { AUTHENTICATORS: Dict[str, AuthConstructor] = {
"credential-file": lambda n, s, c: "credential-file": lambda n, s, c:
CredentialFileAuthenticator(n, CredentialFileAuthSection(s)), CredentialFileAuthenticator(n, CredentialFileAuthSection(s), c),
"keyring": lambda n, s, c: "keyring": lambda n, s, c:
KeyringAuthenticator(n, KeyringAuthSection(s)), KeyringAuthenticator(n, KeyringAuthSection(s)),
"simple": lambda n, s, c: "simple": lambda n, s, c:

View File

@ -1,6 +1,7 @@
from pathlib import Path from pathlib import Path
from typing import Tuple from typing import Tuple
from ..config import Config
from ..utils import fmt_real_path from ..utils import fmt_real_path
from .authenticator import Authenticator, AuthLoadError, AuthSection from .authenticator import Authenticator, AuthLoadError, AuthSection
@ -14,10 +15,10 @@ class CredentialFileAuthSection(AuthSection):
class CredentialFileAuthenticator(Authenticator): class CredentialFileAuthenticator(Authenticator):
def __init__(self, name: str, section: CredentialFileAuthSection) -> None: def __init__(self, name: str, section: CredentialFileAuthSection, config: Config) -> None:
super().__init__(name) super().__init__(name)
path = section.path() path = config.default_section.working_dir() / section.path()
try: try:
with open(path) as f: with open(path) as f:
lines = list(f) lines = list(f)

View File

@ -69,6 +69,7 @@ class Section:
class DefaultSection(Section): class DefaultSection(Section):
def working_dir(self) -> Path: def working_dir(self) -> Path:
# TODO Change to working dir instead of manually prepending it to paths
pathstr = self.s.get("working_dir", ".") pathstr = self.s.get("working_dir", ".")
return Path(pathstr).expanduser() return Path(pathstr).expanduser()