mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Move logging logic to singleton
- Renamed module and class because "conductor" didn't make a lot of sense - Used singleton approach (there's only one stdout after all) - Redesigned progress bars (now with download speed!)
This commit is contained in:
@ -2,7 +2,6 @@ from configparser import SectionProxy
|
||||
from typing import Callable, Dict
|
||||
|
||||
from ..authenticator import Authenticator, AuthSection
|
||||
from ..conductor import TerminalConductor
|
||||
from ..config import Config
|
||||
from .simple import SimpleAuthenticator, SimpleAuthSection
|
||||
from .tfa import TfaAuthenticator
|
||||
@ -11,12 +10,11 @@ AuthConstructor = Callable[[
|
||||
str, # Name (without the "auth:" prefix)
|
||||
SectionProxy, # Authenticator's section of global config
|
||||
Config, # Global config
|
||||
TerminalConductor, # Global conductor instance
|
||||
], Authenticator]
|
||||
|
||||
AUTHENTICATORS: Dict[str, AuthConstructor] = {
|
||||
"simple": lambda n, s, c, t:
|
||||
SimpleAuthenticator(n, SimpleAuthSection(s), c, t),
|
||||
"tfa": lambda n, s, c, t:
|
||||
TfaAuthenticator(n, AuthSection(s), c, t),
|
||||
"simple": lambda n, s, c:
|
||||
SimpleAuthenticator(n, SimpleAuthSection(s), c),
|
||||
"tfa": lambda n, s, c:
|
||||
TfaAuthenticator(n, AuthSection(s), c),
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from ..authenticator import Authenticator, AuthException, AuthSection
|
||||
from ..conductor import TerminalConductor
|
||||
from ..config import Config
|
||||
from ..logging import log
|
||||
from ..utils import agetpass, ainput
|
||||
|
||||
|
||||
@ -20,9 +20,8 @@ class SimpleAuthenticator(Authenticator):
|
||||
name: str,
|
||||
section: SimpleAuthSection,
|
||||
config: Config,
|
||||
conductor: TerminalConductor,
|
||||
) -> None:
|
||||
super().__init__(name, section, config, conductor)
|
||||
super().__init__(name, section, config)
|
||||
|
||||
self._username = section.username()
|
||||
self._password = section.password()
|
||||
@ -34,7 +33,7 @@ class SimpleAuthenticator(Authenticator):
|
||||
if self._username is not None and self._password is not None:
|
||||
return self._username, self._password
|
||||
|
||||
async with self.conductor.exclusive_output():
|
||||
async with log.exclusive_output():
|
||||
if self._username is None:
|
||||
self._username = await ainput("Username: ")
|
||||
else:
|
||||
|
@ -1,8 +1,8 @@
|
||||
from typing import Tuple
|
||||
|
||||
from ..authenticator import Authenticator, AuthException, AuthSection
|
||||
from ..conductor import TerminalConductor
|
||||
from ..config import Config
|
||||
from ..logging import log
|
||||
from ..utils import ainput
|
||||
|
||||
|
||||
@ -12,15 +12,14 @@ class TfaAuthenticator(Authenticator):
|
||||
name: str,
|
||||
section: AuthSection,
|
||||
config: Config,
|
||||
conductor: TerminalConductor,
|
||||
) -> None:
|
||||
super().__init__(name, section, config, conductor)
|
||||
super().__init__(name, section, config)
|
||||
|
||||
async def username(self) -> str:
|
||||
raise AuthException("TFA authenticator does not support usernames")
|
||||
|
||||
async def password(self) -> str:
|
||||
async with self.conductor.exclusive_output():
|
||||
async with log.exclusive_output():
|
||||
code = await ainput("TFA code: ")
|
||||
return code
|
||||
|
||||
|
Reference in New Issue
Block a user