-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florimond Manca
committed
Mar 23, 2020
1 parent
bcbc37e
commit 0cbc9fa
Showing
4 changed files
with
113 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Set | ||
|
||
|
||
class SecretsSanitizer: | ||
""" | ||
A helper for sanitizing secrets (password, keys, ...) in text output. | ||
""" | ||
|
||
REDACTED = '********' | ||
|
||
def __init__(self): | ||
# type: () -> None | ||
self.patterns = set() # type: Set[str] | ||
|
||
def register(self, secret): | ||
# type: (str) -> None | ||
self.patterns.add(secret) | ||
|
||
def sanitize(self, text): | ||
# type: (str) -> str | ||
for pattern in self.patterns: | ||
text = text.replace(pattern, self.REDACTED) | ||
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters