20
20
if TYPE_CHECKING :
21
21
from contentctl .input .director import DirectorOutputDto
22
22
from contentctl .objects .baseline import Baseline
23
-
23
+ from contentctl .objects .config import CustomApp
24
+
24
25
from contentctl .objects .security_content_object import SecurityContentObject
25
26
from contentctl .objects .enums import AnalyticsType
26
27
from contentctl .objects .enums import DataModel
36
37
from contentctl .objects .data_source import DataSource
37
38
from contentctl .objects .base_test_result import TestResultStatus
38
39
39
- # from contentctl.objects.playbook import Playbook
40
40
from contentctl .objects .enums import ProvidingTechnology
41
41
from contentctl .enrichments .cve_enrichment import CveEnrichmentObj
42
42
import datetime
51
51
# TODO (#266): disable the use_enum_values configuration
52
52
class Detection_Abstract (SecurityContentObject ):
53
53
model_config = ConfigDict (use_enum_values = True )
54
-
55
- # contentType: SecurityContentType = SecurityContentType.detections
54
+ name : str = Field (..., max_length = 67 )
55
+ #contentType: SecurityContentType = SecurityContentType.detections
56
56
type : AnalyticsType = Field (...)
57
57
status : DetectionStatus = Field (...)
58
58
data_source : list [str ] = []
@@ -70,10 +70,31 @@ class Detection_Abstract(SecurityContentObject):
70
70
# https://github.com/pydantic/pydantic/issues/9101#issuecomment-2019032541
71
71
tests : List [Annotated [Union [UnitTest , IntegrationTest , ManualTest ], Field (union_mode = 'left_to_right' )]] = []
72
72
# A list of groups of tests, relying on the same data
73
- test_groups : Union [ list [TestGroup ], None ] = Field ( None , validate_default = True )
73
+ test_groups : list [TestGroup ] = []
74
74
75
75
data_source_objects : list [DataSource ] = []
76
76
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 } ' " )
84
+
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
+
95
+
96
+
97
+
77
98
@field_validator ("search" , mode = "before" )
78
99
@classmethod
79
100
def validate_presence_of_filter_macro (cls , value :str , info :ValidationInfo )-> str :
@@ -515,7 +536,7 @@ def model_post_init(self, __context: Any) -> None:
515
536
self .data_source_objects = matched_data_sources
516
537
517
538
for story in self .tags .analytic_story :
518
- story .detections .append (self )
539
+ story .detections .append (self )
519
540
520
541
self .cve_enrichment_func (__context )
521
542
0 commit comments