38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, Field, field_validator
|
|
|
|
from app.core.config import settings
|
|
|
|
|
|
class SecretCreate(BaseModel):
|
|
"""Schema for creating a new secret."""
|
|
content: str = Field(..., description="The secret content to store")
|
|
ttl_hours: Optional[int] = Field(
|
|
default=settings.DEFAULT_SECRET_TTL_HOURS,
|
|
description="Time-to-live in hours"
|
|
)
|
|
|
|
@field_validator("ttl_hours")
|
|
def validate_ttl(cls, ttl_hours: int) -> int:
|
|
"""Validate TTL doesn't exceed maximum."""
|
|
if ttl_hours <= 0:
|
|
raise ValueError("TTL must be greater than 0")
|
|
|
|
if ttl_hours > settings.MAX_SECRET_TTL_HOURS:
|
|
return settings.MAX_SECRET_TTL_HOURS
|
|
|
|
return ttl_hours
|
|
|
|
|
|
class SecretResponse(BaseModel):
|
|
"""Schema for response after creating a secret."""
|
|
token: str = Field(..., description="The token to access the secret")
|
|
expires_at: datetime = Field(..., description="When the secret expires")
|
|
message: str = Field("Secret stored successfully", description="Status message")
|
|
|
|
|
|
class SecretRetrieved(BaseModel):
|
|
"""Schema for retrieved secret."""
|
|
content: str = Field(..., description="The secret content")
|
|
message: str = Field("Secret retrieved successfully", description="Status message") |