Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

fix: Notify to secrets to DB on complete redacted text #564

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/codegate/pipeline/secrets/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,13 @@ def obfuscate(self, text: str) -> tuple[str, int]:
# Store matches for logging
found_secrets = 0

# Replace each match with its encrypted value
# First pass. Replace each match with its encrypted value
logger.info("\nFound secrets:")
for start, end, match in absolute_matches:
hidden_secret = self._hide_secret(match)

# Replace the secret in the text
protected_text[start:end] = hidden_secret

self._notify_secret(match, protected_text)
found_secrets += 1
# Log the findings
logger.info(
Expand All @@ -153,6 +151,10 @@ def obfuscate(self, text: str) -> tuple[str, int]:
f"\nEncrypted: {hidden_secret}"
)

# Second pass. Notify the secrets in DB over the complete protected text.
for _, _, match in absolute_matches:
self._notify_secret(match, protected_text)

# Convert back to string
protected_string = "".join(protected_text)
print(f"\nProtected text:\n{protected_string}")
Expand Down
Loading