diff --git a/examples/redact_sensitive.py b/examples/redact_sensitive.py index a7e3a80..004cdbd 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,10 @@ def main(): input("Enter a regex indicating sensitive content: ").lower() ) + new_string = input("Enter the string used to replace sensitive content: ") + if not new_string: + new_string = "REDACTED" + print("") if DRYRUN: print( @@ -74,12 +76,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, new_string) else: - _redact_bucket(bid_to_redact, pattern) + _redact_bucket(bid_to_redact, pattern, new_string) -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 +99,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 +123,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):