40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Redact credential assignments from every background-process result."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
|
|
BEFORE = ''' result[field] = redact_terminal_output(value, command)
|
|
'''
|
|
|
|
AFTER = ''' result[field] = redact_sensitive_text(
|
|
redact_terminal_output(value, command),
|
|
code_file=False,
|
|
)
|
|
'''
|
|
|
|
|
|
def patch(source: Path, destination: Path) -> None:
|
|
"""Apply unconditional result redaction and fail on upstream drift."""
|
|
content = source.read_text(encoding="utf-8")
|
|
if content.count(BEFORE) != 1:
|
|
raise RuntimeError("Hermes process-result redaction context changed")
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.write_text(content.replace(BEFORE, AFTER, 1), encoding="utf-8")
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("source", type=Path)
|
|
parser.add_argument("destination", type=Path)
|
|
args = parser.parse_args()
|
|
patch(args.source, args.destination)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|