Spaces:
Paused
Paused
| """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() | |
| 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 | |