generated from coulomb/repo-seed
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Register the guide-board pilot metadata schema through the HTTP API."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import urllib.error
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
SCHEMA_SLUG = "guide-board.run.v1"
|
|
|
|
|
|
def main() -> None:
|
|
api_url = os.environ.get("ARTIFACTSTORE_API_URL", "http://127.0.0.1:8000").rstrip("/")
|
|
token = os.environ["ARTIFACTSTORE_API_TOKEN"]
|
|
schema_path = Path(
|
|
os.environ.get("ARTIFACTSTORE_GUIDE_BOARD_SCHEMA", "schemas/guide-board.run.v1.json")
|
|
)
|
|
payload = {
|
|
"slug": SCHEMA_SLUG,
|
|
"json_schema": json.loads(schema_path.read_text(encoding="utf-8")),
|
|
}
|
|
request = urllib.request.Request(
|
|
f"{api_url}/metadata-schemas",
|
|
data=json.dumps(payload).encode(),
|
|
headers={
|
|
"Authorization": f"Bearer {token}",
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
},
|
|
method="POST",
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(request, timeout=30) as response:
|
|
print(response.read().decode("utf-8"))
|
|
except urllib.error.HTTPError as exc:
|
|
detail = exc.read().decode("utf-8", errors="replace")
|
|
raise SystemExit(f"HTTP {exc.code}: {detail}") from exc
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|