From 94e0309d82af702273ffe7f5ae1c5a046e0b206e Mon Sep 17 00:00:00 2001 From: Vinfall <91039000+Vinfall@users.noreply.github.com> Date: Mon, 3 Feb 2025 15:54:43 +0800 Subject: [PATCH] feat(example): support custom string in redact_sensitive script --- examples/redact_sensitive.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/redact_sensitive.py b/examples/redact_sensitive.py index a7e3a80..1ada0a8 100644 --- a/examples/redact_sensitive.py +++ b/examples/redact_sensitive.py @@ -4,7 +4,6 @@ Issues/improvements: - If an event matches the sensitive string, only the sensitive field will be redacted (so if the title matches but not the URL, the URL will remain unredacted) - - One might not want to redact to the non-informative 'REDACTED', but instead to a string with secret meaning. - No preview of the events/strings to be redacted. """ @@ -24,7 +23,6 @@ aw: ActivityWatchClient -REDACTED = "REDACTED" DRYRUN = True @@ -59,6 +57,8 @@ def main(): input("Enter a regex indicating sensitive content: ").lower() ) + REDACTED = input("Enter the string used to replace sensitive content: ") + print("") if DRYRUN: print( @@ -74,12 +74,12 @@ def main(): for bucket_id in buckets.keys(): if bucket_id.startswith("aw-watcher-afk"): continue - _redact_bucket(bucket_id, pattern) + _redact_bucket(bucket_id, pattern, REDACTED) else: - _redact_bucket(bid_to_redact, pattern) + _redact_bucket(bid_to_redact, pattern, REDACTED) -def _redact_bucket(bucket_id: str, pattern: Union[str, Pattern]): +def _redact_bucket(bucket_id: str, pattern: Union[str, Pattern], REDACTED: str): print(f"\nChecking bucket: {bucket_id}") global aw @@ -97,7 +97,7 @@ def _redact_bucket(bucket_id: str, pattern: Union[str, Pattern]): for e in events: if e.id in sensitive_ids: e_before = e - e = _redact_event(e, pattern) + e = _redact_event(e, pattern, REDACTED) print(f"\nData before: {e_before.data}") print(f"Data after: {e.data}") @@ -121,7 +121,7 @@ def _check_event(e: Event, pattern: Union[str, Pattern]) -> bool: return False -def _redact_event(e: Event, pattern: Union[str, Pattern]) -> Event: +def _redact_event(e: Event, pattern: Union[str, Pattern], REDACTED: str) -> Event: e = deepcopy(e) for k, v in e.data.items(): if isinstance(v, str):