From 6e3036da7ffbe961281938bae973100e012f0f44 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 2 Dec 2024 17:43:43 +0100 Subject: [PATCH] Hardcoded fields are now correctly lowercase --- secret_loader/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/secret_loader/__init__.py b/secret_loader/__init__.py index ccc3b84..efe55bf 100644 --- a/secret_loader/__init__.py +++ b/secret_loader/__init__.py @@ -105,7 +105,7 @@ class SecretLoader: Hardcoded values are stored directly, and can be used to configure the other subsystems. """ - self.hardcoded: dict[str, str] = hardcoded + self.hardcoded: dict[str, str] = {k.lower(): v for k,v in hardcoded.items()} self.pass_folder = None self.vault_client = None self.env_key_prefix = None @@ -125,10 +125,11 @@ class SecretLoader: # Setup secrets path self.secret_folder = Path( - self.hardcoded.get(ENV_KEY_SECRETS_DIRECTORY) + self.hardcoded.get(ENV_KEY_SECRETS_DIRECTORY.lower()) or self._load_or_none_env(ENV_KEY_SECRETS_DIRECTORY) or DEFAULT_SECRETS_DIRECTORY, ) + logger.info('Secrets folder is set to: %s', self.secret_folder) # Setup pass self.pass_folder = self._load_or_none(ENV_KEY_PASS_FOLDER) @@ -161,7 +162,7 @@ class SecretLoader: return `None` if not found. """ return ( - self.hardcoded.get(secret_name) + self.hardcoded.get(secret_name.lower()) or self._load_or_none_path_or_file(secret_name) or self._load_or_none_local_password_store(secret_name) ) @@ -188,7 +189,10 @@ class SecretLoader: return None def _load_or_none_env(self, secret_name) -> str | None: - return os.environ.get(f'{self.env_key_prefix}_{secret_name.upper()}') + if self.env_key_prefix is None: + return None + env_key = f'{self.env_key_prefix}_{secret_name.upper()}' + return os.environ.get(env_key) def _load_or_none_local_password_store(self, secret_name: str) -> str | None: """Load secret from the `pass` password manager.