feat(api): phase 3 step 2 — topology read endpoints (list/get/status/catalog)
GET /api/v1/topologies — paginated list with status filter. Extends
repo.list_topologies() to accept limit/offset and adds count_topologies()
for the total envelope field.
GET /api/v1/topologies/{id} — hydrated TopologyDetail; 404 if missing.
GET /api/v1/topologies/{id}/status-events — audit trail, limit-capped.
Catalog helpers for the phase-4 canvas UI:
* GET /topologies/services — full service catalog.
* GET /topologies/next-subnet?base=172.20 — wraps SubnetAllocator against
reserved_subnets across non-torn-down topologies.
* GET /topologies/{id}/lans/{lan_id}/next-ip — IPAllocator pre-seeded
with existing decky IPs in that LAN.
All read routes are viewer-or-admin. Sub-routers are included in an
order that keeps literal catalog paths (/services, /next-subnet) from
being shadowed by the /{topology_id} trie branch.
This commit is contained in:
38
decnet/web/router/topology/api_list_topologies.py
Normal file
38
decnet/web/router/topology/api_list_topologies.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""GET /topologies — paginated list of MazeNET topologies."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
|
||||
from decnet.telemetry import traced as _traced
|
||||
from decnet.web.db.models import TopologyListResponse, TopologySummary
|
||||
from decnet.web.dependencies import repo, require_viewer
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/",
|
||||
tags=["MazeNET Topologies"],
|
||||
response_model=TopologyListResponse,
|
||||
responses={
|
||||
401: {"description": "Missing or invalid credentials"},
|
||||
403: {"description": "Insufficient permissions"},
|
||||
},
|
||||
)
|
||||
@_traced("api.topology.list")
|
||||
async def api_list_topologies(
|
||||
status: Optional[str] = Query(default=None, description="Filter by topology status"),
|
||||
limit: int = Query(default=50, ge=1, le=500),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
_viewer: dict = Depends(require_viewer),
|
||||
) -> TopologyListResponse:
|
||||
total = await repo.count_topologies(status=status)
|
||||
rows = await repo.list_topologies(status=status, limit=limit, offset=offset)
|
||||
return TopologyListResponse(
|
||||
total=total,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
data=[TopologySummary(**r) for r in rows],
|
||||
)
|
||||
Reference in New Issue
Block a user