aw-client icon indicating copy to clipboard operation
aw-client copied to clipboard

feat(example): support custom string in redact_sensitive script

Open Vinfall opened this issue 11 months ago • 0 comments

Just like the title said. I thought I open a PR months ago but obviously I didn't. Would fallback to previous "REDACTED" if the input is empty.

Command line example (ignore the make command):

$ make run
WET RUNNING!
source .venv/bin/activate; \
python3 redact_sensitive_patched.py --wet
Buckets: 
 - aw-watcher-window_xxx
 - aw-watcher-afk_xxx
 - aw-stopwatch

In which bucket are the events you want to redact? (* for all): * 
Do you want to search by regex or string? (regex/string): string

NOTE: Matching is not case sensitive!
Enter a string indicating sensitive content: blahblahtoreplace
Enter the string used to replace sensitive content: allohainplace

WARNING: Note that this performs an operation that cannot be undone. We strongly recommend that you backup/export your data before proceeding.
Press ENTER to continue, or Ctrl-C to abort

Checking bucket: aw-watcher-window_xxx
Found 0 sensitive events

Checking bucket: aw-stopwatch
Found 0 sensitive events

By the way, would you accept a PR to add Inline script metadata per PEP 723 in these scripts?

This is useful because I "install" activitywatch via Linux tarball and do not want to pip install aw-client again to use these scripts. With inline script metadata, I can run them simply by uv run redact_sensitive.py and it would handle dependency/venv automatically.

It would look like this:

# /// script
# requires-python = ">=3.11"
# dependencies = ["aw-client"]
# ///

import re
import sys
from copy import deepcopy
from typing import (
    List,
    Pattern,
    Set,
    Union,
    cast,
)

from aw_client import ActivityWatchClient
from aw_core import Event

aw: ActivityWatchClient

[!IMPORTANT] Adds support for custom replacement strings in examples/redact_sensitive.py for redacting sensitive data.

  • Behavior:
    • Adds input prompt in main() for custom replacement string for sensitive content.
    • Passes custom string to _redact_bucket() and _redact_event() for redaction.
  • Functions:
    • Updates _redact_bucket() to accept and use custom replacement string.
    • Updates _redact_event() to replace sensitive content with custom string.
  • Misc:
    • Removes hardcoded REDACTED string from global scope.

This description was created by Ellipsis for 94e0309d82af702273ffe7f5ae1c5a046e0b206e. It will automatically update as commits are pushed.

Vinfall avatar Feb 03 '25 08:02 Vinfall