from . import Password, PasswordManager
|
|
|
|
import subprocess
|
|
from typing import Tuple, List
|
|
|
|
class GNUPassPasswordManager( PasswordManager ):
|
|
"""
|
|
GNU pass password manager
|
|
https://www.passwordstore.org/
|
|
"""
|
|
|
|
@classmethod
|
|
def name( cls ):
|
|
return "pass"
|
|
|
|
|
|
@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
|
|
"""
|
|
return (True, [])
|
|
|
|
|
|
def __init__( self, config: dict ):
|
|
# no parameters
|
|
pass
|
|
|
|
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
|
|
"""
|
|
result = subprocess.run([
|
|
"pass",
|
|
identifier
|
|
],
|
|
capture_output = True
|
|
)
|
|
lines = result.stdout.decode("utf-8").splitlines()
|
|
if len(lines) == 0:
|
|
return Password( None )
|
|
ret = Password( lines[0] )
|
|
for i in range(1, len(lines)):
|
|
fields = lines[i].split(': ', 1)
|
|
if len(fields) != 2:
|
|
continue
|
|
if fields[0] == "login":
|
|
ret.login = str(fields[1])
|
|
return ret
|