Added rule icons
This commit is contained in:
parent
b4f5e3ebd4
commit
62c96fcbf6
@ -4,7 +4,7 @@ import json
|
|||||||
import itertools
|
import itertools
|
||||||
import yaml
|
import yaml
|
||||||
import jsonschema
|
import jsonschema
|
||||||
from typing import Any, List, NotRequired, Optional, TypedDict
|
from typing import Any, Dict, List, Literal, NotRequired, Optional, TypedDict
|
||||||
import requests
|
import requests
|
||||||
try:
|
try:
|
||||||
from yachalk import chalk
|
from yachalk import chalk
|
||||||
@ -220,8 +220,10 @@ class Artifact(TypedDict):
|
|||||||
lines: NotRequired[list[int]]
|
lines: NotRequired[list[int]]
|
||||||
repository: NotRequired[str]
|
repository: NotRequired[str]
|
||||||
|
|
||||||
|
RuleStatus = Literal["disregarded", "observed", "not applicable", "unknown"]
|
||||||
|
|
||||||
class SecurityRule(TypedDict):
|
class SecurityRule(TypedDict):
|
||||||
status: str
|
status: RuleStatus
|
||||||
argument: str | list[str]
|
argument: str | list[str]
|
||||||
artifacts: NotRequired[list[Artifact]]
|
artifacts: NotRequired[list[Artifact]]
|
||||||
|
|
||||||
@ -322,7 +324,7 @@ def rule_to_string(info: ModelInformation, id: int, rule: SecurityRule | None):
|
|||||||
return ""
|
return ""
|
||||||
argument = rule['argument']
|
argument = rule['argument']
|
||||||
argument = argument if isinstance(argument, str) else "".join(f"\n1. {arg}" for arg in argument)
|
argument = argument if isinstance(argument, str) else "".join(f"\n1. {arg}" for arg in argument)
|
||||||
text = f"""#### Rule {id}: {rule_names[id]}
|
text = f"""#### Rule {id}: {rule_names[id]} {{#rule{id:02}}}
|
||||||
|
|
||||||
This rule is {rule['status']}: {argument}"""
|
This rule is {rule['status']}: {argument}"""
|
||||||
artifacts = rule.get("artifacts", [])
|
artifacts = rule.get("artifacts", [])
|
||||||
@ -334,8 +336,18 @@ Artifacts:
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
def write_security_rules(info: ModelInformation, security_rules: dict[int, SecurityRule]):
|
def write_security_rules(info: ModelInformation, security_rules: dict[int, SecurityRule]):
|
||||||
|
icons: Dict[RuleStatus | str, str] = {
|
||||||
|
'disregarded': '<i class="fa fa-exclamation-circle" style="color: #d72b28;"></i>',
|
||||||
|
'observed': '<i class="fa fa-check-square-o" style="color: #6be16d;"></i>',
|
||||||
|
'not applicable': '<i class="fa fa-info-circle" style="color: #31708;"></i>',
|
||||||
|
'unknown': '<i class="fa fa-warning" style="color: #bfc600;"></i>',
|
||||||
|
}
|
||||||
return f"""## Security Rules
|
return f"""## Security Rules
|
||||||
|
|
||||||
|
{" | ".join(f"R{i}" for i in range(1, 19))}
|
||||||
|
{" | ".join("--" for _ in range(1, 19))}
|
||||||
|
{" | ".join(f'<a href="#rule{i:02}">{icons[security_rules.get(i, {"status": "unknown"})["status"]]}</a>' for i in range(1, 19))}
|
||||||
|
|
||||||
### Authentication / Authorization
|
### Authentication / Authorization
|
||||||
|
|
||||||
{(chr(10)*2).join(rule_to_string(info, i, security_rules.get(i)) for i in range(1, 7))}
|
{(chr(10)*2).join(rule_to_string(info, i, security_rules.get(i)) for i in range(1, 7))}
|
||||||
|
Loading…
Reference in New Issue
Block a user