From c42bef6f02e36ac1e57e7812414beff438108f56 Mon Sep 17 00:00:00 2001 From: Daniel Dizdarevic Date: Mon, 8 May 2023 17:47:21 +0200 Subject: [PATCH] Catch exception if no password found --- src/ldaptool/search/config.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ldaptool/search/config.py b/src/ldaptool/search/config.py index 438d980..6dd72f0 100644 --- a/src/ldaptool/search/config.py +++ b/src/ldaptool/search/config.py @@ -148,7 +148,9 @@ class Keepass(PasswordManager): password = getpass.getpass(f"KeePass password for database {self.database}: ") kp = pykeepass.PyKeePass(self.database, password=password) entry = kp.find_entries(username=password_name, first=True) - return entry.password # type: ignore + if entry: + return entry.password # type: ignore + @dataclasses.dataclass @@ -221,6 +223,11 @@ class Config: if realm.account is None: raise RuntimeError("Can't get password without acccount - should use kerberos instead") if self.password_manager: - return self.password_manager.get_password(realm.password_name) + password = self.password_manager.get_password(realm.password_name) + else: + password = getpass.getpass(f"Enter password for {realm.password_name}: ") - return getpass.getpass(f"Enter password for {realm.password_name}: ") + if password: + return password + else: + raise SystemExit(f"No password found for {realm.password_name}")