From 30ca3b6a083c65836500f2cd23ea010876d1fe57 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Tue, 22 Nov 2022 16:31:20 +0100 Subject: [PATCH] Revision 16th of November --- createreadmes.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/createreadmes.py b/createreadmes.py index 280f11e..dad36b5 100644 --- a/createreadmes.py +++ b/createreadmes.py @@ -3,7 +3,7 @@ import json import itertools import yaml import jsonschema -from typing import Any +from typing import Any, TypedDict import requests try: from yachalk import chalk @@ -55,13 +55,13 @@ def get_file(slug: str, path: str): def plural(amount: int, name: str, plural: str = 's'): return f"{amount} {name}{plural[:amount^1]}" -from typing import NamedTuple +from typing import TypedDict -class Artifact(NamedTuple): +class Artifact(TypedDict): file: str lines: list[int] -class SecurityRule(NamedTuple): +class SecurityRule(TypedDict): status: str argument: str artifacts: None | list[Artifact] @@ -99,8 +99,11 @@ def check_security_rules(security_rules: dict[Any, Any] | None) -> dict[int, Sec for n in range(1, 19): try: rule = security_rules.get(n, None) - if rule is None: raise jsonschema.ValidationError('Rule {} is not evaluated'.format(n)) + if rule is None: raise jsonschema.ValidationError(f"Rule {n} is not evaluated") jsonschema.validate(rule, rule_schema) + rule: SecurityRule + if rule["status"] == "unknown": + warning(f"Rule {n} is still unknown!") except jsonschema.ValidationError as e: error("Security rule {n}: {msg} at $.{n}.{path}".format(n=n, msg=e.message, path=e.json_path)) warning("Not checking further rules!")