implement ops hub extension contract
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a053ff-1d6f-7fe2-ac1c-a6eb40a42a0c
This commit is contained in:
parent
9bbbf2032d
commit
75f4944144
14 changed files with 662 additions and 43 deletions
50
scripts/hub-extension-check.py
Normal file
50
scripts/hub-extension-check.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Validate the owner package against hub-core's versioned schemas."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from jsonschema import Draft202012Validator, FormatChecker
|
||||
|
||||
from ops_hub.extension_contract import load_extension_package, validation_receipt
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--hub-core-repo", type=Path, default=Path("../hub-core"))
|
||||
args = parser.parse_args()
|
||||
|
||||
root = (
|
||||
args.hub_core_repo
|
||||
/ "hub_core"
|
||||
/ "contracts"
|
||||
/ "helixforge_hub_extension"
|
||||
/ "v0_1_0"
|
||||
)
|
||||
schemas = root / "schemas"
|
||||
package = load_extension_package()
|
||||
for key, schema_name in (
|
||||
("descriptor", "hub-descriptor.schema.json"),
|
||||
("manifest", "hub-manifest.schema.json"),
|
||||
):
|
||||
schema = json.loads((schemas / schema_name).read_text(encoding="utf-8"))
|
||||
Draft202012Validator.check_schema(schema)
|
||||
Draft202012Validator(schema, format_checker=FormatChecker()).validate(package[key])
|
||||
|
||||
catalog = json.loads((root / "catalogs" / "event-types.json").read_text(encoding="utf-8"))
|
||||
known_events = {entry["type"] for entry in catalog["event_types"]}
|
||||
declared_events = set(package["manifest"]["events_emitted"])
|
||||
declared_events.update(package["manifest"]["events_consumed"])
|
||||
unknown = sorted(declared_events - known_events)
|
||||
if unknown:
|
||||
raise SystemExit("events absent from hub-core catalog: " + ", ".join(unknown))
|
||||
|
||||
print(json.dumps(validation_receipt(), indent=2, sort_keys=True))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue