Skip to content

Commit b8b5c2d

Browse files
authored
Merge pull request #301 from splunk/test_on_app_change
Testing on Datasource changes
2 parents 3c733f1 + 3c9395c commit b8b5c2d

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

contentctl/actions/detection_testing/GitService.py

Lines changed: 17 additions & 6 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

@@ -67,9 +68,12 @@ def getChanges(self, target_branch:str)->List[Detection]:
6768

6869
#Make a filename to content map
6970
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+
7377

7478
for diff in all_diffs:
7579
if type(diff) == pygit2.Patch:
@@ -90,6 +94,13 @@ def getChanges(self, target_branch:str)->List[Detection]:
9094
updated_macros.add(macroObject)
9195
else:
9296
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)}")
93104

94105
elif decoded_path.is_relative_to(self.config.path/"lookups"):
95106
# 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]:
115126
# Detected a changed .mlmodel file. However, since we do not have testing for these detections at
116127
# this time, we will ignore this change.
117128
updatedLookup = None
118-
119129

120130
else:
121131
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]:
136146

137147
# If a detection has at least one dependency on changed content,
138148
# 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)
140151

141152
for detection in self.director.detections:
142153
if detection in updated_detections:
143154
# we are already planning to test it, don't need
144155
# to add it again
145156
continue
146157

147-
for obj in changed_macros_and_lookups:
158+
for obj in changed_macros_and_lookups_and_datasources:
148159
if obj in detection.get_content_dependencies():
149160
updated_detections.add(detection)
150161
break

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ def get_content_dependencies(self) -> list[SecurityContentObject]:
689689
objects: list[SecurityContentObject] = []
690690
objects += self.macros
691691
objects += self.lookups
692+
objects += self.data_source_objects
692693
return objects
693694

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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "contentctl"
3-
version = "4.4.4"
3+
version = "4.4.5"
44

55
description = "Splunk Content Control Tool"
66
authors = ["STRT <[email protected]>"]

0 commit comments

Comments
 (0)