13
13
from contentctl .objects .macro import Macro
14
14
from contentctl .objects .lookup import Lookup
15
15
from contentctl .objects .detection import Detection
16
+ from contentctl .objects .data_source import DataSource
16
17
from contentctl .objects .security_content_object import SecurityContentObject
17
18
from contentctl .objects .config import test_common , All , Changes , Selected
18
19
@@ -67,9 +68,12 @@ def getChanges(self, target_branch:str)->List[Detection]:
67
68
68
69
#Make a filename to content map
69
70
filepath_to_content_map = { obj .file_path :obj for (_ ,obj ) in self .director .name_to_content_map .items ()}
70
- updated_detections :set [Detection ] = set ()
71
- updated_macros :set [Macro ] = set ()
72
- updated_lookups :set [Lookup ] = set ()
71
+
72
+ updated_detections : set [Detection ] = set ()
73
+ updated_macros : set [Macro ] = set ()
74
+ updated_lookups : set [Lookup ] = set ()
75
+ updated_datasources : set [DataSource ] = set ()
76
+
73
77
74
78
for diff in all_diffs :
75
79
if type (diff ) == pygit2 .Patch :
@@ -90,6 +94,13 @@ def getChanges(self, target_branch:str)->List[Detection]:
90
94
updated_macros .add (macroObject )
91
95
else :
92
96
raise Exception (f"Error getting macro object for file { str (decoded_path )} " )
97
+
98
+ elif decoded_path .is_relative_to (self .config .path / "data_sources" ) and decoded_path .suffix == ".yml" :
99
+ datasourceObject = filepath_to_content_map .get (decoded_path , None )
100
+ if isinstance (datasourceObject , DataSource ):
101
+ updated_datasources .add (datasourceObject )
102
+ else :
103
+ raise Exception (f"Error getting data source object for file { str (decoded_path )} " )
93
104
94
105
elif decoded_path .is_relative_to (self .config .path / "lookups" ):
95
106
# We need to convert this to a yml. This means we will catch
@@ -115,7 +126,6 @@ def getChanges(self, target_branch:str)->List[Detection]:
115
126
# Detected a changed .mlmodel file. However, since we do not have testing for these detections at
116
127
# this time, we will ignore this change.
117
128
updatedLookup = None
118
-
119
129
120
130
else :
121
131
raise Exception (f"Detected a changed file in the lookups/ directory '{ str (decoded_path )} '.\n "
@@ -136,15 +146,16 @@ def getChanges(self, target_branch:str)->List[Detection]:
136
146
137
147
# If a detection has at least one dependency on changed content,
138
148
# then we must test it again
139
- changed_macros_and_lookups :set [SecurityContentObject ] = updated_macros .union (updated_lookups )
149
+
150
+ changed_macros_and_lookups_and_datasources :set [SecurityContentObject ] = updated_macros .union (updated_lookups , updated_datasources )
140
151
141
152
for detection in self .director .detections :
142
153
if detection in updated_detections :
143
154
# we are already planning to test it, don't need
144
155
# to add it again
145
156
continue
146
157
147
- for obj in changed_macros_and_lookups :
158
+ for obj in changed_macros_and_lookups_and_datasources :
148
159
if obj in detection .get_content_dependencies ():
149
160
updated_detections .add (detection )
150
161
break
0 commit comments