77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
|
|
|
|
class ApiKeyCreate(BaseModel):
|
|
"""Schema pour créer une clé API"""
|
|
|
|
name: str = Field(..., min_length=3, max_length=255, description="Nom de la clé")
|
|
description: Optional[str] = Field(None, description="Description de l'usage")
|
|
expires_in_days: Optional[int] = Field(
|
|
None, ge=1, le=3650, description="Expiration en jours (max 10 ans)"
|
|
)
|
|
rate_limit_per_minute: int = Field(
|
|
60, ge=1, le=1000, description="Limite de requêtes par minute"
|
|
)
|
|
allowed_endpoints: Optional[List[str]] = Field(
|
|
None, description="Endpoints autorisés ([] = tous, ['/clients*'] = wildcard)"
|
|
)
|
|
|
|
|
|
class ApiKeyResponse(BaseModel):
|
|
"""Schema de réponse pour une clé API"""
|
|
|
|
id: str
|
|
name: str
|
|
description: Optional[str]
|
|
key_prefix: str
|
|
is_active: bool
|
|
is_expired: bool
|
|
rate_limit_per_minute: int
|
|
allowed_endpoints: Optional[List[str]]
|
|
total_requests: int
|
|
last_used_at: Optional[datetime]
|
|
created_at: datetime
|
|
expires_at: Optional[datetime]
|
|
revoked_at: Optional[datetime]
|
|
created_by: str
|
|
|
|
|
|
class ApiKeyCreatedResponse(ApiKeyResponse):
|
|
"""Schema de réponse après création (inclut la clé en clair)"""
|
|
|
|
api_key: str = Field(
|
|
..., description=" Clé API en clair - à sauvegarder immédiatement"
|
|
)
|
|
|
|
|
|
class ApiKeyList(BaseModel):
|
|
"""Liste de clés API"""
|
|
|
|
total: int
|
|
items: List[ApiKeyResponse]
|
|
|
|
|
|
class SwaggerUserCreate(BaseModel):
|
|
"""Schema pour créer un utilisateur Swagger"""
|
|
|
|
username: str = Field(..., min_length=3, max_length=100)
|
|
password: str = Field(..., min_length=8)
|
|
full_name: Optional[str] = None
|
|
email: Optional[str] = None
|
|
|
|
|
|
class SwaggerUserResponse(BaseModel):
|
|
"""Schema de réponse pour un utilisateur Swagger"""
|
|
|
|
id: str
|
|
username: str
|
|
full_name: Optional[str]
|
|
email: Optional[str]
|
|
is_active: bool
|
|
created_at: datetime
|
|
last_login: Optional[datetime]
|
|
|
|
class Config:
|
|
from_attributes = True
|