Skip to content

Commit d670f3e

Browse files
authored
Merge pull request #187 from splunk/fix_modechanges_diff_bug
Fix checking during mode:changes
2 parents 93d689c + 63ca367 commit d670f3e

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

contentctl/actions/detection_testing/GitService.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,28 @@ def getChanges(self, target_branch:str)->List[Detection]:
7676
if diff.delta.status in (DeltaStatus.ADDED, DeltaStatus.MODIFIED, DeltaStatus.RENAMED):
7777
#print(f"{DeltaStatus(diff.delta.status).name:<8}:{diff.delta.new_file.raw_path}")
7878
decoded_path = pathlib.Path(diff.delta.new_file.raw_path.decode('utf-8'))
79-
if 'app_template/' in str(decoded_path) or 'ssa_detections' in str(decoded_path) or str(self.config.getBuildDir()) in str(decoded_path):
80-
#Ignore anything that is embedded in the app template.
81-
#Also ignore ssa detections
82-
pass
83-
elif 'detections/' in str(decoded_path) and decoded_path.suffix == ".yml":
79+
# Note that we only handle updates to detections, lookups, and macros at this time. All other changes are ignored.
80+
if decoded_path.is_relative_to(self.config.path/"detections") and decoded_path.suffix == ".yml":
8481
detectionObject = filepath_to_content_map.get(decoded_path, None)
8582
if isinstance(detectionObject, Detection):
8683
updated_detections.append(detectionObject)
8784
else:
8885
raise Exception(f"Error getting detection object for file {str(decoded_path)}")
8986

90-
elif 'macros/' in str(decoded_path) and decoded_path.suffix == ".yml":
87+
elif decoded_path.is_relative_to(self.config.path/"macros") and decoded_path.suffix == ".yml":
9188
macroObject = filepath_to_content_map.get(decoded_path, None)
9289
if isinstance(macroObject, Macro):
9390
updated_macros.append(macroObject)
9491
else:
9592
raise Exception(f"Error getting macro object for file {str(decoded_path)}")
9693

97-
elif 'lookups/' in str(decoded_path):
94+
elif decoded_path.is_relative_to(self.config.path/"lookups"):
9895
# We need to convert this to a yml. This means we will catch
9996
# both changes to a csv AND changes to the YML that uses it
100-
101-
10297
if decoded_path.suffix == ".yml":
10398
updatedLookup = filepath_to_content_map.get(decoded_path, None)
10499
if not isinstance(updatedLookup,Lookup):
105-
raise Exception(f"Expected {decoded_path} to be type {type(Lookup)}, but instead if was {(type(lookupObject))}")
100+
raise Exception(f"Expected {decoded_path} to be type {type(Lookup)}, but instead if was {(type(updatedLookup))}")
106101
updated_lookups.append(updatedLookup)
107102

108103
elif decoded_path.suffix == ".csv":
@@ -127,12 +122,8 @@ def getChanges(self, target_branch:str)->List[Detection]:
127122
else:
128123
pass
129124
#print(f"Ignore changes to file {decoded_path} since it is not a detection, macro, or lookup.")
130-
131-
# else:
132-
# print(f"{diff.delta.new_file.raw_path}:{DeltaStatus(diff.delta.status).name} (IGNORED)")
133-
# pass
134125
else:
135-
raise Exception(f"Unrecognized type {type(diff)}")
126+
raise Exception(f"Unrecognized diff type {type(diff)}")
136127

137128

138129
# If a detection has at least one dependency on changed content,
@@ -153,7 +144,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
153144
#Print out the names of all modified/new content
154145
modifiedAndNewContentString = "\n - ".join(sorted([d.name for d in updated_detections]))
155146

156-
print(f"[{len(updated_detections)}] Pieces of modifed and new content to test:\n - {modifiedAndNewContentString}")
147+
print(f"[{len(updated_detections)}] Pieces of modifed and new content (this may include experimental/deprecated/manual_test content):\n - {modifiedAndNewContentString}")
157148
return updated_detections
158149

159150
def getSelected(self, detectionFilenames:List[FilePath])->List[Detection]:

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.1.1"
3+
version = "4.1.2"
44
description = "Splunk Content Control Tool"
55
authors = ["STRT <[email protected]>"]
66
license = "Apache 2.0"

0 commit comments

Comments
 (0)