Skip to content

Commit

Permalink
feat(example): support custom string in redact_sensitive script
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinfall committed Feb 3, 2025
1 parent 8f9483d commit 94e0309
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/redact_sensitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand All @@ -24,7 +23,6 @@

aw: ActivityWatchClient

REDACTED = "REDACTED"
DRYRUN = True


Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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}")

Expand All @@ -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):
Expand Down

0 comments on commit 94e0309

Please sign in to comment.