40
40
from contentctl .objects .enums import ProvidingTechnology
41
41
from contentctl .enrichments .cve_enrichment import CveEnrichmentObj
42
42
import datetime
43
+ from contentctl .objects .constants import (
44
+ ES_MAX_STANZA_LENGTH ,
45
+ ES_SEARCH_STANZA_NAME_FORMAT_AFTER_CLONING_IN_PRODUCT_TEMPLATE ,
46
+ CONTENTCTL_MAX_SEARCH_NAME_LENGTH
47
+ )
48
+
43
49
MISSING_SOURCES : set [str ] = set ()
44
50
45
51
# Those AnalyticsTypes that we do not test via contentctl
51
57
# TODO (#266): disable the use_enum_values configuration
52
58
class Detection_Abstract (SecurityContentObject ):
53
59
model_config = ConfigDict (use_enum_values = True )
54
- name :str = Field (...,max_length = 67 )
60
+ name :str = Field (...,max_length = CONTENTCTL_MAX_SEARCH_NAME_LENGTH )
55
61
#contentType: SecurityContentType = SecurityContentType.detections
56
62
type : AnalyticsType = Field (...)
57
63
status : DetectionStatus = Field (...)
@@ -74,26 +80,19 @@ class Detection_Abstract(SecurityContentObject):
74
80
75
81
data_source_objects : list [DataSource ] = []
76
82
77
- def get_action_dot_correlationsearch_dot_label (self , app :CustomApp , max_stanza_length :int = 99 )-> str :
78
- label = self .get_conf_stanza_name (app )
79
- label_after_saving_in_product = f"{ self .tags .security_domain .value } - { label } - Rule"
80
-
81
- if len (label_after_saving_in_product ) > max_stanza_length :
82
- raise ValueError (f"label may only be { max_stanza_length } characters to allow updating in-product, "
83
- f"but stanza was actually { len (label_after_saving_in_product )} characters: '{ label_after_saving_in_product } ' " )
83
+ def get_action_dot_correlationsearch_dot_label (self , app :CustomApp , max_stanza_length :int = ES_MAX_STANZA_LENGTH )-> str :
84
+ stanza_name = self .get_conf_stanza_name (app )
85
+ stanza_name_after_saving_in_es = ES_SEARCH_STANZA_NAME_FORMAT_AFTER_CLONING_IN_PRODUCT_TEMPLATE .format (
86
+ security_domain_value = self .tags .security_domain .value ,
87
+ search_name = stanza_name
88
+ )
84
89
85
- return label
86
-
87
- def get_conf_stanza_name (self , app :CustomApp , max_stanza_length :int = 81 )-> str :
88
- stanza_name = f"{ app .label } - { self .name } - Rule"
89
- if len (stanza_name ) > max_stanza_length :
90
- raise ValueError (f"conf stanza may only be { max_stanza_length } characters, "
91
- f"but stanza was actually { len (stanza_name )} characters: '{ stanza_name } ' " )
92
- #print(f"Stanza Length[{len(stanza_name)}]")
93
- return stanza_name
94
90
91
+ if len (stanza_name_after_saving_in_es ) > max_stanza_length :
92
+ raise ValueError (f"label may only be { max_stanza_length } characters to allow updating in-product, "
93
+ f"but stanza was actually { len (stanza_name_after_saving_in_es )} characters: '{ stanza_name_after_saving_in_es } ' " )
95
94
96
-
95
+ return stanza_name
97
96
98
97
@field_validator ("search" , mode = "before" )
99
98
@classmethod
@@ -674,7 +673,7 @@ def addTags_nist(self):
674
673
else :
675
674
self .tags .nist = [NistCategory .DE_AE ]
676
675
return self
677
-
676
+
678
677
679
678
@model_validator (mode = "after" )
680
679
def ensureThrottlingFieldsExist (self ):
@@ -685,10 +684,6 @@ def ensureThrottlingFieldsExist(self):
685
684
if self .tags .throttling is None :
686
685
# No throttling configured for this detection
687
686
return self
688
-
689
- if not isinstance (self .search , str ):
690
- # Search is sigma-formatted, so we cannot perform this validation.
691
- return self
692
687
693
688
missing_fields :list [str ] = [field for field in self .tags .throttling .fields if field not in self .search ]
694
689
if len (missing_fields ) > 0 :
0 commit comments