Skip to content

Commit 1f15302

Browse files
committed
first go at testing on ds changes
1 parent 5488ca6 commit 1f15302

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

contentctl/actions/detection_testing/GitService.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from contentctl.objects.macro import Macro
1414
from contentctl.objects.lookup import Lookup
1515
from contentctl.objects.detection import Detection
16+
from contentctl.objects.data_source import DataSource
1617
from contentctl.objects.security_content_object import SecurityContentObject
1718
from contentctl.objects.config import test_common, All, Changes, Selected
1819

@@ -70,6 +71,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
7071
updated_detections:List[Detection] = []
7172
updated_macros:List[Macro] = []
7273
updated_lookups:List[Lookup] =[]
74+
updated_datasources:List[DataSource] = []
7375

7476
for diff in all_diffs:
7577
if type(diff) == pygit2.Patch:
@@ -90,6 +92,13 @@ def getChanges(self, target_branch:str)->List[Detection]:
9092
updated_macros.append(macroObject)
9193
else:
9294
raise Exception(f"Error getting macro object for file {str(decoded_path)}")
95+
96+
elif decoded_path.is_relative_to(self.config.path/"data_sources") and decoded_path.suffix == ".yml":
97+
datasourceObject = filepath_to_content_map.get(decoded_path, None)
98+
if isinstance(datasourceObject, DataSource):
99+
updated_datasources.append(datasourceObject)
100+
else:
101+
raise Exception(f"Error getting data source object for file {str(decoded_path)}")
93102

94103
elif decoded_path.is_relative_to(self.config.path/"lookups"):
95104
# We need to convert this to a yml. This means we will catch
@@ -115,7 +124,6 @@ def getChanges(self, target_branch:str)->List[Detection]:
115124
# Detected a changed .mlmodel file. However, since we do not have testing for these detections at
116125
# this time, we will ignore this change.
117126
updatedLookup = None
118-
119127

120128
else:
121129
raise Exception(f"Detected a changed file in the lookups/ directory '{str(decoded_path)}'.\n"
@@ -136,15 +144,15 @@ def getChanges(self, target_branch:str)->List[Detection]:
136144

137145
# If a detection has at least one dependency on changed content,
138146
# then we must test it again
139-
changed_macros_and_lookups = updated_macros + updated_lookups
147+
changed_macros_and_lookups_and_datasources = updated_macros + updated_lookups + updated_datasources
140148

141149
for detection in self.director.detections:
142150
if detection in updated_detections:
143151
# we are already planning to test it, don't need
144152
# to add it again
145153
continue
146154

147-
for obj in changed_macros_and_lookups:
155+
for obj in changed_macros_and_lookups_and_datasources:
148156
if obj in detection.get_content_dependencies():
149157
updated_detections.append(detection)
150158
break

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ def get_content_dependencies(self) -> list[SecurityContentObject]:
647647
objects: list[SecurityContentObject] = []
648648
objects += self.macros
649649
objects += self.lookups
650+
objects += self.data_source_objects
650651
return objects
651652

652653
@field_validator("deployment", mode="before")

0 commit comments

Comments
 (0)