Skip to content

Commit 97f0fa9

Browse files
committed
make sure the cve enrichment skeleton works
1 parent 9862e48 commit 97f0fa9

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

contentctl/enrichments/cve_enrichment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def getCveEnrichment(config:validate, timeout_seconds:int=10, force_disable_enri
5555
return CveEnrichment(use_enrichment=False, cve_api_obj=None)
5656

5757

58-
def enrich_cve(self, cve_id:str, raise_exception_on_failure:bool=True)->Union[CveEnrichmentObj,None]:
58+
def enrich_cve(self, cve_id:str, raise_exception_on_failure:bool=True)->CveEnrichmentObj:
5959

6060
if not self.use_enrichment:
61-
CveEnrichmentObj(id=cve_id,cvss=Decimal(5.0),summary="SUMMARY NOT AVAILABLE! ONLY THE LINK WILL BE USED AT THIS TIME")
61+
return CveEnrichmentObj(id=cve_id,cvss=Decimal(5.0),summary="SUMMARY NOT AVAILABLE! ONLY THE LINK WILL BE USED AT THIS TIME")
6262
else:
6363
print("WARNING - Dynamic enrichment not supported at this time.")
64-
CveEnrichmentObj(id=cve_id,cvss=Decimal(5.0),summary="SUMMARY NOT AVAILABLE! ONLY THE LINK WILL BE USED AT THIS TIME")
64+
return CveEnrichmentObj(id=cve_id,cvss=Decimal(5.0),summary="SUMMARY NOT AVAILABLE! ONLY THE LINK WILL BE USED AT THIS TIME")
6565
# Depending on needs, we may add dynamic enrichment functionality back to the tool

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def mappings(self)->dict[str, List[str]]:
146146
cve_enrichment: list[CveEnrichmentObj] = Field([], validate_default=True)
147147

148148
@model_validator(mode="after")
149-
def cve_enrichment_func(self, info:ValidationInfo)->Detection_Abstract:
149+
def cve_enrichment_func(self, info:ValidationInfo):
150150
if len(self.cve_enrichment) > 0:
151151
raise ValueError(f"Error, field 'cve_enrichment' should be empty and "
152152
f"dynamically populated at runtime. Instead, this field contained: {self.cve_enrichment}")
@@ -155,20 +155,15 @@ def cve_enrichment_func(self, info:ValidationInfo)->Detection_Abstract:
155155
if output_dto is None:
156156
raise ValueError("Context not provided to detection model post validator")
157157

158-
if output_dto.cve_enrichment.use_enrichment is False:
159-
return self
160158

161159
enriched_cves:list[CveEnrichmentObj] = []
160+
162161
for cve_id in self.tags.cve:
163162
try:
164-
enrichment = output_dto.cve_enrichment.enrich_cve(cve_id, raise_exception_on_failure=False)
165-
if enrichment is None:
166-
print(f"WARNING: Failed to find cve_id '{cve_id}'")
167-
else:
168-
enriched_cves.append(enrichment)
163+
enriched_cves.append(output_dto.cve_enrichment.enrich_cve(cve_id, raise_exception_on_failure=False))
169164
except Exception as e:
170165
raise ValueError(f"{e}")
171-
166+
self.cve_enrichment = enriched_cves
172167
return self
173168

174169

0 commit comments

Comments
 (0)