A stub keyvault to simulate an integration with Azure Keyvault. This would be
replaced by a keyvault library.
Source code in data_platform_utils/keyvault_stub.py
| class SecretClient: # pragma: no coverage
"""A stub keyvault to simulate an integration with Azure Keyvault. This would be
replaced by a keyvault library.
"""
def get_secret(self, secret_name: str) -> str:
"""returns a secret from the keyvault"""
secrets = self.__secrets
location, _, attribute = secret_name.split("__")
secret = secrets.get(location, {}).get(attribute)
return secret or ""
def __init__(
self, vault_url: str | None = None, credential: str | None = None
) -> None:
secrets = {"SOURCE": {}, "DESTINATION": {}}
if env_path := find_dotenv(usecwd=True):
with open(env_path) as env:
for line in env:
line = line.strip()
if line and not line.strip().startswith("#") and "=" in line:
key, value = line.split(sep="=", maxsplit=1)
keys = key.split("__")
if len(keys) == 2:
location, attribute = keys
secrets[location][attribute] = value
self.__secrets = secrets
|
returns a secret from the keyvault
Source code in data_platform_utils/keyvault_stub.py
| def get_secret(self, secret_name: str) -> str:
"""returns a secret from the keyvault"""
secrets = self.__secrets
location, _, attribute = secret_name.split("__")
secret = secrets.get(location, {}).get(attribute)
return secret or ""
|