Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up output order #164

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions contentctl/actions/new_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def buildDetection(self)->dict[str,Any]:
answers['date'] = datetime.today().strftime('%Y-%m-%d')
answers['author'] = answers['detection_author']
del answers['detection_author']
answers['data_source'] = answers['data_source']
answers['data_sources'] = answers['data_source']
del answers['data_source']
answers['type'] = answers['detection_type']
del answers['detection_type']
answers['status'] = "production" #start everything as production since that's what we INTEND the content to become
Expand All @@ -49,6 +50,7 @@ def buildDetection(self)->dict[str,Any]:
answers['tags']['required_fields'] = ['UPDATE']
answers['tags']['risk_score'] = 'UPDATE (impact * confidence)/100'
answers['tags']['security_domain'] = answers['security_domain']
del answers["security_domain"]
answers['tags']['cve'] = ['UPDATE WITH CVE(S) IF APPLICABLE']

#generate the tests section
Expand All @@ -64,6 +66,7 @@ def buildDetection(self)->dict[str,Any]:
]
}
]
del answers["mitre_attack_ids"]
return answers

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

YmlWriter.writeYmlFile(file_path, object)
YmlWriter.writeDetection(file_path, object)
print("Successfully created detection " + file_path)

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

else:
Expand Down
40 changes: 39 additions & 1 deletion contentctl/output/yml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,42 @@ class YmlWriter:
def writeYmlFile(file_path : str, obj : dict[Any,Any]) -> None:

with open(file_path, 'w') as outfile:
yaml.safe_dump(obj, outfile, default_flow_style=False, sort_keys=False)
yaml.safe_dump(obj, outfile, default_flow_style=False, sort_keys=False)

@staticmethod
def writeDetection(file_path: str, obj: dict[Any,Any]) -> None:
output = dict()
output["name"] = obj["name"]
output["id"] = obj["id"]
output["version"] = obj["version"]
output["date"] = obj["date"]
output["author"] = obj["author"]
output["type"] = obj["type"]
output["status"] = obj["status"]
output["data_source"] = obj['data_sources']
output["description"] = obj["description"]
output["search"] = obj["search"]
output["how_to_implement"] = obj["how_to_implement"]
output["known_false_positives"] = obj["known_false_positives"]
output["references"] = obj["references"]
output["tags"] = obj["tags"]
output["tests"] = obj["tags"]

YmlWriter.writeYmlFile(file_path=file_path, obj=output)

@staticmethod
def writeStory(file_path: str, obj: dict[Any,Any]) -> None:
output = dict()
output['name'] = obj['name']
output['id'] = obj['id']
output['version'] = obj['version']
output['date'] = obj['date']
output['author'] = obj['author']
output['description'] = obj['description']
output['narrative'] = obj['narrative']
output['references'] = obj['references']
output['tags'] = obj['tags']

YmlWriter.writeYmlFile(file_path=file_path, obj=output)


Loading