Files
DECNET/decnet/web/router/webhooks/api_test_webhook.py
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
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.
2026-05-22 21:04:16 -04:00

62 lines
1.8 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""POST /webhooks/{uuid}/test — fire a synthetic ping to verify plumbing.
This hits the same delivery path the worker uses, so a 200 here proves
the destination URL, HMAC secret, and network egress all work without
waiting for a real bus event.
"""
from __future__ import annotations
from datetime import datetime, timezone
from uuid import uuid4
from fastapi import APIRouter, Depends, HTTPException
from decnet.logging import get_logger
from decnet.telemetry import traced as _traced
from decnet.web.db.models import WebhookTestResponse
from decnet.web.dependencies import repo, require_admin
from decnet.webhook.client import deliver, SyntheticEvent
log = get_logger("api.webhooks.test")
router = APIRouter()
@router.post(
"/{uuid}/test",
tags=["Webhooks"],
response_model=WebhookTestResponse,
responses={
404: {"description": "Webhook not found"},
},
)
@_traced("api.webhook.test")
async def api_test_webhook(
uuid: str,
admin: dict = Depends(require_admin),
) -> WebhookTestResponse:
sub = await repo.get_webhook_subscription(uuid)
if not sub:
raise HTTPException(status_code=404, detail="Webhook not found")
event = SyntheticEvent(
topic="test.ping",
type="test",
ts=datetime.now(timezone.utc).isoformat(),
id=str(uuid4()),
payload={
"message": "Synthetic test event from DECNET",
"triggered_by": admin.get("username", "unknown"),
},
)
# Single attempt — no retries on manual tests. The operator wants a
# fast signal about the current state of the receiver, not a
# retry-and-wait behavior.
result = await deliver(sub, event, retry_schedule=[])
return WebhookTestResponse(
delivered=result.ok,
status_code=result.status_code,
error=result.error,
)