Files

50 lines
1.8 KiB
Python
Raw Permalink Normal View History

"""Pydantic schemas for Webhook CRUD."""
from __future__ import annotations
import uuid
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
class WebhookCreate(BaseModel):
"""Schema for creating a new webhook."""
url: str = Field(..., min_length=1, max_length=500, description="Target URL for the webhook")
events: list[str] = Field(..., min_length=1, description="List of event names to subscribe to")
secret: str | None = Field(default=None, max_length=255, description="HMAC secret for payload signing")
is_active: bool = Field(default=True, description="Whether the webhook is active")
retry_count: int = Field(default=3, ge=0, le=10, description="Number of retry attempts on failure")
timeout_seconds: int = Field(default=30, ge=1, le=120, description="Request timeout in seconds")
class WebhookUpdate(BaseModel):
"""Schema for updating an existing webhook."""
url: str | None = Field(default=None, max_length=500)
events: list[str] | None = Field(default=None, min_length=1)
secret: str | None = Field(default=None, max_length=255)
is_active: bool | None = Field(default=None)
retry_count: int | None = Field(default=None, ge=0, le=10)
timeout_seconds: int | None = Field(default=None, ge=1, le=120)
class WebhookResponse(BaseModel):
"""Schema for returning a webhook."""
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
tenant_id: uuid.UUID
url: str
events: list[str]
has_secret: bool = False # Only indicate if a secret is set, never return it
is_active: bool = True
retry_count: int = 3
timeout_seconds: int = 30
created_by: uuid.UUID | None = None
updated_by: uuid.UUID | None = None
created_at: datetime
updated_at: datetime