feat: фаза 3 — i18n RU/EN, /metrics, AI disclaimer, initiator+IP, LLM очередь
3.3 i18n: модуль с RU/EN словарями, LangMiddleware (cookie+query),
Jinja-фильтр t(), переключатель EN/RU в nav, перевод ключевых
строк интерфейса
3.5 /metrics: Prometheus-совместимый endpoint (scans_total,
scans_flagged, findings_total, by_status, by_ecosystem,
last_scan_timestamp)
3.2 AI disclaimer: сноска под каждым LLM-вердиктом (.llm-disclaimer)
3.4 LLM очередь: asyncio.Semaphore(LLM_MAX_CONCURRENT_ANALYSES)
3.1 initiator + source_ip: поля в Scan, захват из webhook payload,
показ в scan_detail + API
3.6 UI: убран stat-minibar и heatmap с дашборда
This commit is contained in:
@@ -4,20 +4,44 @@ import os
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from guarddog_nexus.config import config
|
||||
from guarddog_nexus.constants import APP_DESCRIPTION, APP_NAME, APP_PACKAGE, STATIC_MOUNT_PATH
|
||||
from guarddog_nexus.db.engine import init_db
|
||||
from guarddog_nexus.i18n import DEFAULT_LANG, LANGUAGES
|
||||
from guarddog_nexus.logging_setup import log
|
||||
from guarddog_nexus.routes import api_findings, api_packages, api_scans
|
||||
from guarddog_nexus.routes.metrics import router as metrics_router
|
||||
from guarddog_nexus.routes.web import router as web_router
|
||||
from guarddog_nexus.routes.webhooks import router as webhook_router
|
||||
|
||||
STATIC_DIR = os.path.join(os.path.dirname(__file__), "web", "static")
|
||||
|
||||
|
||||
class LangMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
# Cookie takes priority, then query param, then default
|
||||
cookie_lang = request.cookies.get("lang")
|
||||
query_lang = request.query_params.get("lang")
|
||||
|
||||
if query_lang and query_lang in LANGUAGES and query_lang != cookie_lang:
|
||||
lang = query_lang
|
||||
elif cookie_lang and cookie_lang in LANGUAGES:
|
||||
lang = cookie_lang
|
||||
else:
|
||||
lang = DEFAULT_LANG
|
||||
|
||||
request.state.lang = lang
|
||||
response = await call_next(request)
|
||||
|
||||
if query_lang and query_lang in LANGUAGES:
|
||||
response.set_cookie("lang", query_lang, max_age=365 * 24 * 3600, httponly=True)
|
||||
return response
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
await init_db()
|
||||
@@ -32,8 +56,10 @@ app = FastAPI(
|
||||
description=APP_DESCRIPTION,
|
||||
lifespan=lifespan,
|
||||
)
|
||||
app.add_middleware(LangMiddleware)
|
||||
|
||||
app.include_router(webhook_router)
|
||||
app.include_router(metrics_router)
|
||||
app.include_router(api_scans.router)
|
||||
app.include_router(api_packages.router)
|
||||
app.include_router(api_findings.router)
|
||||
|
||||
Reference in New Issue
Block a user