| |
| """Revoke an unused D2 invitation by id. |
| |
| Usage: |
| python scripts/d2_revoke_invitation.py --db-path /tmp/amanpay-d2/amanpay.db \ |
| --invitation-id inv_xxxxxxxx |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
|
|
| from amanpay.identity.cli import emit, open_storage, snapshot_best_effort |
| from amanpay.identity.repository import D2Repository |
|
|
|
|
| def main(argv=None) -> int: |
| ap = argparse.ArgumentParser(description="Revoke a D2 invitation") |
| ap.add_argument("--db-path", required=True) |
| ap.add_argument("--invitation-id", required=True) |
| args = ap.parse_args(argv) |
|
|
| storage = open_storage(args.db_path) |
| try: |
| repo = D2Repository(storage.db) |
| inv = repo.get_invitation(args.invitation_id) |
| if inv is None: |
| raise SystemExit(f"error: invitation not found: {args.invitation_id!r}") |
| repo.revoke_invitation(args.invitation_id) |
| gen = snapshot_best_effort(storage) |
| emit({"invitation_id": args.invitation_id, "revoked": True, |
| "snapshot_generation": gen}) |
| finally: |
| storage.close() |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|