mirror of
https://github.com/Rarebuffalo/securelens-backend.git
synced 2026-06-19 07:00:30 +00:00
updated the architecture
This commit is contained in:
42
app/services/scoring.py
Normal file
42
app/services/scoring.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from app.schemas.scan import Issue, LayerStatus
|
||||
|
||||
SEVERITY_WEIGHTS: dict[str, int] = {
|
||||
"Critical": 15,
|
||||
"Warning": 5,
|
||||
"Info": 2,
|
||||
}
|
||||
|
||||
LAYER_NAMES = [
|
||||
"Transport Layer",
|
||||
"SSL/TLS Layer",
|
||||
"Server Config Layer",
|
||||
"Cookie Security",
|
||||
"Exposure Layer",
|
||||
]
|
||||
|
||||
|
||||
def calculate_score(issues: list[Issue]) -> int:
|
||||
score = 100
|
||||
for issue in issues:
|
||||
score -= SEVERITY_WEIGHTS.get(issue.severity, 0)
|
||||
return max(score, 0)
|
||||
|
||||
|
||||
def calculate_layer_statuses(issues: list[Issue]) -> dict[str, LayerStatus]:
|
||||
layers: dict[str, LayerStatus] = {
|
||||
name: LayerStatus(issues=0, status="green") for name in LAYER_NAMES
|
||||
}
|
||||
|
||||
for issue in issues:
|
||||
if issue.layer in layers:
|
||||
layers[issue.layer].issues += 1
|
||||
|
||||
for layer in layers.values():
|
||||
if layer.issues == 0:
|
||||
layer.status = "green"
|
||||
elif layer.issues < 3:
|
||||
layer.status = "yellow"
|
||||
else:
|
||||
layer.status = "red"
|
||||
|
||||
return layers
|
||||
Reference in New Issue
Block a user