feat: Enhance Booklooker client with webhook signature verification, idempotency handling, and retry logic
This commit is contained in:
parent
1d8ee1bba6
commit
f2e5774204
6 changed files with 232 additions and 50 deletions
|
|
@ -2,18 +2,21 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
|
||||
from booklooker_client import BooklookerConfig, BooklookerWebhookHelper, SyncBooklookerClient
|
||||
|
||||
|
||||
app = FastAPI(title="Booklooker webhook receiver")
|
||||
helper = BooklookerWebhookHelper()
|
||||
helper = BooklookerWebhookHelper(webhook_secret=os.environ.get("BOOKLOOKER_WEBHOOK_SECRET"))
|
||||
client = SyncBooklookerClient(BooklookerConfig(api_key=os.environ.get("BOOKLOOKER_API_KEY", "REPLACE_ME")))
|
||||
|
||||
|
||||
@app.post("/webhooks/booklooker")
|
||||
async def receive_booklooker_webhook(request: Request) -> dict:
|
||||
raw_body = await request.body()
|
||||
if not helper.validate_request(raw_body, request.headers):
|
||||
raise HTTPException(status_code=401, detail="Invalid webhook signature")
|
||||
payload = await request.json()
|
||||
event = helper.enrich_with_client(payload, client)
|
||||
return {"accepted": True, "event": event.model_dump(mode="json")}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue