feat: Enhance Booklooker client with webhook signature verification, idempotency handling, and retry logic

This commit is contained in:
claudi 2026-04-16 14:58:18 +02:00
parent 1d8ee1bba6
commit f2e5774204
6 changed files with 232 additions and 50 deletions

View file

@ -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")}