AccessPath / tools /sanitize_log_stream.py
anonymous-accesspath's picture
Audited anonymous-review AccessPath release
2f382c4 verified
Raw
History Blame Contribute Delete
1.13 kB
#!/usr/bin/env python3
"""Filter a text stream so Slurm logs do not expose local identity details."""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from accesspath3r.privacy import sanitize_text # noqa: E402
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument("--project-root", type=Path, required=True)
parser.add_argument("--output-root", type=Path, default=None)
parser.add_argument("--sensitive-path", action="append", default=[])
return parser
def main() -> int:
args = build_parser().parse_args()
for chunk in sys.stdin:
sys.stdout.write(
sanitize_text(
chunk,
project_root=args.project_root,
output_root=args.output_root,
sensitive_paths=args.sensitive_path,
)
)
sys.stdout.flush()
return 0
if __name__ == "__main__":
raise SystemExit(main())