Skip to content
Merged
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
97 changes: 2 additions & 95 deletions bin/pretty_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,96 +55,6 @@ def pretty_yaml_detections(REPO_PATH, VERBOSE, content_part):
pretty_yaml['tags'] = {key: value for key, value in sorted(object['tags'].items())}


with open(manifest_file, 'w') as file:
documents = yaml.dump(pretty_yaml, file, sort_keys=False)

return manifest_files

def pretty_yaml_baselines(REPO_PATH, VERBOSE, content_part):
manifest_files = []
for root, dirs, files in walk(REPO_PATH + "/" + content_part + '/'):
for file in files:
if file.endswith(".yml"):
manifest_files.append((path.join(root, file)))

for manifest_file in manifest_files:
pretty_yaml = dict()
if VERBOSE:
print("processing manifest {0}".format(manifest_file))

with open(manifest_file, 'r') as stream:
try:
object = list(yaml.safe_load_all(stream))[0]
except yaml.YAMLError as exc:
print(exc)
print("Error reading {0}".format(manifest_file))
error = True
continue

pretty_yaml['name'] = object['name']
pretty_yaml['id'] = object['id']
pretty_yaml['version'] = object['version']
pretty_yaml['date'] = object['date']
pretty_yaml['author'] = object['author']
pretty_yaml['type'] = object['type']
pretty_yaml['datamodel'] = object['datamodel']
pretty_yaml['description'] = object['description']
pretty_yaml['search'] = object['search']
if 'how_to_implement' in object:
pretty_yaml['how_to_implement'] = object['how_to_implement']
else:
pretty_yaml['how_to_implement'] = ''
if 'references' in object:
pretty_yaml['references'] = object['references']
else:
pretty_yaml['references'] = []
pretty_yaml['tags'] = {key: value for key, value in sorted(object['tags'].items())}

with open(manifest_file, 'w') as file:
documents = yaml.dump(pretty_yaml, file, sort_keys=False)

return manifest_files

def pretty_yaml_baselines(REPO_PATH, VERBOSE, content_part):
manifest_files = []
for root, dirs, files in walk(REPO_PATH + "/" + content_part + '/'):
for file in files:
if file.endswith(".yml"):
manifest_files.append((path.join(root, file)))

for manifest_file in manifest_files:
pretty_yaml = dict()
if VERBOSE:
print("processing manifest {0}".format(manifest_file))

with open(manifest_file, 'r') as stream:
try:
object = list(yaml.safe_load_all(stream))[0]
except yaml.YAMLError as exc:
print(exc)
print("Error reading {0}".format(manifest_file))
error = True
continue

pretty_yaml['name'] = object['name']
pretty_yaml['id'] = object['id']
pretty_yaml['version'] = object['version']
pretty_yaml['date'] = object['date']
pretty_yaml['author'] = object['author']
pretty_yaml['type'] = object['type']
pretty_yaml['datamodel'] = object['datamodel']
pretty_yaml['description'] = object['description']
pretty_yaml['search'] = object['search']
if 'how_to_implement' in object:
pretty_yaml['how_to_implement'] = object['how_to_implement']
else:
pretty_yaml['how_to_implement'] = ''
if 'references' in object:
pretty_yaml['references'] = object['references']
else:
pretty_yaml['references'] = []
pretty_yaml['tags'] = {key: value for key, value in sorted(object['tags'].items())}

with open(manifest_file, 'w') as file:
documents = yaml.dump(pretty_yaml, file, sort_keys=False)

Expand Down Expand Up @@ -212,7 +122,6 @@ def pretty_yaml_stories(REPO_PATH, VERBOSE, content_part):
pretty_yaml['version'] = object['version']
pretty_yaml['date'] = object['date']
pretty_yaml['author'] = object['author']
pretty_yaml['type'] = object['type']
pretty_yaml['description'] = object['description']
pretty_yaml['narrative'] = object['narrative']
if 'references' in object:
Expand All @@ -231,8 +140,6 @@ def pretty_yaml(REPO_PATH, VERBOSE, content_part):
manifest_files = []
if content_part == 'detections':
manifest_files = pretty_yaml_detections(REPO_PATH, VERBOSE, content_part)
elif content_part == 'baselines':
manifest_files = pretty_yaml_baselines(REPO_PATH, VERBOSE, content_part)
elif content_part == 'deployments':
manifest_files = pretty_yaml_deployments(REPO_PATH, VERBOSE, content_part)
elif content_part == 'stories':
Expand All @@ -252,7 +159,7 @@ def main(args):
REPO_PATH = args.path
VERBOSE = args.verbose
output = []
pretty_yaml_objects = ['macros','lookups','stories','detections','baselines','response_tasks','responses','deployments']
pretty_yaml_objects = ['macros','lookups','stories','detections','response_tasks','responses','deployments']
for pretty_yaml_object in pretty_yaml_objects:
touch_count = pretty_yaml(REPO_PATH, VERBOSE, pretty_yaml_object)
if VERBOSE:
Expand All @@ -265,4 +172,4 @@ def main(args):


if __name__ == "__main__":
main(sys.argv[1:])
main(sys.argv[1:])