Make hub discovery public
This commit is contained in:
parent
2e450e3a2d
commit
5c13de1b8f
7 changed files with 100 additions and 20 deletions
|
|
@ -67,7 +67,7 @@ def main() -> int:
|
|||
|
||||
|
||||
def ensure_hub() -> dict[str, Any]:
|
||||
existing = find_by(list_items("/api/v2/hubs", OPERATOR_KEY), "slug", HUB_SLUG)
|
||||
existing = find_by(list_items("/api/v2/hubs", None), "slug", HUB_SLUG)
|
||||
if existing:
|
||||
print(f"reusing hub {HUB_SLUG} ({existing['id']})", file=sys.stderr)
|
||||
return existing
|
||||
|
|
@ -216,7 +216,7 @@ def verify_event(runtime_key: str, widget_id: str, event_id: str) -> None:
|
|||
raise RuntimeError(f"created event {event_id} was not returned by list endpoint")
|
||||
|
||||
|
||||
def list_items(path: str, token: str) -> list[dict[str, Any]]:
|
||||
def list_items(path: str, token: str | None) -> list[dict[str, Any]]:
|
||||
response = request_json("GET", path, token, None, expected={200})
|
||||
data = response.get("data", [])
|
||||
if not isinstance(data, list):
|
||||
|
|
@ -227,14 +227,15 @@ def list_items(path: str, token: str) -> list[dict[str, Any]]:
|
|||
def request_json(
|
||||
method: str,
|
||||
path: str,
|
||||
token: str,
|
||||
token: str | None,
|
||||
body: dict[str, Any] | None,
|
||||
*,
|
||||
expected: set[int],
|
||||
) -> dict[str, Any]:
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
request = urllib.request.Request(BASE_URL + path, data=data, method=method)
|
||||
request.add_header("Authorization", f"Bearer {token}")
|
||||
if token is not None:
|
||||
request.add_header("Authorization", f"Bearer {token}")
|
||||
request.add_header("Accept", "application/json")
|
||||
if body is not None:
|
||||
request.add_header("Content-Type", "application/json")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue