Spaces:
Paused
Paused
File size: 1,506 Bytes
0d3f7cc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | """Security router."""
from __future__ import annotations
import logging
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
from hermes.agents.orchestrator.agent import OrchestratorAgent
from hermes.api.middleware import sanitize_path
from hermes.core.auth import get_api_key_dependency
logger = logging.getLogger(__name__)
router = APIRouter(dependencies=[Depends(get_api_key_dependency)])
class SecurityScanRequest(BaseModel):
path: str = Field(..., max_length=500, description="File or directory path to scan")
class SecurityResponse(BaseModel):
task_id: str
status: str
title: str
summary: str
findings_count: int
orchestrator = OrchestratorAgent()
@router.post("/security-scan", response_model=SecurityResponse)
async def security_scan(request: SecurityScanRequest) -> SecurityResponse:
try:
path = sanitize_path(request.path, max_length=500)
except ValueError as e:
raise HTTPException(status_code=422, detail=str(e)) from e
try:
report = await orchestrator.execute_security_scan(path)
return SecurityResponse(
task_id=report.id,
status="completed",
title=report.title,
summary=report.summary,
findings_count=len(report.findings),
)
except Exception as e:
logger.error(f"Security scan failed: {e}", exc_info=True)
raise HTTPException(status_code=500, detail="Security scan failed") from e
|