Skip to content

Commit

Permalink
Use configured secret engine mount point
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Nov 6, 2024
1 parent 99c035d commit 29e5d0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/sms/core/secrets_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class VaultConfig(BaseSettings):
vault_token: str = Field(
default=..., description="Token for the Vault", examples=["dev-token"]
)
vault_secrets_mount_point: str = Field(
default="secret",
examples=["secret"],
description="Name used to address the secret engine under a custom mount path.",
)


class SecretsHandler(SecretsHandlerPort):
Expand All @@ -52,7 +57,10 @@ def client(self) -> HvacClient:
def get_secrets(self, vault_path: str) -> list[str]:
"""Return the IDs of all secrets in the specified vault."""
try:
secrets = self.client.secrets.kv.v2.list_secrets(path=vault_path)
secrets = self.client.secrets.kv.v2.list_secrets(
path=vault_path,
mount_point=self._config.vault_secrets_mount_point,
)
secret_ids = secrets["data"]["keys"]
return secret_ids
except InvalidPath:
Expand All @@ -73,5 +81,6 @@ def delete_secrets(self, vault_path: str):

for secret in secrets:
self.client.secrets.kv.v2.delete_metadata_and_all_versions(
path=f"{vault_path}/{secret}"
path=f"{vault_path}/{secret}",
mount_point=self._config.vault_secrets_mount_point,
)
3 changes: 2 additions & 1 deletion tests/unit/secrets/test_secrets_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def test_delete_successful(

# delete_metadata_and_all_versions is called for each secret
internal_deletion_calls = [
call(path=f"{DEFAULT_VAULT_PATH}/{secret}") for secret in stored_secrets
call(path=f"{DEFAULT_VAULT_PATH}/{secret}", mount_point="secret")
for secret in stored_secrets
]
mock_client.secrets.kv.v2.delete_metadata_and_all_versions.assert_has_calls(
internal_deletion_calls,
Expand Down

0 comments on commit 29e5d0b

Please sign in to comment.