Anonymize logged in users flair in logs (#4861)

* Anonymize logged in users flair in logs #4838

* small improvement to regular expression

---------

Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
This commit is contained in:
clairericks
2023-04-24 11:53:38 +01:00
committed by GitHub
parent c0bf77bd8c
commit d5917587bc

View File

@@ -65,6 +65,14 @@ class FormatterWithExceptions(logging.Formatter):
text_mocked = re.sub(pattern, replacement, text)
return text_mocked
@staticmethod
def mock_flair(text: str) -> str:
pattern = r'("FLAIR": "\[)(.*?)\]'
replacement = r"\1 FILTERED_FLAIR ]"
text_mocked = re.sub(pattern, replacement, text)
return text_mocked
@staticmethod
def mock_home_directory(text: str) -> str:
user_home_directory = str(HOME_DIRECTORY)
@@ -85,6 +93,7 @@ class FormatterWithExceptions(logging.Formatter):
text_filtered = cls.mock_email(text=text_filtered)
text_filtered = cls.mock_password(text=text_filtered)
text_filtered = cls.mock_home_directory(text=text_filtered)
text_filtered = cls.mock_flair(text=text_filtered)
return text_filtered