From 79989036146bc2d977263620eff6f58f26e851d5 Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 1 Nov 2024 11:36:22 +0000 Subject: [PATCH] make severity mapping constantly --- fixlib/fixlib/baseresources.py | 9 +++++++++ plugins/azure/fix_plugin_azure/resource/security.py | 11 ++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fixlib/fixlib/baseresources.py b/fixlib/fixlib/baseresources.py index df3038f0bd..0032907e1d 100644 --- a/fixlib/fixlib/baseresources.py +++ b/fixlib/fixlib/baseresources.py @@ -263,6 +263,15 @@ class Finding: details: Optional[Json] = None +SEVERITY_MAPPING = { + "INFORMATIONAL": Severity.info, + "LOW": Severity.low, + "MEDIUM": Severity.medium, + "HIGH": Severity.high, + "CRITICAL": Severity.critical, +} + + @define(slots=True) class Assessment: # The provider of the security assessment diff --git a/plugins/azure/fix_plugin_azure/resource/security.py b/plugins/azure/fix_plugin_azure/resource/security.py index 20f139e167..8aeacf5a37 100644 --- a/plugins/azure/fix_plugin_azure/resource/security.py +++ b/plugins/azure/fix_plugin_azure/resource/security.py @@ -7,7 +7,7 @@ from fix_plugin_azure.azure_client import AzureResourceSpec from fix_plugin_azure.resource.base import MicrosoftResource, AzureSystemData, GraphBuilder -from fixlib.baseresources import Finding, ModelReference, PhantomBaseResource, Severity +from fixlib.baseresources import SEVERITY_MAPPING, Finding, PhantomBaseResource, Severity from fixlib.json_bender import Bender, S, Bend, ForallBend, F from fixlib.types import Json @@ -126,17 +126,10 @@ class AzureSecurityAssessment(MicrosoftResource, PhantomBaseResource): subscription_issue: Optional[bool] = field(default=False, metadata={'description': 'Indicates if the assessment is a subscription issue'}) # fmt: skip def parse_finding(self, source: Json) -> Finding: - severity_mapping = { - "INFORMATIONAL": Severity.info, - "LOW": Severity.low, - "MEDIUM": Severity.medium, - "HIGH": Severity.high, - "CRITICAL": Severity.critical, - } remediation = finding_title = self.safe_name properties = source.get("properties") or {} if metadata := properties.get("metadata", {}): - finding_severity = severity_mapping.get(metadata.get("severity", "").upper(), Severity.medium) + finding_severity = SEVERITY_MAPPING.get(metadata.get("severity", "").upper(), Severity.medium) else: finding_severity = Severity.medium if status := self.assessment_status: