Skip to content

Commit f5bea85

Browse files
committed
fine tuning.
1 parent f31a6e7 commit f5bea85

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

β€Žcompliance-monitor/monitor.pyβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(self):
8484
ROLES = {'read_any': 1, 'append_any': 2, 'admin': 4, 'approve': 8}
8585
# number of days that expired results will be considered in lieu of more recent, but unapproved ones
8686
GRACE_PERIOD_DAYS = 7
87+
HISTORY_LIMIT = 500
8788
# separator between signature and report data; use something like
8889
# ssh-keygen \
8990
# -Y sign -f ~/.ssh/id_ed25519 -n report myreport.yaml
@@ -719,10 +720,10 @@ async def get_history(
719720
scopes = get_scopes()
720721
scope_name = scopes[scopeuuid]['name'] if scopeuuid in scopes else scopeuuid
721722
with conn.cursor() as cur:
722-
history = db_get_report_history(cur, subject, scopeuuid)
723+
history = db_get_report_history(cur, subject, scopeuuid, limit=HISTORY_LIMIT)
723724
return render_view(
724725
VIEW_HISTORY, view_type, history=history, subject=subject, scope_name=scope_name,
725-
base_url=settings.base_url, title=f'Compliance history for {subject}',
726+
history_limit=HISTORY_LIMIT, base_url=settings.base_url, title=f'πŸ“œ Compliance history for {subject}',
726727
)
727728

728729

β€Žcompliance-monitor/sql.pyβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def db_get_recent_results2(cur: cursor, approved, limit, skip, max_age_days=None
419419
return [{col: val for col, val in zip(columns, row)} for row in cur.fetchall()]
420420

421421

422-
def db_get_report_history(cur: cursor, subject, scopeuuid):
422+
def db_get_report_history(cur: cursor, subject, scopeuuid, limit=500):
423423
"""list all past reports for a subject/scope, newest first, with pass/fail/abort counts"""
424424
cur.execute('''
425425
SELECT report.reportuuid, report.checked_at,
@@ -431,8 +431,9 @@ def db_get_report_history(cur: cursor, subject, scopeuuid):
431431
WHERE report.subject = %(subject)s
432432
AND result2.scopeuuid = %(scopeuuid)s
433433
GROUP BY report.reportuuid, report.checked_at
434-
ORDER BY report.checked_at DESC;
435-
''', {"subject": subject, "scopeuuid": scopeuuid})
434+
ORDER BY report.checked_at DESC
435+
LIMIT %(limit)s;
436+
''', {"subject": subject, "scopeuuid": scopeuuid, "limit": limit})
436437
columns = ('reportuuid', 'checked_at', 'pass_count', 'fail_count', 'abort_count')
437438
return [{col: val for col, val in zip(columns, row)} for row in cur.fetchall()]
438439

β€Žcompliance-monitor/templates/details.md.j2β€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Jump to
2222
## {{ subject }}: {{ scope_result.name }}
2323

2424
- [spec overview]({{ scope_url(scopeuuid) }})
25-
- [compliance history]({{ history_url(subject, scopeuuid) }})
25+
- [πŸ“œ compliance history]({{ history_url(subject, scopeuuid) }})
2626

2727
{% if not scope_result.relevant -%}
2828

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
## Compliance history: {{ subject }} β€” {{ scope_name }}
1+
## πŸ“œ Compliance history: {{ subject }} β€” {{ scope_name }}
22

33
{% if history %}
44
| Date | PASS | FAIL | ABORT | Report |
55
|---|---|---|---|---|
66
{% for entry in history -%}
77
| {{ entry.checked_at | short_isodate }} | {{ entry.pass_count }} | {{ entry.fail_count }} | {{ entry.abort_count }} | [view]({{ report_url(entry.reportuuid) }}) |
88
{% endfor %}
9+
{% if history | length == history_limit %}
10+
_Showing the most recent {{ history_limit }} reports. Older entries are not displayed._
11+
{% endif %}
912
{% else %}
1013
No history available.
1114
{% endif %}

β€Žcompliance-monitor/templates/report.md.j2β€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- uuid: [{{ report.run.uuid }}]({{ report_url(report.run.uuid, download=True) }})
44
- subject: {{ report.subject }}
55
- scope: [{{ report.spec.name }}]({{ scope_url(report.spec.uuid) }})
6+
- [πŸ“œ compliance history]({{ history_url(report.subject, report.spec.uuid) }})
67
- checked at: {{ report.checked_at }}
78
- variable assignment: {% set comma = joiner(", ") %}{% for key, value in report.run.assignment.items() -%}{{comma()}}`{{ key }}`=`{{ value }}`{% endfor %}
89

0 commit comments

Comments
Β (0)