Revision 16th of November

This commit is contained in:
Michael Chen 2022-11-22 16:31:20 +01:00
parent 7b06820170
commit 30ca3b6a08
Signed by: cnml
GPG Key ID: 5845BF3F82D5F629

View File

@ -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!")