Skip to content

Commit

Permalink
Account for effectiveness state when showing passed versions (#704)
Browse files Browse the repository at this point in the history
resolves #702

Signed-off-by: Matthias Büchse <[email protected]>
  • Loading branch information
mbuechse authored Aug 19, 2024
1 parent 4d46088 commit dcb9ddd
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions compliance-monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def __init__(self):
schemes=('argon2', 'bcrypt'),
deprecated='auto',
)
env = Environment()
env.filters.update(
passed=lambda scopedata:
", ".join(key for key, val in scopedata['versions'].items() if val == 1) if scopedata else "",
)
env = Environment() # populate this on startup (final section of this file)
templates_map = {
k: None for k in REQUIRED_TEMPLATES
}
Expand Down Expand Up @@ -378,13 +374,13 @@ def convert_result_rows_to_dict2(rows, scopes_lookup, grace_period_days):
precomputed = scopes_lookup.get(scopeuuid)
if precomputed is None:
continue
validity = precomputed['spec']['versions'][version]['validity']
main_suite = precomputed['versions'][version]['targets']['main']
by_result = main_suite.evaluate(scenario_results, now=now)
missing, failed = by_result[0], by_result[-1]
total_result = -1 if failed else 0 if missing else 1
results[subject][scopeuuid]["versions"][version] = total_result
if total_result == 1:
# FIXME also check that the version is valid
results[subject][scopeuuid]["versions"][version] = {'result': total_result, 'validity': validity}
if total_result == 1 and validity in ('effective', 'warn'):
results[subject][scopeuuid]["result"] = 1
return results

Expand Down Expand Up @@ -515,7 +511,24 @@ async def post_subjects(
conn.commit()


def passed_filter(scopedata):
if not scopedata or not scopedata.get('versions'):
return ""
# sort passed versions into buckets according to validity status
buckets = defaultdict(list)
for vname, val in scopedata['versions'].items():
if val['result'] != 1:
continue
buckets[val['validity']].append(vname)
# only show "warn" versions if no effective ones are passed
passed = buckets['effective'] or [vname + '†' for vname in buckets['warn']]
# append draft versions
passed.extend([vname + '*' for vname in buckets['draft']])
return ", ".join(passed)


if __name__ == "__main__":
env.filters.update(passed=passed_filter)
with mk_conn(settings=settings) as conn:
db_ensure_schema(conn)
import_bootstrap(settings.bootstrap_path, conn=conn)
Expand Down

0 comments on commit dcb9ddd

Please sign in to comment.