Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /nfraxlab_svc-infra /src /svc_infra /webhooks /router.py
| from __future__ import annotations | |
| from typing import Any | |
| from fastapi import APIRouter, Depends, HTTPException | |
| from svc_infra.db.outbox import InMemoryOutboxStore, OutboxStore | |
| from .service import InMemoryWebhookSubscriptions, WebhookService | |
| router = APIRouter(prefix="/_webhooks", tags=["webhooks"]) | |
| def get_outbox() -> OutboxStore: | |
| # For now expose an in-memory default. Apps can override via DI. | |
| # In production, provide a proper store through dependency override. | |
| return InMemoryOutboxStore() | |
| def get_subs() -> InMemoryWebhookSubscriptions: | |
| return InMemoryWebhookSubscriptions() | |
| def get_service( | |
| outbox: OutboxStore = Depends(get_outbox), | |
| subs: InMemoryWebhookSubscriptions = Depends(get_subs), | |
| ) -> WebhookService: | |
| return WebhookService(outbox=outbox, subs=subs) | |
| def add_subscription( | |
| body: dict[str, Any], | |
| subs: InMemoryWebhookSubscriptions = Depends(get_subs), | |
| ): | |
| topic = body.get("topic") | |
| url = body.get("url") | |
| secret = body.get("secret") | |
| if not topic or not url or not secret: | |
| raise HTTPException(status_code=400, detail="Missing topic/url/secret") | |
| subs.add(topic, url, secret) | |
| return {"ok": True} | |
| def test_fire( | |
| body: dict[str, Any], | |
| svc: WebhookService = Depends(get_service), | |
| ): | |
| topic = body.get("topic") | |
| payload = body.get("payload") or {} | |
| if not topic: | |
| raise HTTPException(status_code=400, detail="Missing topic") | |
| outbox_id = svc.publish(topic, payload) | |
| return {"ok": True, "outbox_id": outbox_id} | |
Xet Storage Details
- Size:
- 1.59 kB
- Xet hash:
- c95f30198e479bd3de2493c3dd6142ac59d300fda343e2d0a3fd12ed972166f2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.