refactor: вынос хардкода + LLM-анализ finding'ов
## Часть A: Вынос хардкода
- Новый модуль constants.py — все magic strings, лимиты, severity, ключи
(104 хардкод-значения централизованы)
- Новый модуль queries.py — общие SQL-запросы (build_scan_list_query,
build_package_list_query, get_dashboard_stats)
Убрана дупликация между api/*.py и web/routes.py (~90%)
- config.py: добавлены NLP_ENABLED, nexus_timeout, guarddog_binary,
log_syslog_facility, LLM-переменные
- nexus_client.py: таймауты из конфига, SHA256_CHUNK_SIZE из constants
- scanner.py: error-ключи из constants, GUARDDOG_OUTPUT_FORMAT из constants
- webhooks.py: RELEVANT_WEBHOOK_ACTIONS, METADATA_PATTERNS, ignore-строки
из constants
- logging_setup.py: конфигурируемый syslog facility, APP_PACKAGE из constants
- main.py: APP_NAME, APP_DESCRIPTION, APP_PACKAGE из constants
- models.py: поле report: JSON | None в Finding для LLM-отчётов
- harvester.py: авто-очистка tmpdir через finally; ERROR_MESSAGE_MAX_LENGTH
из constants; PACKAGE_EXTENSIONS вместо SUPPORTED_EXTENSIONS (с .gem)
- api/*.py + web/routes.py: используют build_*_query из queries.py,
константы для лимитов и сортировок
- tests/conftest.py: SEVERITY_WARNING, DEFAULT_ECOSYSTEM из constants
## Часть B: LLM-анализ finding'ов
- llm.py: клиент для OpenAI-совместимых API с промптом security-аналитика
- harvester.py: авто-триггер после flagged scan, сохранение report в БД
- api/findings.py: POST /{id}/analyze — ручной триггер
- web/routes.py: POST /api/v1/findings/{id}/analyze — HTMX-фрагмент
- _llm_report_fragment.html: шаблон фрагмента с вердиктом
- scan_detail.html, package_detail.html: кнопка Analyze with LLM
(htmx-post, spinner, inline-замена на LLM-отчёт)
- style.css: стили для .llm-report .verdict-safe/suspicious/malicious
## Часть C: Тесты
- 50 тестов, все зелёные
- Линтер чистый
- Тесты используют constants где нужно
This commit is contained in:
@@ -373,6 +373,49 @@ th.sortable.active .sort-icon {
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
/* LLM report */
|
||||
.llm-report {
|
||||
margin-top: 0.75rem;
|
||||
padding: 0.6rem 0.8rem;
|
||||
background: var(--pico-color-gray-700);
|
||||
border-radius: 6px;
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.5;
|
||||
border-left: 3px solid var(--pico-color-blue-400);
|
||||
}
|
||||
|
||||
.llm-report strong {
|
||||
color: var(--pico-color-blue-300);
|
||||
}
|
||||
|
||||
.verdict-safe {
|
||||
color: var(--pico-color-green-400);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.verdict-suspicious {
|
||||
color: var(--pico-color-yellow-400);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.verdict-malicious {
|
||||
color: var(--pico-color-red-400);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.llm-actions {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.llm-actions button {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* htmx indicator */
|
||||
.htmx-indicator {
|
||||
display: inline;
|
||||
}
|
||||
.toggle-all-btn {
|
||||
font-size: 0.8rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
Reference in New Issue
Block a user