Properly invalidate exceptions

The simple authenticator now properly invalidates its credentials. Also, the
invalidation functions have been given better names and documentation.
This commit is contained in:
Joscha
2021-05-15 17:37:05 +02:00
parent b70b62cef5
commit d63494908d
3 changed files with 50 additions and 7 deletions

View File

@ -1,6 +1,6 @@
from typing import Optional, Tuple
from ..authenticator import Authenticator, AuthSection
from ..authenticator import Authenticator, AuthException, AuthSection
from ..conductor import TerminalConductor
from ..config import Config
from ..utils import agetpass, ainput
@ -42,7 +42,26 @@ class SimpleAuthenticator(Authenticator):
if self.password is None:
self.password = await agetpass("Password: ")
else:
print("Password: *******")
return self.username, self.password
def invalidate_credentials(self) -> None:
if self.username_fixed and self.password_fixed:
raise AuthException("Configured credentials are invalid")
if not self.username_fixed:
self.username = None
if not self.password_fixed:
self.password = None
def invalidate_username(self) -> None:
if self.username_fixed:
raise AuthException("Configured username is invalid")
else:
self.username = None
def invalidate_password(self) -> None:
if self.password_fixed:
raise AuthException("Configured password is invalid")
else:
self.password = None