Skip to content

Commit d0a29d8

Browse files
authored
Merge pull request #375 from splunk/no_more_missing_datasources
Convert warning for missing datasource to an error
2 parents b2f0985 + 07bca0d commit d0a29d8

File tree

2 files changed

+20
-55
lines changed

2 files changed

+20
-55
lines changed

contentctl/input/director.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import os
22
import sys
3-
from pathlib import Path
43
from dataclasses import dataclass, field
5-
from pydantic import ValidationError
4+
from pathlib import Path
65
from uuid import UUID
7-
from contentctl.input.yml_reader import YmlReader
86

9-
from contentctl.objects.detection import Detection
10-
from contentctl.objects.story import Story
7+
from pydantic import ValidationError
118

12-
from contentctl.objects.baseline import Baseline
13-
from contentctl.objects.investigation import Investigation
14-
from contentctl.objects.playbook import Playbook
15-
from contentctl.objects.deployment import Deployment
16-
from contentctl.objects.macro import Macro
17-
from contentctl.objects.lookup import LookupAdapter, Lookup
18-
from contentctl.objects.atomic import AtomicEnrichment
19-
from contentctl.objects.security_content_object import SecurityContentObject
20-
from contentctl.objects.data_source import DataSource
21-
from contentctl.objects.dashboard import Dashboard
229
from contentctl.enrichments.attack_enrichment import AttackEnrichment
2310
from contentctl.enrichments.cve_enrichment import CveEnrichment
24-
11+
from contentctl.helper.utils import Utils
12+
from contentctl.input.yml_reader import YmlReader
13+
from contentctl.objects.atomic import AtomicEnrichment
14+
from contentctl.objects.baseline import Baseline
2515
from contentctl.objects.config import validate
16+
from contentctl.objects.dashboard import Dashboard
17+
from contentctl.objects.data_source import DataSource
18+
from contentctl.objects.deployment import Deployment
19+
from contentctl.objects.detection import Detection
2620
from contentctl.objects.enums import SecurityContentType
27-
from contentctl.helper.utils import Utils
21+
from contentctl.objects.investigation import Investigation
22+
from contentctl.objects.lookup import Lookup, LookupAdapter
23+
from contentctl.objects.macro import Macro
24+
from contentctl.objects.playbook import Playbook
25+
from contentctl.objects.security_content_object import SecurityContentObject
26+
from contentctl.objects.story import Story
2827

2928

3029
@dataclass
@@ -113,20 +112,6 @@ def execute(self, input_dto: validate) -> None:
113112
self.createSecurityContent(SecurityContentType.detections)
114113
self.createSecurityContent(SecurityContentType.dashboards)
115114

116-
from contentctl.objects.abstract_security_content_objects.detection_abstract import (
117-
MISSING_SOURCES,
118-
)
119-
120-
if len(MISSING_SOURCES) > 0:
121-
missing_sources_string = "\n 🟡 ".join(sorted(list(MISSING_SOURCES)))
122-
print(
123-
"WARNING: The following data_sources have been used in detections, but are not yet defined.\n"
124-
"This is not yet an error since not all data_sources have been defined, but will be convered to an error soon:\n 🟡 "
125-
f"{missing_sources_string}"
126-
)
127-
else:
128-
print("No missing data_sources!")
129-
130115
def createSecurityContent(self, contentType: SecurityContentType) -> None:
131116
if contentType in [
132117
SecurityContentType.deployments,

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
from contentctl.objects.test_group import TestGroup
5252
from contentctl.objects.unit_test import UnitTest
5353

54-
MISSING_SOURCES: set[str] = set()
55-
5654
# Those AnalyticsTypes that we do not test via contentctl
5755
SKIPPED_ANALYTICS_TYPES: set[str] = {AnalyticsType.Correlation}
5856

@@ -514,7 +512,7 @@ def model_post_init(self, __context: Any) -> None:
514512
baseline.tags.detections = new_detections
515513

516514
# Data source may be defined 1 on each line, OR they may be defined as
517-
# SOUCE_1 AND ANOTHERSOURCE AND A_THIRD_SOURCE
515+
# SOURCE_1 AND ANOTHERSOURCE AND A_THIRD_SOURCE
518516
# if more than 1 data source is required for a detection (for example, because it includes a join)
519517
# Parse and update the list to resolve individual names and remove potential duplicates
520518
updated_data_source_names: set[str] = set()
@@ -524,27 +522,9 @@ def model_post_init(self, __context: Any) -> None:
524522
updated_data_source_names.update(split_data_sources)
525523

526524
sources = sorted(list(updated_data_source_names))
527-
528-
matched_data_sources: list[DataSource] = []
529-
missing_sources: list[str] = []
530-
for source in sources:
531-
try:
532-
matched_data_sources += DataSource.mapNamesToSecurityContentObjects(
533-
[source], director
534-
)
535-
except Exception:
536-
# We gobble this up and add it to a global set so that we
537-
# can print it ONCE at the end of the build of datasources.
538-
# This will be removed later as per the note below
539-
MISSING_SOURCES.add(source)
540-
541-
if len(missing_sources) > 0:
542-
# This will be changed to ValueError when we have a complete list of data sources
543-
print(
544-
"WARNING: The following exception occurred when mapping the data_source field to "
545-
f"DataSource objects:{missing_sources}"
546-
)
547-
525+
matched_data_sources = DataSource.mapNamesToSecurityContentObjects(
526+
sources, director
527+
)
548528
self.data_source_objects = matched_data_sources
549529

550530
for story in self.tags.analytic_story:

0 commit comments

Comments
 (0)