46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Create and verify an allowlisted Hub state archive without secrets."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from packages.hub_operations.backup import BackupManager, BackupPolicy # noqa: E402
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--source-root", type=Path, required=True)
|
|
parser.add_argument("--backup-root", type=Path, required=True)
|
|
parser.add_argument("--name", required=True)
|
|
parser.add_argument("--include", action="append", required=True)
|
|
args = parser.parse_args()
|
|
manager = BackupManager(args.backup_root, policy=BackupPolicy())
|
|
artifact = manager.create_archive(
|
|
args.source_root, name=args.name, include=(Path(item) for item in args.include)
|
|
)
|
|
verified = manager.verify(artifact)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"archive": str(verified.archive),
|
|
"sha256": verified.sha256,
|
|
"bytes": verified.bytes,
|
|
"entries": verified.entries,
|
|
},
|
|
sort_keys=True,
|
|
)
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|