Replaces LICENSE (GPLv3 -> AGPLv3) and prepends `SPDX-License-Identifier: AGPL-3.0-or-later` to every source file across decnet/, decnet_web/, tests/, scripts/, and tools/. Rationale: closes the GPLv3 ASP loophole so any party operating a modified DECNET as a network service must offer their modified source. Personal copyright (Samuel Paschuan) + inbound=outbound contributions make a future unilateral relicense infeasible. - LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt) - COPYRIGHT: project copyright notice - tools/add_spdx_headers.py: idempotent header injector (shebang- and PEP 263-aware) Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh). No behavior change; comments only.
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Shared helpers for the Phase-3 child-CRUD routes."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import HTTPException
|
|
|
|
from decnet.topology.status import (
|
|
TopologyNotEditable,
|
|
TopologyStatus,
|
|
VersionConflict,
|
|
)
|
|
from decnet.web.db.models.topology import TopologySummary
|
|
from decnet.web.dependencies import repo
|
|
|
|
|
|
async def get_topology_or_404(topology_id: str) -> TopologySummary:
|
|
topo = await repo.get_topology(topology_id)
|
|
if topo is None:
|
|
raise HTTPException(status_code=404, detail="Topology not found")
|
|
return topo
|
|
|
|
|
|
async def assert_pending_or_409(topology_id: str) -> TopologySummary:
|
|
"""Ensure the topology exists and is in ``pending`` state.
|
|
|
|
The repo layer enforces the same rule inside mutation methods, but the
|
|
``add_*`` helpers don't — re-check here so every write route agrees on
|
|
the pre-condition before any side effect.
|
|
"""
|
|
topo = await get_topology_or_404(topology_id)
|
|
if topo.status != TopologyStatus.PENDING:
|
|
raise HTTPException(
|
|
status_code=409,
|
|
detail=(
|
|
f"Topology is {topo.status!r}; free-form child edits are "
|
|
f"pending-only. Use the mutation queue for active topologies."
|
|
),
|
|
)
|
|
return topo
|
|
|
|
|
|
def map_repo_exception(exc: Exception) -> HTTPException:
|
|
"""Translate repo-layer exceptions to HTTP status codes."""
|
|
if isinstance(exc, TopologyNotEditable):
|
|
return HTTPException(status_code=409, detail=str(exc))
|
|
if isinstance(exc, VersionConflict):
|
|
return HTTPException(
|
|
status_code=409,
|
|
detail=f"Version conflict: expected {exc.expected}, current {exc.current}",
|
|
)
|
|
if isinstance(exc, ValueError):
|
|
return HTTPException(status_code=400, detail=str(exc))
|
|
return HTTPException(status_code=500, detail="Internal error")
|