Initial commit: Pixel AI comic/video creation platform
- FastAPI backend with SQLModel, Alembic migrations, AgentScope agents - Next.js 15 frontend with React 19, Tailwind, Zustand, React Flow - Multi-provider AI system (DashScope, Kling, MiniMax, Volcengine, OpenAI, etc.) - All HTTP clients migrated from sync requests to async httpx - Admin-managed API keys via environment variables - SSRF vulnerability fixed in ensure_url()
This commit is contained in:
79
backend/src/api/config/validation.py
Normal file
79
backend/src/api/config/validation.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""Configuration validation endpoints."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from typing import Dict, Any
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from src.models.schemas import ResponseModel
|
||||
from src.utils.errors import AppException, ErrorCode
|
||||
from src.services.provider.validation import ConfigValidator, validate_all_configs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/config/validate", response_model=ResponseModel)
|
||||
async def validate_configurations():
|
||||
"""Validate all service configurations."""
|
||||
try:
|
||||
report = validate_all_configs()
|
||||
return ResponseModel(data=report)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to validate configurations: {e}")
|
||||
raise AppException(
|
||||
message=str(e),
|
||||
code=ErrorCode.INTERNAL_ERROR,
|
||||
status_code=500
|
||||
)
|
||||
|
||||
|
||||
@router.post("/config/validate/service", response_model=ResponseModel)
|
||||
async def validate_service_configuration(config: Dict[str, Any]):
|
||||
"""Validate a single service configuration."""
|
||||
try:
|
||||
is_valid, errors = ConfigValidator.validate_config_deep(config)
|
||||
return ResponseModel(data={
|
||||
"valid": is_valid,
|
||||
"errors": errors,
|
||||
"config": config
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to validate service configuration: {e}")
|
||||
raise AppException(
|
||||
message=str(e),
|
||||
code=ErrorCode.INTERNAL_ERROR,
|
||||
status_code=500
|
||||
)
|
||||
|
||||
|
||||
@router.get("/config/validate/file/{filename}", response_model=ResponseModel)
|
||||
async def validate_config_file(filename: str):
|
||||
"""Validate a specific configuration file."""
|
||||
try:
|
||||
src_dir = os.path.dirname(os.path.dirname(__file__))
|
||||
config_path = os.path.join(src_dir, "config", "services", filename)
|
||||
|
||||
if not os.path.exists(config_path):
|
||||
raise AppException(
|
||||
message=f"Configuration file not found: {filename}",
|
||||
code=ErrorCode.NOT_FOUND,
|
||||
status_code=404
|
||||
)
|
||||
|
||||
is_valid, errors = ConfigValidator.validate_config_file(config_path)
|
||||
return ResponseModel(data={
|
||||
"filename": filename,
|
||||
"valid": is_valid,
|
||||
"errors": errors
|
||||
})
|
||||
except AppException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to validate config file: {e}")
|
||||
raise AppException(
|
||||
message=str(e),
|
||||
code=ErrorCode.INTERNAL_ERROR,
|
||||
status_code=500
|
||||
)
|
||||
Reference in New Issue
Block a user