Skip to content

Commit f84c069

Browse files
author
Patrick Bareiss
committed
Data source output fields validation
1 parent a64d879 commit f84c069

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,3 +1055,30 @@ def get_summary(
10551055
# Return the summary
10561056

10571057
return summary_dict
1058+
1059+
@model_validator(mode="after")
1060+
def validate_data_source_output_fields(self):
1061+
# Skip validation for Hunting and Correlation types, or non-production detections
1062+
if (self.status != DetectionStatus.production or
1063+
self.type in {AnalyticsType.Hunting, AnalyticsType.Correlation} or
1064+
len(self.data_source) <= 1):
1065+
return self
1066+
1067+
# Validate that all required output fields are present in the search
1068+
for data_source in self.data_source_objects:
1069+
if not data_source.output_fields:
1070+
continue
1071+
1072+
missing_fields = [
1073+
field for field in data_source.output_fields
1074+
if field not in self.search
1075+
]
1076+
1077+
if missing_fields:
1078+
raise ValueError(
1079+
f"Data source '{data_source.name}' has output fields "
1080+
f"{missing_fields} that are not present in the search "
1081+
f"for detection '{self.name}'"
1082+
)
1083+
1084+
return self

contentctl/objects/data_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DataSource(SecurityContentObject):
2323
field_mappings: None | list = None
2424
convert_to_log_source: None | list = None
2525
example_log: None | str = None
26-
output_fields: list[str] = []
26+
output_fields: None | list = None
2727

2828
@model_serializer
2929
def serialize_model(self):

0 commit comments

Comments
 (0)