From 34fcd259ef9c7d77021701b2b16ea33c9ff44ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Wed, 10 May 2023 16:25:41 +0200 Subject: [PATCH] improve config loading: don't modify dicts to allow yaml repeated nodes --- src/ldaptool/search/config.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ldaptool/search/config.py b/src/ldaptool/search/config.py index a8da6e3..7c99562 100644 --- a/src/ldaptool/search/config.py +++ b/src/ldaptool/search/config.py @@ -30,12 +30,12 @@ class Realm: @staticmethod def load(name: str, data: typing.Any) -> Realm: assert isinstance(data, dict), f"Realm section isn't a dictionary: {data!r}" - domain = data.pop("domain") - servers = data.pop("servers").split() - forest_root_domain = data.pop("forest_root_domain", domain) - account = data.pop("account", None) - password_file = data.pop("password_file", None) - password_folder = data.pop("password_folder", None) + domain = data["domain"] + servers = data["servers"].split() + forest_root_domain = data.get("forest_root_domain", domain) + account = data.get("account", None) + password_file = data.get("password_file", None) + password_folder = data.get("password_folder", None) return Realm( name=name, domain=domain, @@ -102,8 +102,8 @@ class Keyringer(PasswordManager): @staticmethod def load(data: typing.Any) -> Keyringer: assert isinstance(data, dict) - keyring = data.pop("keyring") - folder = data.pop("folder") + keyring = data["keyring"] + folder = data.get("folder", "") return Keyringer(keyring=keyring, folder=folder) def get_password(self, password_name: str) -> str: @@ -200,7 +200,7 @@ class Config: data = yaml.safe_load(f) assert isinstance(data, dict) assert "realms" in data, "Missing realms section in config" - realms_data = data.pop("realms") + realms_data = data["realms"] assert isinstance(realms_data, dict) realms = {} for name, realm_data in realms_data.items(): @@ -210,15 +210,15 @@ class Config: if "keyringer" in data: if password_manager: raise ValueError("Can only set a single password manager") - password_manager = Keyringer.load(data.pop("keyringer")) + password_manager = Keyringer.load(data["keyringer"]) if "keepass" in data: if password_manager: raise ValueError("Can only set a single password manager") - password_manager = Keepass.load(data.pop("keepass")) + password_manager = Keepass.load(data["keepass"]) if "password-script" in data: if password_manager: raise ValueError("Can only set a single password manager") - password_manager = PasswordScript.load(data.pop("password-script")) + password_manager = PasswordScript.load(data["password-script"]) return Config(realms=realms, password_manager=password_manager)