refactor: JSON data column for findings, code snippets captured and displayed
This commit is contained in:
@@ -4,7 +4,7 @@ import datetime
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy import Integer, cast, func, select
|
||||
from sqlalchemy import Integer, cast, func, select, text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from guarddog_nexus.database import get_session
|
||||
@@ -53,10 +53,14 @@ async def _dashboard_data(session: AsyncSession) -> dict:
|
||||
total_findings = await session.scalar(select(func.count(Finding.id)))
|
||||
|
||||
warnings_count = await session.scalar(
|
||||
select(func.count(Finding.id)).where(Finding.severity == "WARNING")
|
||||
select(func.count(Finding.id)).where(
|
||||
func.json_extract(Finding.data, "$.severity") == "WARNING"
|
||||
)
|
||||
)
|
||||
errors_count = await session.scalar(
|
||||
select(func.count(Finding.id)).where(Finding.severity == "ERROR")
|
||||
select(func.count(Finding.id)).where(
|
||||
func.json_extract(Finding.data, "$.severity") == "ERROR"
|
||||
)
|
||||
)
|
||||
|
||||
latest_flagged = (
|
||||
@@ -77,9 +81,12 @@ async def _dashboard_data(session: AsyncSession) -> dict:
|
||||
|
||||
top_rules = (
|
||||
await session.execute(
|
||||
select(Finding.rule, func.count(Finding.id).label("cnt"))
|
||||
.group_by(Finding.rule)
|
||||
.order_by(func.count(Finding.id).desc())
|
||||
select(
|
||||
func.json_extract(Finding.data, "$.rule").label("rule"),
|
||||
func.count(Finding.id).label("cnt"),
|
||||
)
|
||||
.group_by(text("rule"))
|
||||
.order_by(text("cnt DESC"))
|
||||
.limit(10)
|
||||
)
|
||||
).all()
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<strong>{{ f.rule }}</strong>
|
||||
{% if f.location %}<small> @ {{ f.location }}</small>{% endif %}
|
||||
<p>{{ f.message }}</p>
|
||||
{% if f.code %}<pre><code>{{ f.code }}</code></pre>{% endif %}
|
||||
</article>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
<h2>Findings ({{ scan.findings|length }})</h2>
|
||||
{% if scan.findings %}
|
||||
{% for f in scan.findings|sort(attribute='severity', reverse=true) %}
|
||||
<article class="finding-card {{ f.severity }}">
|
||||
<strong class="severity-{{ f.severity }}">[{{ f.severity }}]</strong>
|
||||
<strong>{{ f.rule }}</strong>
|
||||
{% if f.location %}<small> @ {{ f.location }}</small>{% endif %}
|
||||
<p>{{ f.message }}</p>
|
||||
{% for f in scan.findings|sort(attribute='data.severity', reverse=true) %}
|
||||
<article class="finding-card {{ f.data.severity }}">
|
||||
<strong class="severity-{{ f.data.severity }}">[{{ f.data.severity }}]</strong>
|
||||
<strong>{{ f.data.rule }}</strong>
|
||||
{% if f.data.location %}<small> @ {{ f.data.location }}</small>{% endif %}
|
||||
<p>{{ f.data.message }}</p>
|
||||
{% if f.data.code %}<pre><code>{{ f.data.code }}</code></pre>{% endif %}
|
||||
</article>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
|
||||
Reference in New Issue
Block a user