generated from coulomb/repo-seed
Add registry artifacts and projections
This commit is contained in:
@@ -12,12 +12,13 @@ from urllib.parse import parse_qs, urlparse
|
||||
from .registry import (
|
||||
RegistryError,
|
||||
RegistryStore,
|
||||
backstage_projection,
|
||||
blast_radius,
|
||||
consumers,
|
||||
dependency_path_lines,
|
||||
graph_node,
|
||||
providers,
|
||||
unresolved_dependencies,
|
||||
xregistry_projection,
|
||||
)
|
||||
|
||||
|
||||
@@ -46,7 +47,7 @@ class RegistryHandler(BaseHTTPRequestHandler):
|
||||
if parts == ["graph", "nodes"]:
|
||||
return HTTPStatus.OK, self.store.combined_graph()["nodes"]
|
||||
if len(parts) == 3 and parts[0] == "graph" and parts[1] == "nodes":
|
||||
return HTTPStatus.OK, graph_node(self.store.combined_graph(), parts[2])
|
||||
return HTTPStatus.OK, self.store.graph_node_detail(parts[2])
|
||||
if parts == ["graph", "providers"]:
|
||||
return HTTPStatus.OK, providers(self.store.combined_graph(), _query_one(query, "capability_type"))
|
||||
if parts == ["graph", "consumers"]:
|
||||
@@ -59,6 +60,18 @@ class RegistryHandler(BaseHTTPRequestHandler):
|
||||
return HTTPStatus.OK, {"lines": dependency_path_lines(self.store.combined_graph(), _query_one(query, "service_id"))}
|
||||
if parts == ["exports", "state-hub"]:
|
||||
return HTTPStatus.OK, self.store.combined_graph()
|
||||
if parts == ["exports", "backstage"]:
|
||||
return HTTPStatus.OK, backstage_projection(self.store.combined_graph())
|
||||
if parts == ["exports", "xregistry"]:
|
||||
return HTTPStatus.OK, xregistry_projection(self.store.combined_graph())
|
||||
if parts == ["artifacts"]:
|
||||
return HTTPStatus.OK, self.store.list_artifacts(
|
||||
repo_slug=_query_optional(query, "repo_slug"),
|
||||
target_id=_query_optional(query, "target_id"),
|
||||
artifact_type=_query_optional(query, "artifact_type") or _query_optional(query, "type"),
|
||||
)
|
||||
if len(parts) == 2 and parts[0] == "artifacts":
|
||||
return HTTPStatus.OK, self.store.get_artifact(_int_id(parts[1], "artifact_id"))
|
||||
raise RegistryError(f"route not found: {path}", 404)
|
||||
|
||||
def _post(self, path: str, _query: dict[str, list[str]]) -> tuple[int, Any]:
|
||||
@@ -68,6 +81,8 @@ class RegistryHandler(BaseHTTPRequestHandler):
|
||||
return HTTPStatus.CREATED, self.store.upsert_repository(body)
|
||||
if len(parts) == 3 and parts[0] == "repositories" and parts[2] == "snapshots":
|
||||
return HTTPStatus.CREATED, self.store.add_snapshot(parts[1], body)
|
||||
if parts == ["artifacts"]:
|
||||
return HTTPStatus.CREATED, self.store.add_artifact(body)
|
||||
raise RegistryError(f"route not found: {path}", 404)
|
||||
|
||||
def _handle(self, action: Any) -> None:
|
||||
@@ -145,5 +160,19 @@ def _query_one(query: dict[str, list[str]], key: str) -> str:
|
||||
return values[0]
|
||||
|
||||
|
||||
def _query_optional(query: dict[str, list[str]], key: str) -> str | None:
|
||||
values = query.get(key)
|
||||
if not values or not values[0]:
|
||||
return None
|
||||
return values[0]
|
||||
|
||||
|
||||
def _int_id(value: str, label: str) -> int:
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError as exc:
|
||||
raise RegistryError(f"invalid {label}: {value}", 400) from exc
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user