Skip to content

Commit f00e886

Browse files
Merge branch 'main' into feature/version-bumping-enforcement
2 parents 4cf3628 + 3cda211 commit f00e886

File tree

13 files changed

+50
-380
lines changed

13 files changed

+50
-380
lines changed

contentctl/actions/initialize.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import shutil
33
import os
44
import pathlib
5-
6-
from pydantic import RootModel
75
from contentctl.objects.config import test
86
from contentctl.output.yml_writer import YmlWriter
97

@@ -17,26 +15,44 @@ def execute(self, config: test) -> None:
1715

1816
YmlWriter.writeYmlFile(str(config.path/'contentctl.yml'), config.model_dump())
1917

18+
2019
#Create the following empty directories:
21-
for emptyDir in ['lookups', 'baselines', 'docs', 'reporting', 'investigations']:
20+
for emptyDir in ['lookups', 'baselines', 'data_sources', 'docs', 'reporting', 'investigations',
21+
'detections/application', 'detections/cloud', 'detections/endpoint',
22+
'detections/network', 'detections/web', 'macros', 'stories']:
2223
#Throw an error if this directory already exists
23-
(config.path/emptyDir).mkdir(exist_ok=False)
24+
(config.path/emptyDir).mkdir(exist_ok=False, parents=True)
25+
26+
# If this is not a bare config, then populate
27+
# a small amount of content into the directories
28+
if not config.bare:
29+
#copy the contents of all template directories
30+
for templateDir, targetDir in [
31+
('../templates/detections/', 'detections'),
32+
('../templates/data_sources/', 'data_sources'),
33+
('../templates/macros/', 'macros'),
34+
('../templates/stories/', 'stories'),
35+
]:
36+
source_directory = pathlib.Path(os.path.dirname(__file__))/templateDir
37+
target_directory = config.path/targetDir
38+
39+
# Do not throw an exception if the directory exists. In fact, it was
40+
# created above when the structure of the app was created.
41+
shutil.copytree(source_directory, target_directory, dirs_exist_ok=True)
2442

25-
26-
#copy the contents of all template directories
43+
# The contents of app_template must ALWAYS be copied because it contains
44+
# several special files.
45+
# For now, we also copy the deployments because the ability to create custom
46+
# deployment files is limited with built-in functionality.
2747
for templateDir, targetDir in [
2848
('../templates/app_template/', 'app_template'),
29-
('../templates/deployments/', 'deployments'),
30-
('../templates/detections/', 'detections'),
31-
('../templates/data_sources/', 'data_sources'),
32-
('../templates/macros/','macros'),
33-
('../templates/stories/', 'stories'),
49+
('../templates/deployments/', 'deployments')
3450
]:
3551
source_directory = pathlib.Path(os.path.dirname(__file__))/templateDir
3652
target_directory = config.path/targetDir
3753
#Throw an exception if the target exists
3854
shutil.copytree(source_directory, target_directory, dirs_exist_ok=False)
39-
55+
4056
# Create a README.md file. Note that this is the README.md for the repository, not the
4157
# one which will actually be packaged into the app. That is located in the app_template folder.
4258
shutil.copyfile(pathlib.Path(os.path.dirname(__file__))/'../templates/README.md','README.md')

contentctl/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def update_config(config:Union[test,test_servers], **key_value_updates:dict[str,
126126
def content_to_dict(director:DirectorOutputDto)->dict[str,list[dict[str,Any]]]:
127127
output_dict:dict[str,list[dict[str,Any]]] = {}
128128
for contentType in ['detections','stories','baselines','investigations',
129-
'playbooks','macros','lookups','deployments','ssa_detections']:
129+
'playbooks','macros','lookups','deployments',]:
130130

131131
output_dict[contentType] = []
132132
t:list[SecurityContentObject] = getattr(director,contentType)

contentctl/input/director.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from contentctl.objects.deployment import Deployment
1919
from contentctl.objects.macro import Macro
2020
from contentctl.objects.lookup import Lookup
21-
from contentctl.objects.ssa_detection import SSADetection
2221
from contentctl.objects.atomic import AtomicTest
2322
from contentctl.objects.security_content_object import SecurityContentObject
2423
from contentctl.objects.data_source import DataSource
@@ -33,10 +32,7 @@
3332
from contentctl.objects.enums import DetectionStatus
3433
from contentctl.helper.utils import Utils
3534

36-
from contentctl.objects.enums import SecurityContentType
3735

38-
from contentctl.objects.enums import DetectionStatus
39-
from contentctl.helper.utils import Utils
4036

4137

4238
@dataclass
@@ -60,10 +56,7 @@ class DirectorOutputDto:
6056

6157
def addContentToDictMappings(self, content: SecurityContentObject):
6258
content_name = content.name
63-
if isinstance(content, SSADetection):
64-
# Since SSA detections may have the same name as ESCU detection,
65-
# for this function we prepend 'SSA ' to the name.
66-
content_name = f"SSA {content_name}"
59+
6760

6861
if content_name in self.name_to_content_map:
6962
raise ValueError(
@@ -149,7 +142,7 @@ def createSecurityContent(self, contentType: SecurityContentType) -> None:
149142
os.path.join(self.input_dto.path, str(contentType.name))
150143
)
151144
security_content_files = [
152-
f for f in files if not f.name.startswith("ssa___")
145+
f for f in files
153146
]
154147
else:
155148
raise (Exception(f"Cannot createSecurityContent for unknown product."))

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ def validate_presence_of_filter_macro(cls, value:str, info:ValidationInfo)->str:
8383
8484
8585
Args:
86-
value (Union[str, dict[str,Any]]): The search. It can either be a string (and should be
87-
SPL or a dict, in which case it is Sigma-formatted.
86+
value (str): The SPL search. It must be an SPL-formatted string.
8887
info (ValidationInfo): The validation info can contain a number of different objects.
8988
Today it only contains the director.
9089
9190
Returns:
92-
Union[str, dict[str,Any]]: The search, either in sigma or SPL format.
93-
"""
94-
91+
str: The search, as an SPL formatted string.
92+
"""
9593

9694
# Otherwise, the search is SPL.
9795

contentctl/objects/config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ def serialize_path(path: DirectoryPath)->str:
176176
return str(path)
177177

178178
class init(Config_Base):
179-
pass
179+
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
180+
bare: bool = Field(default=False, description="contentctl normally provides some some example content "
181+
"(macros, stories, data_sources, and/or analytic stories). This option disables "
182+
"initialization with that additional contnet. Note that even if --bare is used, it "
183+
"init will still create the directory structure of the app, "
184+
"include the app_template directory with default content, and content in "
185+
"the deployment/ directory (since it is not yet easily customizable).")
180186

181187

182188
# TODO (#266): disable the use_enum_values configuration
@@ -238,9 +244,6 @@ def getPackageFilePath(self, include_version:bool=False)->pathlib.Path:
238244
return self.getBuildDir() / f"{self.app.appid}-{self.app.version}.tar.gz"
239245
else:
240246
return self.getBuildDir() / f"{self.app.appid}-latest.tar.gz"
241-
242-
def getSSAPath(self)->pathlib.Path:
243-
return self.getBuildDir() / "ssa"
244247

245248
def getAPIPath(self)->pathlib.Path:
246249
return self.getBuildDir() / "api"

contentctl/objects/enums.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class SecurityContentType(enum.Enum):
5454
deployments = 7
5555
investigations = 8
5656
unit_tests = 9
57-
ssa_detections = 10
5857
data_sources = 11
5958

6059
# Bringing these changes back in line will take some time after
@@ -69,7 +68,6 @@ class SecurityContentType(enum.Enum):
6968

7069
class SecurityContentProduct(enum.Enum):
7170
SPLUNK_APP = 1
72-
SSA = 2
7371
API = 3
7472
CUSTOM = 4
7573

contentctl/objects/ssa_detection.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)