INNER CODE UNIT · Python
set_retention
caipe-io/ai-platform-engineering · ai_platform_engineering/audit_service/main.py:421
async def set_retention(request: Request, body: Any = Body(...)) -> dict[str, Any]:
store = request.app.state.audit_store
current_settings: Settings = request.app.state.audit_settings
if not isinstance(store, S3AuditStore):
raise HTTPException(
status_code=400,
detail="Retention can only be updated at runtime for the S3 backend. "
"For local disk, set AUDIT_SERVICE_LOCAL_RETENTION_DAYS and restart.",
)
if not isinstance(body, dict) or "days" not in body:
raise HTTPException(status_code=400, detail='body must be {"days": N}')
try:
days = int(body["days"])
except (TypeError, ValueError) as exc:
raise HTTPException(status_code=400, detail="days must be an integer") from exc
if days < 0:
raise HTTPException(status_code=400, detail="days must be >= 0 (use 0 to disable lifecycle rule)")
try: