@@ -58,7 +58,7 @@ class Detection_Abstract(SecurityContentObject):
58
58
59
59
@field_validator ("search" , mode = "before" )
60
60
@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 :
62
62
"""
63
63
Validates that, if required to be present, the filter macro is present with the proper name.
64
64
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
73
73
Union[str, dict[str,Any]]: The search, either in sigma or SPL format.
74
74
"""
75
75
76
- if isinstance (value ,dict ):
77
- #If the search is a dict, then it is in Sigma format so return it
78
- return value
79
76
80
77
# Otherwise, the search is SPL.
81
78
@@ -143,10 +140,8 @@ def datamodel(self)->List[DataModel]:
143
140
@computed_field
144
141
@property
145
142
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
+
150
145
151
146
deployment : Deployment = Field ({})
152
147
@@ -424,12 +419,11 @@ def model_post_init(self, ctx:dict[str,Any]):
424
419
def getDetectionLookups (cls , v :list [str ], info :ValidationInfo )-> list [Lookup ]:
425
420
director :DirectorOutputDto = info .context .get ("output_dto" ,None )
426
421
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?" )
431
425
432
- lookups = Lookup .get_lookups (search , director )
426
+ lookups = Lookup .get_lookups (search , director )
433
427
return lookups
434
428
435
429
@field_validator ('baselines' ,mode = "before" )
@@ -458,10 +452,9 @@ def mapDetectionNamesToBaselineObjects(cls, v:list[str], info:ValidationInfo)->L
458
452
def getDetectionMacros (cls , v :list [str ], info :ValidationInfo )-> list [Macro ]:
459
453
director :DirectorOutputDto = info .context .get ("output_dto" ,None )
460
454
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?" )
465
458
466
459
search_name :Union [str ,Any ] = info .data .get ("name" ,None )
467
460
assert isinstance (search_name ,str ), f"Expected 'search_name' to be a string, instead it was [{ type (search_name )} ]"
0 commit comments