sbom-nexus/scripts/sync_repository_projections.py

36 lines
1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""Synchronize Repo Manager repository projections into SBOM Nexus."""
from __future__ import annotations
import argparse
import json
import urllib.error
from sbom_nexus.projection import sync_repository_projections
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source-url", default="http://127.0.0.1:8000")
parser.add_argument("--target-url", default="http://127.0.0.1:8010")
parser.add_argument("--host-id")
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
try:
result = sync_repository_projections(
args.source_url,
args.target_url,
dry_run=args.dry_run,
host_id=args.host_id,
)
except (urllib.error.URLError, json.JSONDecodeError) as exc:
raise SystemExit(f"Projection sync failed: {exc}") from exc
print(json.dumps(result, indent=2, sort_keys=True))
if not result["ok"]:
raise SystemExit(1)
if __name__ == "__main__":
main()