41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Assert the released v2 capability contract is truthful and explicit."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
CONTRACT = Path("contracts/repository/v1/capabilities-v2.0.json")
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--release", required=True)
|
|
parser.add_argument("--include", required=True)
|
|
parser.add_argument("--exclude", required=True)
|
|
args = parser.parse_args()
|
|
if args.release != "v2.0":
|
|
raise SystemExit("only v2.0 capability certification is supported")
|
|
try:
|
|
payload = json.loads(CONTRACT.read_text(encoding="utf-8"))
|
|
except (OSError, json.JSONDecodeError) as error:
|
|
raise SystemExit(f"cannot load capability contract: {error}") from error
|
|
available = set(payload["sources"])
|
|
available.update(name for name, enabled in payload["features"].items() if enabled)
|
|
required = {item for item in args.include.split(",") if item}
|
|
forbidden = {item for item in args.exclude.split(",") if item}
|
|
missing = sorted(required - available)
|
|
present = sorted(forbidden & available)
|
|
if missing or present:
|
|
raise SystemExit(
|
|
f"capability assertion failed: missing={missing}, forbidden={present}"
|
|
)
|
|
print(f"v2.0 capabilities certified: {', '.join(sorted(available))}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|