Skip to content

Commit

Permalink
fix(hashicorp): Incorrect work with json in vault code (#2917)
Browse files Browse the repository at this point in the history
Signed-off-by: Adilbek Kangerey <[email protected]>
Co-authored-by: Tal <[email protected]>
  • Loading branch information
00041275 and talboren authored Dec 30, 2024
1 parent 75d7b91 commit 7a34226
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions keep/secretmanager/vaultsecretmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, context_manager, **kwargs):
def write_secret(self, secret_name: str, secret_value: str) -> None:
self.logger.info("Writing secret", extra={"secret_name": secret_name})
self.client.secrets.kv.v2.create_or_update_secret(
path=secret_name, secret=json.loads(secret_value)
path=secret_name, secret={"value": secret_value}
)
self.logger.info(
"Secret created/updated successfully", extra={"secret_name": secret_name}
Expand All @@ -58,7 +58,14 @@ def read_secret(self, secret_name: str, is_json: bool = False) -> str | dict:
self.logger.info(
"Secret retrieved successfully", extra={"secret_name": secret_name}
)
return secret["data"]["data"]
secret_value = secret["data"]["data"].get("value")
if is_json:
try:
secret_value = json.loads(secret_value)
except json.JSONDecodeError as e:
self.logger.error("Failed to parse secret as JSON", extra={"secret_name": secret_name, "error": str(e)})
raise
return secret_value

def delete_secret(self, secret_name: str) -> None:
self.logger.info("Deleting secret", extra={"secret_name": secret_name})
Expand Down

0 comments on commit 7a34226

Please sign in to comment.