from . import Password, PasswordManager
|
|
|
|
from typing import Tuple, List, Optional
|
|
|
|
class PlainTextPasswordManager( PasswordManager ):
|
|
"""
|
|
Passwords provided as plain-text (bad idea, but always useful)
|
|
"""
|
|
|
|
@classmethod
|
|
def name( cls ):
|
|
return "plaintext"
|
|
|
|
|
|
@classmethod
|
|
def verify( cls, config: dict, path: str ) -> Tuple[bool, List[str]]:
|
|
"""
|
|
Verifies that the configuration is correct
|
|
|
|
Args:
|
|
config: dict with password manager configuration
|
|
path: path to the "config" dict in the main configuration file
|
|
|
|
Returns:
|
|
bool: true if the config is correct
|
|
List[str]: list of errors if the config is not correct
|
|
"""
|
|
ok = True
|
|
errors = []
|
|
|
|
if "passwords" not in config:
|
|
ok = False
|
|
errors.append(f'Missing section "{path}.passwords"')
|
|
elif type(config["passwords"]) is not dict:
|
|
ok = False
|
|
errors.append(f'"{path}.passwords" is not dict')
|
|
|
|
return (ok, errors)
|
|
|
|
|
|
def __init__( self, config: dict ):
|
|
self.passwords = config["passwords"]
|
|
|
|
|
|
def get( self, identifier: str ) -> Password:
|
|
"""
|
|
Gets a password from the manager.
|
|
|
|
This function is overriden by the concrete PasswordManager instances.
|
|
|
|
Args:
|
|
identifier: which password to get
|
|
|
|
Returns:
|
|
None if the password is not found,
|
|
the password otherwise
|
|
"""
|
|
if identifier not in self.passwords:
|
|
return Password( None )
|
|
return Password( self.passwords[identifier] )
|