Skip to content

Commit 1f52c7d

Browse files
authored
Merge branch 'release_v4.1.0' into update_deps_4.1
2 parents 18b2c67 + bfe98c9 commit 1f52c7d

File tree

5 files changed

+69
-19
lines changed

5 files changed

+69
-19
lines changed

contentctl/actions/new_content.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def buildDetection(self)->dict[str,Any]:
2525
answers['date'] = datetime.today().strftime('%Y-%m-%d')
2626
answers['author'] = answers['detection_author']
2727
del answers['detection_author']
28-
answers['data_source'] = answers['data_source']
28+
answers['data_sources'] = answers['data_source']
29+
del answers['data_source']
2930
answers['type'] = answers['detection_type']
3031
del answers['detection_type']
3132
answers['status'] = "production" #start everything as production since that's what we INTEND the content to become
@@ -49,6 +50,7 @@ def buildDetection(self)->dict[str,Any]:
4950
answers['tags']['required_fields'] = ['UPDATE']
5051
answers['tags']['risk_score'] = 'UPDATE (impact * confidence)/100'
5152
answers['tags']['security_domain'] = answers['security_domain']
53+
del answers["security_domain"]
5254
answers['tags']['cve'] = ['UPDATE WITH CVE(S) IF APPLICABLE']
5355

5456
#generate the tests section
@@ -64,6 +66,7 @@ def buildDetection(self)->dict[str,Any]:
6466
]
6567
}
6668
]
69+
del answers["mitre_attack_ids"]
6770
return answers
6871

6972
def buildStory(self)->dict[str,Any]:
@@ -111,12 +114,12 @@ def writeObjectNewContent(self, object: dict, subdirectory_name: str, type: NewC
111114
#make sure the output folder exists for this detection
112115
output_folder.mkdir(exist_ok=True)
113116

114-
YmlWriter.writeYmlFile(file_path, object)
117+
YmlWriter.writeDetection(file_path, object)
115118
print("Successfully created detection " + file_path)
116119

117120
elif type == NewContentType.story:
118121
file_path = os.path.join(self.output_path, 'stories', self.convertNameToFileName(object['name'], object['tags']['product']))
119-
YmlWriter.writeYmlFile(file_path, object)
122+
YmlWriter.writeStory(file_path, object)
120123
print("Successfully created story " + file_path)
121124

122125
else:

contentctl/contentctl.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from contentctl.actions.initialize import Initialize
1+
import traceback
2+
import sys
3+
import warnings
4+
import pathlib
25
import tyro
6+
7+
from contentctl.actions.initialize import Initialize
38
from contentctl.objects.config import init, validate, build, new, deploy_acs, deploy_rest, test, test_servers, inspect, report, test_common, release_notes
49
from contentctl.actions.validate import Validate
510
from contentctl.actions.new_content import NewContent
@@ -9,14 +14,10 @@
914
DirectorOutputDto,
1015
Build,
1116
)
12-
1317
from contentctl.actions.test import Test
1418
from contentctl.actions.test import TestInputDto
1519
from contentctl.actions.reporting import ReportingInputDto, Reporting
1620
from contentctl.actions.inspect import Inspect
17-
import sys
18-
import warnings
19-
import pathlib
2021
from contentctl.input.yml_reader import YmlReader
2122
from contentctl.actions.release_notes import ReleaseNotes
2223

@@ -183,7 +184,7 @@ def main():
183184

184185

185186

186-
187+
config = None
187188
try:
188189
# Since some model(s) were constructed and not model_validated, we have to catch
189190
# warnings again when creating the cli
@@ -220,9 +221,18 @@ def main():
220221
else:
221222
raise Exception(f"Unknown command line type '{type(config).__name__}'")
222223
except Exception as e:
223-
import traceback
224-
traceback.print_exc()
225-
traceback.print_stack()
226-
#print(e)
224+
if config is None:
225+
print("There was a serious issue where the config file could not be created.\n"
226+
"The entire stack trace is provided below (please include it if filing a bug report).\n")
227+
traceback.print_exc()
228+
elif config.verbose:
229+
print("Verbose error logging is ENABLED.\n"
230+
"The entire stack trace has been provided below (please include it if filing a bug report):\n")
231+
traceback.print_exc()
232+
else:
233+
print("Verbose error logging is DISABLED.\n"
234+
"Please use the --verbose command line argument if you need more context for your error or file a bug report.")
235+
print(e)
236+
227237
sys.exit(1)
228238

contentctl/objects/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class Config_Base(BaseModel):
154154

155155
path: DirectoryPath = Field(default=DirectoryPath("."), description="The root of your app.")
156156
app:CustomApp = Field(default_factory=CustomApp)
157+
verbose:bool = Field(default=False, description="Enable verbose error logging, including a stacktrace. "
158+
"This option makes debugging contentctl errors much easier, but produces way more "
159+
"output than is useful under most uses cases. "
160+
"Please use this flag if you are submitting a bug report or issue on GitHub.")
157161

158162
@field_serializer('path',when_used='always')
159163
def serialize_path(path: DirectoryPath)->str:

contentctl/output/yml_writer.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,42 @@ class YmlWriter:
88
def writeYmlFile(file_path : str, obj : dict[Any,Any]) -> None:
99

1010
with open(file_path, 'w') as outfile:
11-
yaml.safe_dump(obj, outfile, default_flow_style=False, sort_keys=False)
11+
yaml.safe_dump(obj, outfile, default_flow_style=False, sort_keys=False)
12+
13+
@staticmethod
14+
def writeDetection(file_path: str, obj: dict[Any,Any]) -> None:
15+
output = dict()
16+
output["name"] = obj["name"]
17+
output["id"] = obj["id"]
18+
output["version"] = obj["version"]
19+
output["date"] = obj["date"]
20+
output["author"] = obj["author"]
21+
output["type"] = obj["type"]
22+
output["status"] = obj["status"]
23+
output["data_source"] = obj['data_sources']
24+
output["description"] = obj["description"]
25+
output["search"] = obj["search"]
26+
output["how_to_implement"] = obj["how_to_implement"]
27+
output["known_false_positives"] = obj["known_false_positives"]
28+
output["references"] = obj["references"]
29+
output["tags"] = obj["tags"]
30+
output["tests"] = obj["tags"]
31+
32+
YmlWriter.writeYmlFile(file_path=file_path, obj=output)
33+
34+
@staticmethod
35+
def writeStory(file_path: str, obj: dict[Any,Any]) -> None:
36+
output = dict()
37+
output['name'] = obj['name']
38+
output['id'] = obj['id']
39+
output['version'] = obj['version']
40+
output['date'] = obj['date']
41+
output['author'] = obj['author']
42+
output['description'] = obj['description']
43+
output['narrative'] = obj['narrative']
44+
output['references'] = obj['references']
45+
output['tags'] = obj['tags']
46+
47+
YmlWriter.writeYmlFile(file_path=file_path, obj=output)
48+
49+

contentctl/templates/app_template/default/distsearch.conf

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

0 commit comments

Comments
 (0)