- Implement tests for database generator to ensure proper session handling. - Create tests for EXIF extraction and conversion functions. - Add tests for image-related endpoints, ensuring proper data retrieval and isolation between clients. - Develop tests for OCR functionality, including language detection and text extraction. - Introduce tests for the image processing pipeline, covering success and failure scenarios. - Validate rate limiting functionality and ensure independent counters for different clients. - Implement scraper tests to verify HTML content fetching and error handling. - Add unit tests for various services, including storage and filename generation. - Establish worker entry point for ARQ to handle background image processing tasks.
68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
"""
|
|
Schémas Pydantic — authentification et gestion des clients API
|
|
"""
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
from app.models.client import ClientPlan
|
|
|
|
|
|
# ─────────────────────────────────────────────────────────────
|
|
# Requêtes
|
|
# ─────────────────────────────────────────────────────────────
|
|
|
|
class ClientCreate(BaseModel):
|
|
"""Créer un nouveau client API."""
|
|
name: str = Field(..., min_length=1, max_length=256, description="Nom de l'application cliente")
|
|
scopes: List[str] = Field(
|
|
default=["images:read", "images:write"],
|
|
description="Permissions accordées",
|
|
)
|
|
plan: ClientPlan = Field(default=ClientPlan.FREE, description="Plan tarifaire")
|
|
|
|
|
|
class ClientUpdate(BaseModel):
|
|
"""Modifier un client API existant."""
|
|
name: Optional[str] = Field(None, min_length=1, max_length=256)
|
|
scopes: Optional[List[str]] = None
|
|
plan: Optional[ClientPlan] = None
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
# ─────────────────────────────────────────────────────────────
|
|
# Réponses
|
|
# ─────────────────────────────────────────────────────────────
|
|
|
|
class ClientResponse(BaseModel):
|
|
"""Réponse de base pour un client API."""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: str
|
|
name: str
|
|
scopes: List[str]
|
|
plan: ClientPlan
|
|
is_active: bool
|
|
created_at: Optional[datetime] = None
|
|
updated_at: Optional[datetime] = None
|
|
|
|
|
|
class ClientCreateResponse(ClientResponse):
|
|
"""
|
|
Réponse après création d'un client.
|
|
La clé API est retournée EN CLAIR une seule fois.
|
|
"""
|
|
api_key: str = Field(
|
|
...,
|
|
description="Clé API en clair — stockez-la, elle ne sera plus jamais affichée",
|
|
)
|
|
|
|
|
|
class KeyRotateResponse(BaseModel):
|
|
"""Réponse après rotation de la clé API."""
|
|
id: str
|
|
api_key: str = Field(
|
|
...,
|
|
description="Nouvelle clé API en clair — stockez-la, elle ne sera plus jamais affichée",
|
|
)
|
|
message: str = "Clé API régénérée avec succès — l'ancienne clé est désormais invalide"
|