From afefb5415b982730759e58c4fc7ffaa8b841bcb3 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Fri, 11 Jul 2025 14:19:16 -0400 Subject: [PATCH] cli: avoid fingerprint prompt when option provided --- src/password_manager/manager.py | 25 ++++++++++++++++++------- src/seedpass/api.py | 7 ++++--- src/seedpass/cli.py | 8 ++++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/password_manager/manager.py b/src/password_manager/manager.py index 56a151a..f44e94b 100644 --- a/src/password_manager/manager.py +++ b/src/password_manager/manager.py @@ -102,8 +102,14 @@ class PasswordManager: verification, ensuring the integrity and confidentiality of the stored password database. """ - def __init__(self) -> None: - """Initialize the PasswordManager.""" + def __init__(self, fingerprint: Optional[str] = None) -> None: + """Initialize the PasswordManager. + + Parameters + ---------- + fingerprint: + Optional seed profile fingerprint to select without prompting. + """ initialize_app() self.ensure_script_checksum() self.encryption_mode: EncryptionMode = EncryptionMode.SEED_ONLY @@ -131,11 +137,16 @@ class PasswordManager: # Initialize the fingerprint manager first self.initialize_fingerprint_manager() - # Ensure a parent seed is set up before accessing the fingerprint directory - self.setup_parent_seed() - - # Set the current fingerprint directory - self.fingerprint_dir = self.fingerprint_manager.get_current_fingerprint_dir() + if fingerprint: + # Load the specified profile without prompting + self.select_fingerprint(fingerprint) + else: + # Ensure a parent seed is set up before accessing the fingerprint directory + self.setup_parent_seed() + # Set the current fingerprint directory after selection + self.fingerprint_dir = ( + self.fingerprint_manager.get_current_fingerprint_dir() + ) def ensure_script_checksum(self) -> None: """Initialize or verify the checksum of the manager script.""" diff --git a/src/seedpass/api.py b/src/seedpass/api.py index c1482e1..e87c45a 100644 --- a/src/seedpass/api.py +++ b/src/seedpass/api.py @@ -51,9 +51,10 @@ def start_server(fingerprint: str | None = None) -> str: Optional seed profile fingerprint to select before starting the server. """ global _pm, _token - _pm = PasswordManager() - if fingerprint: - _pm.select_fingerprint(fingerprint) + if fingerprint is None: + _pm = PasswordManager() + else: + _pm = PasswordManager(fingerprint=fingerprint) _token = secrets.token_urlsafe(16) print(f"API token: {_token}") origins = [ diff --git a/src/seedpass/cli.py b/src/seedpass/cli.py index afe1f7b..cc98ace 100644 --- a/src/seedpass/cli.py +++ b/src/seedpass/cli.py @@ -44,11 +44,11 @@ app.add_typer(api_app, name="api") def _get_pm(ctx: typer.Context) -> PasswordManager: """Return a PasswordManager optionally selecting a fingerprint.""" - pm = PasswordManager() fp = ctx.obj.get("fingerprint") - if fp: - # `select_fingerprint` will initialize managers - pm.select_fingerprint(fp) + if fp is None: + pm = PasswordManager() + else: + pm = PasswordManager(fingerprint=fp) return pm