Skip to content

Commit ab10a28

Browse files
committed
Change search typing checks which
are no longer required
1 parent 4e862d3 commit ab10a28

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Detection_Abstract(SecurityContentObject):
5858

5959
@field_validator("search", mode="before")
6060
@classmethod
61-
def validate_presence_of_filter_macro(cls, value:Union[str, dict[str,Any]], info:ValidationInfo)->Union[str, dict[str,Any]]:
61+
def validate_presence_of_filter_macro(cls, value:str, info:ValidationInfo)->str:
6262
"""
6363
Validates that, if required to be present, the filter macro is present with the proper name.
6464
The filter macro MUST be derived from the name of the detection
@@ -73,9 +73,6 @@ def validate_presence_of_filter_macro(cls, value:Union[str, dict[str,Any]], info
7373
Union[str, dict[str,Any]]: The search, either in sigma or SPL format.
7474
"""
7575

76-
if isinstance(value,dict):
77-
#If the search is a dict, then it is in Sigma format so return it
78-
return value
7976

8077
# Otherwise, the search is SPL.
8178

@@ -143,10 +140,8 @@ def datamodel(self)->List[DataModel]:
143140
@computed_field
144141
@property
145142
def source(self)->str:
146-
if self.file_path is not None:
147-
return self.file_path.absolute().parent.name
148-
else:
149-
raise ValueError(f"Cannot get 'source' for detection {self.name} - 'file_path' was None.")
143+
return self.file_path.absolute().parent.name
144+
150145

151146
deployment: Deployment = Field({})
152147

@@ -424,12 +419,11 @@ def model_post_init(self, ctx:dict[str,Any]):
424419
def getDetectionLookups(cls, v:list[str], info:ValidationInfo)->list[Lookup]:
425420
director:DirectorOutputDto = info.context.get("output_dto",None)
426421

427-
search:Union[str,dict] = info.data.get("search",None)
428-
if not isinstance(search,str):
429-
#The search was sigma formatted (or failed other validation and was None), so we will not validate macros in it
430-
return []
422+
search:Union[str,None] = info.data.get("search",None)
423+
if search is None:
424+
raise ValueError("Search was None - is this file missing the search field?")
431425

432-
lookups= Lookup.get_lookups(search, director)
426+
lookups = Lookup.get_lookups(search, director)
433427
return lookups
434428

435429
@field_validator('baselines',mode="before")
@@ -458,10 +452,9 @@ def mapDetectionNamesToBaselineObjects(cls, v:list[str], info:ValidationInfo)->L
458452
def getDetectionMacros(cls, v:list[str], info:ValidationInfo)->list[Macro]:
459453
director:DirectorOutputDto = info.context.get("output_dto",None)
460454

461-
search:Union[str,dict] = info.data.get("search",None)
462-
if not isinstance(search,str):
463-
#The search was sigma formatted (or failed other validation and was None), so we will not validate macros in it
464-
return []
455+
search:Union[str,None] = info.data.get("search",None)
456+
if search is None:
457+
raise ValueError("Search was None - is this file missing the search field?")
465458

466459
search_name:Union[str,Any] = info.data.get("name",None)
467460
assert isinstance(search_name,str), f"Expected 'search_name' to be a string, instead it was [{type(search_name)}]"

0 commit comments

Comments
 (0)