Merge branch 'Haagust' of https://github.com/splunk/security_content into Haagust

This commit is contained in:
mhaag-spl
2021-08-18 10:54:38 -06:00
+2 -95
View File
@@ -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)
@@ -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:
@@ -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':
@@ -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:
@@ -265,4 +172,4 @@ def main(args):
if __name__ == "__main__":
main(sys.argv[1:])
main(sys.argv[1:])