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.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""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],
|
|
)
|