50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
|
|
import logging
|
||
|
|
import httpx
|
||
|
|
from app.core.config import settings
|
||
|
|
from app.schemas.qa_report import QARawResults, RuntimeOutput
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
async_client = httpx.AsyncClient(verify=False)
|
||
|
|
|
||
|
|
async def run_project_qa(repo_name: str) -> QARawResults:
|
||
|
|
"""
|
||
|
|
Sollicite l'API du conteneur persistant arc-sandbox pour effectuer
|
||
|
|
une analyse de qualité et sécurité statique (Semgrep).
|
||
|
|
"""
|
||
|
|
sandbox_url = f"http://arc-sandbox:8004/scan/{repo_name}"
|
||
|
|
logger.info(f"[QA Client] Envoi de la requête de scan à la sandbox : {sandbox_url}")
|
||
|
|
|
||
|
|
try:
|
||
|
|
response = await async_client.post(sandbox_url, timeout=120.0)
|
||
|
|
|
||
|
|
if response.status_code == 200:
|
||
|
|
data = response.json()
|
||
|
|
return QARawResults.model_validate(data.get("results"))
|
||
|
|
else:
|
||
|
|
logger.error(f"[QA Client] Erreur de la Sandbox (Status {response.status_code}): {response.text}")
|
||
|
|
return QARawResults(
|
||
|
|
is_executable=False,
|
||
|
|
runtime=RuntimeOutput(
|
||
|
|
exit_code=response.status_code,
|
||
|
|
stdout="",
|
||
|
|
stderr=f"Erreur HTTP Sandbox: {response.text}",
|
||
|
|
duration_seconds=0,
|
||
|
|
timeout_triggered=False
|
||
|
|
),
|
||
|
|
issues=[]
|
||
|
|
)
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
logger.error(f"[QA Client] Impossible de joindre l'API de la Sandbox : {str(e)}")
|
||
|
|
return QARawResults(
|
||
|
|
is_executable=False,
|
||
|
|
runtime=RuntimeOutput(
|
||
|
|
exit_code=-1,
|
||
|
|
stdout="",
|
||
|
|
stderr=f"Exception de connexion QA Client: {str(e)}",
|
||
|
|
duration_seconds=0,
|
||
|
|
timeout_triggered=False
|
||
|
|
),
|
||
|
|
issues=[]
|
||
|
|
)
|