FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
42 lines
921 B
Python
42 lines
921 B
Python
from __future__ import annotations
|
|
|
|
import ipaddress
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
|
|
|
|
|
class UnbanRequestPayload(BaseModel):
|
|
message: str | None = Field(default=None, max_length=2000)
|
|
|
|
|
|
class IpBanResponse(BaseModel):
|
|
ip_address: str
|
|
banned_at: datetime
|
|
reason: str
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class UnbanRequestResponse(BaseModel):
|
|
id: uuid.UUID
|
|
ip_address: str
|
|
message: str | None
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class BanIpRequest(BaseModel):
|
|
ip_address: str
|
|
|
|
@field_validator("ip_address")
|
|
@classmethod
|
|
def _validate_ip(cls, value: str) -> str:
|
|
try:
|
|
ipaddress.ip_address(value.strip())
|
|
except ValueError as exc:
|
|
raise ValueError("Enter a valid IPv4 or IPv6 address.") from exc
|
|
return value.strip()
|