Skip to content

Commit 20c9b57

Browse files
committed
Cleaning up output order
1 parent d94aa7b commit 20c9b57

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
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/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+

0 commit comments

Comments
 (0)