fix(types): T4 — stop spreading TopologySummary as dict; fix heartbeat .get() and scope param
This commit is contained in:
@@ -16,6 +16,7 @@ from __future__ import annotations
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
from collections.abc import MutableMapping
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||||
@@ -38,7 +39,7 @@ class HeartbeatRequest(BaseModel):
|
|||||||
topology: Optional[dict[str, Any]] = None
|
topology: Optional[dict[str, Any]] = None
|
||||||
|
|
||||||
|
|
||||||
def _extract_peer_fingerprint(scope: dict[str, Any]) -> Optional[str]:
|
def _extract_peer_fingerprint(scope: MutableMapping[str, Any]) -> Optional[str]:
|
||||||
"""Pull the peer cert's SHA-256 fingerprint from an ASGI scope.
|
"""Pull the peer cert's SHA-256 fingerprint from an ASGI scope.
|
||||||
|
|
||||||
Tries two extraction paths because uvicorn has historically stashed
|
Tries two extraction paths because uvicorn has historically stashed
|
||||||
@@ -123,7 +124,7 @@ async def _reconcile_topology_report(
|
|||||||
except Exception:
|
except Exception:
|
||||||
log.exception("heartbeat: could not list active topologies")
|
log.exception("heartbeat: could not list active topologies")
|
||||||
return
|
return
|
||||||
mine = [t for t in topos if t.get("target_host_uuid") == host_uuid]
|
mine = [t for t in topos if t.target_host_uuid == host_uuid]
|
||||||
if not mine:
|
if not mine:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -120,4 +120,4 @@ async def api_create_blank_topology(
|
|||||||
row = await repo.get_topology(topology_id)
|
row = await repo.get_topology(topology_id)
|
||||||
if row is None: # pragma: no cover — create then vanish
|
if row is None: # pragma: no cover — create then vanish
|
||||||
raise HTTPException(status_code=500, detail="topology insert vanished")
|
raise HTTPException(status_code=500, detail="topology insert vanished")
|
||||||
return TopologySummary(**row)
|
return row
|
||||||
|
|||||||
@@ -74,4 +74,6 @@ async def api_create_topology(
|
|||||||
) from exc
|
) from exc
|
||||||
raise
|
raise
|
||||||
row = await repo.get_topology(topology_id)
|
row = await repo.get_topology(topology_id)
|
||||||
return TopologySummary(**row)
|
if row is None: # pragma: no cover — create then vanish
|
||||||
|
raise HTTPException(status_code=500, detail="topology insert vanished")
|
||||||
|
return row
|
||||||
|
|||||||
@@ -73,4 +73,4 @@ async def api_deploy_topology(
|
|||||||
)
|
)
|
||||||
|
|
||||||
background.add_task(_run_deploy, topology_id)
|
background.add_task(_run_deploy, topology_id)
|
||||||
return TopologySummary(**topo)
|
return topo
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from typing import Optional
|
|||||||
from fastapi import APIRouter, Depends, Query
|
from fastapi import APIRouter, Depends, Query
|
||||||
|
|
||||||
from decnet.telemetry import traced as _traced
|
from decnet.telemetry import traced as _traced
|
||||||
from decnet.web.db.models import TopologyListResponse, TopologySummary
|
from decnet.web.db.models import TopologyListResponse
|
||||||
from decnet.web.dependencies import repo, require_viewer
|
from decnet.web.dependencies import repo, require_viewer
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -35,5 +35,5 @@ async def api_list_topologies(
|
|||||||
total=total,
|
total=total,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
data=[TopologySummary(**r) for r in rows],
|
data=rows,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -76,4 +76,4 @@ async def api_teardown_topology(
|
|||||||
)
|
)
|
||||||
|
|
||||||
background.add_task(_run_teardown, topology_id)
|
background.add_task(_run_teardown, topology_id)
|
||||||
return TopologySummary(**topo)
|
return topo
|
||||||
|
|||||||
Reference in New Issue
Block a user