Created
September 19, 2011 12:29
-
-
Save dokterbob/1226398 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def sanitize_log_data(secret, data=None, leave_characters=4): | |
""" | |
Clean private/secret data from log statements and other data. | |
Assumes data and secret are strings. Replaces all but the first | |
`leave_characters` of `secret`, as found in `data`, with '*'. | |
If no data is given, all but the first `leave_characters` of secret | |
are simply replaced and returned. | |
""" | |
replace_secret = (secret[:leave_characters] + | |
(len(secret) - leave_characters) * '*') | |
if data: | |
return data.replace(secret, replace_secret) | |
return replace_secret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment