27 lines
763 B
Python
27 lines
763 B
Python
from core.schemas.config import Config, ResolvedConfig
|
|
from core.schemas.results import AuditResults
|
|
from core.schemas.status import AuditSeverity
|
|
|
|
SEVERITY_WEIGHTS = {
|
|
AuditSeverity.LOW: 1,
|
|
AuditSeverity.MEDIUM: 2,
|
|
AuditSeverity.HIGH: 3,
|
|
AuditSeverity.CRITICAL: 4,
|
|
}
|
|
|
|
|
|
def evaluate_exit_code(results: list[AuditResults], config: Config | ResolvedConfig) -> int:
|
|
severity_threshold = SEVERITY_WEIGHTS.get(
|
|
config.allow_failures_below, SEVERITY_WEIGHTS[AuditSeverity.HIGH]
|
|
)
|
|
|
|
threshold_crossed = any(
|
|
SEVERITY_WEIGHTS.get(finding.severity, 1) >= severity_threshold
|
|
for result in results
|
|
for finding in result.findings
|
|
)
|
|
|
|
if threshold_crossed and config.strict_mode:
|
|
return 1
|
|
return 0
|