-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from splunk/pydantic2
We're happy to announce the merge for contentctl 4.0! ![image](https://github.com/splunk/contentctl/assets/87383215/5152e9d2-3ce9-4570-b429-150dcadd3bcc)
- Loading branch information
Showing
141 changed files
with
6,069 additions
and
5,542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,68 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
|
||
{ | ||
"name": "contentctl test", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/splunk_contentctl/contentctl.py", | ||
"cwd": "${workspaceFolder}/splunk_contentctl", | ||
"console": "integratedTerminal", | ||
"justMyCode": true, | ||
"args": ["-p", "tmp", "test"] | ||
} | ||
] | ||
"configurations": [ | ||
{ | ||
"name": "contentctl init", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../ddd/", | ||
"args": ["init"] | ||
}, | ||
{ | ||
"name": "contentctl validate", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["validate"] | ||
}, | ||
{ | ||
"name": "contentctl validate enrich", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["validate", "--enrichments"] | ||
}, | ||
{ | ||
"name": "contentctl build", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["build"] | ||
}, | ||
{ | ||
"name": "contentctl build enrich", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["build", "--enrichments"] | ||
}, | ||
{ | ||
"name": "contentctl test", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["test"] | ||
}, | ||
{ | ||
"name": "contentctl --help", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["--help"] | ||
}, | ||
{ | ||
"name": "contentctl test detection", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/.venv/bin/contentctl", | ||
"cwd": "${workspaceFolder}/../", | ||
"args": ["test", "mode:selected", "--mode.files", "detections/endpoint/3cx_supply_chain_attack_network_indicators.yml"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"python.terminal.activateEnvironment": true, | ||
"python.envFile": "${workspaceFolder}/.env", | ||
"python.testing.cwd": "${workspaceFolder}" | ||
"python.testing.cwd": "${workspaceFolder}", | ||
"python.languageServer": "Pylance", | ||
"python.analysis.typeCheckingMode": "strict" | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import sys | ||
import shutil | ||
import os | ||
|
||
from dataclasses import dataclass | ||
|
||
from contentctl.objects.enums import SecurityContentProduct, SecurityContentType | ||
from contentctl.input.director import Director, DirectorOutputDto | ||
from contentctl.output.conf_output import ConfOutput | ||
from contentctl.output.conf_writer import ConfWriter | ||
from contentctl.output.ba_yml_output import BAYmlOutput | ||
from contentctl.output.api_json_output import ApiJsonOutput | ||
import pathlib | ||
import json | ||
import datetime | ||
from typing import Union | ||
|
||
from contentctl.objects.config import build | ||
|
||
@dataclass(frozen=True) | ||
class BuildInputDto: | ||
director_output_dto: DirectorOutputDto | ||
config:build | ||
|
||
|
||
class Build: | ||
|
||
|
||
|
||
def execute(self, input_dto: BuildInputDto) -> DirectorOutputDto: | ||
if input_dto.config.build_app: | ||
updated_conf_files:set[pathlib.Path] = set() | ||
conf_output = ConfOutput(input_dto.config) | ||
updated_conf_files.update(conf_output.writeHeaders()) | ||
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.detections, SecurityContentType.detections)) | ||
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.stories, SecurityContentType.stories)) | ||
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.baselines, SecurityContentType.baselines)) | ||
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.investigations, SecurityContentType.investigations)) | ||
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.lookups, SecurityContentType.lookups)) | ||
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.macros, SecurityContentType.macros)) | ||
updated_conf_files.update(conf_output.writeAppConf()) | ||
|
||
#Ensure that the conf file we just generated/update is syntactically valid | ||
for conf_file in updated_conf_files: | ||
ConfWriter.validateConfFile(conf_file) | ||
|
||
conf_output.packageApp() | ||
|
||
print(f"Build of '{input_dto.config.app.title}' APP successful to {input_dto.config.getPackageFilePath()}") | ||
|
||
|
||
if input_dto.config.build_api: | ||
shutil.rmtree(input_dto.config.getAPIPath(), ignore_errors=True) | ||
input_dto.config.getAPIPath().mkdir(parents=True) | ||
api_json_output = ApiJsonOutput() | ||
for output_objects, output_type in [(input_dto.director_output_dto.detections, SecurityContentType.detections), | ||
(input_dto.director_output_dto.stories, SecurityContentType.stories), | ||
(input_dto.director_output_dto.baselines, SecurityContentType.baselines), | ||
(input_dto.director_output_dto.investigations, SecurityContentType.investigations), | ||
(input_dto.director_output_dto.lookups, SecurityContentType.lookups), | ||
(input_dto.director_output_dto.macros, SecurityContentType.macros), | ||
(input_dto.director_output_dto.deployments, SecurityContentType.deployments)]: | ||
api_json_output.writeObjects(output_objects, input_dto.config.getAPIPath(), input_dto.config.app.label, output_type ) | ||
|
||
|
||
|
||
#create version file for sse api | ||
version_file = input_dto.config.getAPIPath()/"version.json" | ||
utc_time = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0,tzinfo=None).isoformat() | ||
version_dict = {"version":{"name":f"v{input_dto.config.app.version}","published_at": f"{utc_time}Z" }} | ||
with open(version_file,"w") as version_f: | ||
json.dump(version_dict,version_f) | ||
|
||
print(f"Build of '{input_dto.config.app.title}' API successful to {input_dto.config.getAPIPath()}") | ||
|
||
if input_dto.config.build_ssa: | ||
|
||
srs_path = input_dto.config.getSSAPath() / 'srs' | ||
complex_path = input_dto.config.getSSAPath() / 'complex' | ||
shutil.rmtree(srs_path, ignore_errors=True) | ||
shutil.rmtree(complex_path, ignore_errors=True) | ||
srs_path.mkdir(parents=True) | ||
complex_path.mkdir(parents=True) | ||
ba_yml_output = BAYmlOutput() | ||
ba_yml_output.writeObjects(input_dto.director_output_dto.ssa_detections, str(input_dto.config.getSSAPath())) | ||
|
||
print(f"Build of 'SSA' successful to {input_dto.config.getSSAPath()}") | ||
|
||
return input_dto.director_output_dto |
Oops, something went wrong.