mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-17 23:45:03 +01:00
Some checks failed
crdt-sync pre-commit / pre-commit (push) Has been cancelled
crdt-sync tests / test (push) Has been cancelled
dependency freshness / dependencies on newest stable (push) Has been cancelled
file length / file-length (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
palette drift / palette (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
shared gate tests / gate unit tests (push) Has been cancelled
clear_plaintext_prefix + tool/e2e_cleanup: dry run by default, never creates a header, deletes the old plaintext prefix only when every old record is in the encrypted copy. Todo: fda71ed1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""Clear an app's old plaintext RTDB prefix after the E2E copy is verified.
|
|
|
|
Dry run by default; ``--apply`` deletes. Run only once every device runs an
|
|
encrypting build::
|
|
|
|
python3 -m tool.e2e_cleanup todo-sync/notes --app todo
|
|
python3 -m tool.e2e_cleanup todo-sync/notes --app todo --apply
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from typing import TYPE_CHECKING
|
|
|
|
from crdt_sync import (
|
|
PASSWORD_FILE,
|
|
E2eLockedError,
|
|
FirebaseConfig,
|
|
clear_plaintext_prefix,
|
|
firebase_client_for,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from crdt_sync import RemoteStore
|
|
|
|
|
|
def run(store: RemoteStore, old_prefix: str, passphrase: str, *, apply: bool) -> int:
|
|
"""Clear (or list) ``old_prefix``; return a process exit code."""
|
|
try:
|
|
paths = clear_plaintext_prefix(
|
|
store, old_prefix, passphrase=passphrase, apply=apply
|
|
)
|
|
except E2eLockedError as exc:
|
|
sys.stdout.write(f"refused: {exc}\n")
|
|
return 1
|
|
verb = "deleted" if apply else "would delete"
|
|
sys.stdout.write(f"{verb} {len(paths)} plaintext blob(s) under /{old_prefix}\n")
|
|
for path in paths:
|
|
sys.stdout.write(f" {path}\n")
|
|
return 0
|
|
|
|
|
|
def main(argv: list[str]) -> int: # pragma: no cover - live database entry
|
|
"""Parse args and run against the live database."""
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("old_prefix")
|
|
parser.add_argument("--app", required=True, help="seeded session name")
|
|
parser.add_argument("--apply", action="store_true")
|
|
args = parser.parse_args(argv)
|
|
client = firebase_client_for(args.app, config=FirebaseConfig.load())
|
|
passphrase = PASSWORD_FILE.read_text(encoding="utf-8").strip()
|
|
return run(client, args.old_prefix, passphrase, apply=args.apply)
|
|
|
|
|
|
if __name__ == "__main__": # pragma: no cover
|
|
raise SystemExit(main(sys.argv[1:]))
|