Skip to content

Commit 248e436

Browse files
committed
print giant warning about
contentctl 5 being an alpha. change the version in pyproject to 5.0.0-alpha
1 parent a35b5e0 commit 248e436

File tree

2 files changed

+115
-80
lines changed

2 files changed

+115
-80
lines changed

contentctl/contentctl.py

Lines changed: 114 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
import traceback
1+
import pathlib
22
import sys
3+
import traceback
34
import warnings
4-
import pathlib
5+
56
import tyro
67

7-
from contentctl.actions.initialize import Initialize
8-
from contentctl.objects.config import init, validate, build, new, deploy_acs, test, test_servers, inspect, report, test_common, release_notes
9-
from contentctl.actions.validate import Validate
10-
from contentctl.actions.new_content import NewContent
8+
from contentctl.actions.build import Build, BuildInputDto, DirectorOutputDto
9+
from contentctl.actions.deploy_acs import Deploy
1110
from contentctl.actions.detection_testing.GitService import GitService
12-
from contentctl.actions.build import (
13-
BuildInputDto,
14-
DirectorOutputDto,
15-
Build,
16-
)
17-
from contentctl.actions.test import Test
18-
from contentctl.actions.test import TestInputDto
19-
from contentctl.actions.reporting import ReportingInputDto, Reporting
11+
from contentctl.actions.initialize import Initialize
2012
from contentctl.actions.inspect import Inspect
21-
from contentctl.input.yml_reader import YmlReader
22-
from contentctl.actions.deploy_acs import Deploy
13+
from contentctl.actions.new_content import NewContent
2314
from contentctl.actions.release_notes import ReleaseNotes
15+
from contentctl.actions.reporting import Reporting, ReportingInputDto
16+
from contentctl.actions.test import Test, TestInputDto
17+
from contentctl.actions.validate import Validate
18+
from contentctl.input.yml_reader import YmlReader
19+
from contentctl.objects.config import (
20+
build,
21+
deploy_acs,
22+
init,
23+
inspect,
24+
new,
25+
release_notes,
26+
report,
27+
test,
28+
test_common,
29+
test_servers,
30+
validate,
31+
)
2432

2533
# def print_ascii_art():
2634
# print(
2735
# """
28-
# Running Splunk Security Content Control Tool (contentctl)
36+
# Running Splunk Security Content Control Tool (contentctl)
2937
# ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
3038
# ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢶⠛⡇⠀⠀⠀⠀⠀⠀⣠⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
3139
# ⠀⠀⠀⠀⠀⠀⠀⠀⣀⠼⠖⠛⠋⠉⠉⠓⠢⣴⡻⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
@@ -53,114 +61,137 @@
5361
# )
5462

5563

56-
57-
58-
def init_func(config:test):
64+
def init_func(config: test):
5965
Initialize().execute(config)
6066

6167

62-
def validate_func(config:validate)->DirectorOutputDto:
68+
def validate_func(config: validate) -> DirectorOutputDto:
6369
validate = Validate()
6470
return validate.execute(config)
6571

66-
def report_func(config:report)->None:
72+
73+
def report_func(config: report) -> None:
6774
# First, perform validation. Remember that the validate
6875
# configuration is actually a subset of the build configuration
6976
director_output_dto = validate_func(config)
70-
71-
r = Reporting()
72-
return r.execute(ReportingInputDto(director_output_dto=director_output_dto,
73-
config=config))
74-
7577

76-
def build_func(config:build)->DirectorOutputDto:
78+
r = Reporting()
79+
return r.execute(
80+
ReportingInputDto(director_output_dto=director_output_dto, config=config)
81+
)
82+
83+
84+
def build_func(config: build) -> DirectorOutputDto:
7785
# First, perform validation. Remember that the validate
7886
# configuration is actually a subset of the build configuration
7987
director_output_dto = validate_func(config)
8088
builder = Build()
8189
return builder.execute(BuildInputDto(director_output_dto, config))
8290

83-
def inspect_func(config:inspect)->str:
84-
#Make sure that we have built the most recent version of the app
91+
92+
def inspect_func(config: inspect) -> str:
93+
# Make sure that we have built the most recent version of the app
8594
_ = build_func(config)
8695
inspect_token = Inspect().execute(config)
8796
return inspect_token
88-
8997

90-
def release_notes_func(config:release_notes)->None:
98+
99+
def release_notes_func(config: release_notes) -> None:
91100
ReleaseNotes().release_notes(config)
92101

93-
def new_func(config:new):
94-
NewContent().execute(config)
95102

103+
def new_func(config: new):
104+
NewContent().execute(config)
96105

97106

98-
def deploy_acs_func(config:deploy_acs):
107+
def deploy_acs_func(config: deploy_acs):
99108
print("Building and inspecting app...")
100109
token = inspect_func(config)
101110
print("App successfully built and inspected.")
102111
print("Deploying app...")
103112
Deploy().execute(config, token)
104113

105-
def test_common_func(config:test_common):
114+
115+
def test_common_func(config: test_common):
106116
if type(config) == test:
107-
#construct the container Infrastructure objects
117+
# construct the container Infrastructure objects
108118
config.getContainerInfrastructureObjects()
109-
#otherwise, they have already been passed as servers
119+
# otherwise, they have already been passed as servers
110120

111121
director_output_dto = build_func(config)
112-
gitServer = GitService(director=director_output_dto,config=config)
122+
gitServer = GitService(director=director_output_dto, config=config)
113123
detections_to_test = gitServer.getContent()
114124

115-
116-
117125
test_input_dto = TestInputDto(detections_to_test, config)
118-
126+
119127
t = Test()
120128
t.filter_tests(test_input_dto)
121-
129+
122130
if config.plan_only:
123-
#Emit the test plan and quit. Do not actually run the test
124-
config.dumpCICDPlanAndQuit(gitServer.getHash(),test_input_dto.detections)
125-
return
126-
131+
# Emit the test plan and quit. Do not actually run the test
132+
config.dumpCICDPlanAndQuit(gitServer.getHash(), test_input_dto.detections)
133+
return
134+
127135
success = t.execute(test_input_dto)
128-
136+
129137
if success:
130-
#Everything passed!
138+
# Everything passed!
131139
print("All tests have run successfully or been marked as 'skipped'")
132140
return
133141
raise Exception("There was at least one unsuccessful test")
134142

143+
144+
CONTENTCTL_5_WARNING = """
145+
*****************************************************************************
146+
WARNING - THIS IS AN ALPHA BUILD OF CONTENTCTL 5.
147+
THERE HAVE BEEN NUMEROUS CHANGES IN CONTENTCTL (ESPECIALLY TO YML FORMATS).
148+
YOU ALMOST CERTAINLY DO NOT WANT TO USE THIS BUILD.
149+
IF YOU ENCOUNTER ERRORS, PLEASE USE THE LATEST CURRENTYLY SUPPORTED RELEASE:
150+
151+
CONTENTCTL==4.4.7
152+
153+
YOU HAVE BEEN WARNED!
154+
*****************************************************************************
155+
"""
156+
157+
135158
def main():
159+
print(CONTENTCTL_5_WARNING)
136160
try:
137161
configFile = pathlib.Path("contentctl.yml")
138-
162+
139163
# We MUST load a config (with testing info) object so that we can
140164
# properly construct the command line, including 'contentctl test' parameters.
141165
if not configFile.is_file():
142-
if "init" not in sys.argv and "--help" not in sys.argv and "-h" not in sys.argv:
143-
raise Exception(f"'{configFile}' not found in the current directory.\n"
144-
"Please ensure you are in the correct directory or run 'contentctl init' to create a new content pack.")
145-
166+
if (
167+
"init" not in sys.argv
168+
and "--help" not in sys.argv
169+
and "-h" not in sys.argv
170+
):
171+
raise Exception(
172+
f"'{configFile}' not found in the current directory.\n"
173+
"Please ensure you are in the correct directory or run 'contentctl init' to create a new content pack."
174+
)
175+
146176
if "--help" in sys.argv or "-h" in sys.argv:
147-
print("Warning - contentctl.yml is missing from this directory. The configuration values showed at the default and are informational only.\n"
148-
"Please ensure that contentctl.yml exists by manually creating it or running 'contentctl init'")
177+
print(
178+
"Warning - contentctl.yml is missing from this directory. The configuration values showed at the default and are informational only.\n"
179+
"Please ensure that contentctl.yml exists by manually creating it or running 'contentctl init'"
180+
)
149181
# Otherwise generate a stub config file.
150182
# It will be used during init workflow
151183

152184
t = test()
153185
config_obj = t.model_dump()
154-
186+
155187
else:
156-
#The file exists, so load it up!
157-
config_obj = YmlReader().load_file(configFile,add_fields=False)
188+
# The file exists, so load it up!
189+
config_obj = YmlReader().load_file(configFile, add_fields=False)
158190
t = test.model_validate(config_obj)
159191
except Exception as e:
160192
print(f"Error validating 'contentctl.yml':\n{str(e)}")
161193
sys.exit(1)
162-
163-
194+
164195
# For ease of generating the constructor, we want to allow construction
165196
# of an object from default values WITHOUT requiring all fields to be declared
166197
# with defaults OR in the config file. As such, we construct the model rather
@@ -169,30 +200,26 @@ def main():
169200

170201
models = tyro.extras.subcommand_type_from_defaults(
171202
{
172-
"init":init.model_validate(config_obj),
203+
"init": init.model_validate(config_obj),
173204
"validate": validate.model_validate(config_obj),
174205
"report": report.model_validate(config_obj),
175-
"build":build.model_validate(config_obj),
206+
"build": build.model_validate(config_obj),
176207
"inspect": inspect.model_construct(**t.__dict__),
177-
"new":new.model_validate(config_obj),
178-
"test":test.model_validate(config_obj),
179-
"test_servers":test_servers.model_construct(**t.__dict__),
208+
"new": new.model_validate(config_obj),
209+
"test": test.model_validate(config_obj),
210+
"test_servers": test_servers.model_construct(**t.__dict__),
180211
"release_notes": release_notes.model_construct(**config_obj),
181-
"deploy_acs": deploy_acs.model_construct(**t.__dict__)
212+
"deploy_acs": deploy_acs.model_construct(**t.__dict__),
182213
}
183214
)
184-
185-
186215

187-
188216
config = None
189217
try:
190218
# Since some model(s) were constructed and not model_validated, we have to catch
191219
# warnings again when creating the cli
192220
with warnings.catch_warnings(action="ignore"):
193221
config = tyro.cli(models)
194222

195-
196223
if type(config) == init:
197224
t.__dict__.update(config.__dict__)
198225
init_func(t)
@@ -219,21 +246,29 @@ def main():
219246
print(e)
220247
sys.exit(1)
221248
except Exception as e:
249+
print(CONTENTCTL_5_WARNING)
250+
222251
if config is None:
223-
print("There was a serious issue where the config file could not be created.\n"
224-
"The entire stack trace is provided below (please include it if filing a bug report).\n")
252+
print(
253+
"There was a serious issue where the config file could not be created.\n"
254+
"The entire stack trace is provided below (please include it if filing a bug report).\n"
255+
)
225256
traceback.print_exc()
226257
elif config.verbose:
227-
print("Verbose error logging is ENABLED.\n"
228-
"The entire stack trace has been provided below (please include it if filing a bug report):\n")
258+
print(
259+
"Verbose error logging is ENABLED.\n"
260+
"The entire stack trace has been provided below (please include it if filing a bug report):\n"
261+
)
229262
traceback.print_exc()
230263
else:
231-
print("Verbose error logging is DISABLED.\n"
232-
"Please use the --verbose command line argument if you need more context for your error or file a bug report.")
264+
print(
265+
"Verbose error logging is DISABLED.\n"
266+
"Please use the --verbose command line argument if you need more context for your error or file a bug report."
267+
)
233268
print(e)
234-
269+
235270
sys.exit(1)
236271

237272

238273
if __name__ == "__main__":
239-
main()
274+
main()

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 = "5.0.0"
3+
version = "5.0.0-alpha"
44

55
description = "Splunk Content Control Tool"
66
authors = ["STRT <[email protected]>"]

0 commit comments

Comments
 (0)