new: Added Manifest and Markdown generators

feature-exclusive
mokaddem 2019-11-05 12:00:28 +01:00
parent 4999bb6172
commit 4e21962961
5 changed files with 1779 additions and 526 deletions

File diff suppressed because it is too large Load Diff

1156
Summary.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -567,4 +567,4 @@
]
}
]
}
}

48
tools/gen_manifest.py Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
import json
from pathlib import Path
from datetime import datetime
TAXONOMY_ROOT_PATH = Path(__file__).resolve().parent.parent
def fetchTaxonomies():
taxonomiesFolder = TAXONOMY_ROOT_PATH
taxonomies = []
for taxonomyFile in taxonomiesFolder.glob('./*/machinetag.json'):
with open(taxonomyFile) as f:
taxonomy = json.load(f)
taxonomies.append(taxonomy)
return taxonomies
def generateManifest(taxonomies):
manifest = {}
manifest['taxonomies'] = []
manifest['path'] = 'machinetag.json'
manifest['url'] = 'https://raw.githubusercontent.com/MISP/misp-taxonomies/master/'
manifest['description'] = 'Manifest file of MISP taxonomies available.'
manifest['license'] = 'CC-0'
now = datetime.now()
manifest['version'] = '{}{:02}{:02}'.format(now.year, now.month, now.day)
for taxonomy in taxonomies:
taxObj = {
'name': taxonomy['namespace'],
'description': taxonomy['description'],
'version': taxonomy['version']
}
manifest['taxonomies'].append(taxObj)
return manifest
def saveManifest(manifest):
with open(TAXONOMY_ROOT_PATH / 'MANIFEST.json', 'w') as f:
json.dump(manifest, f, indent=2, sort_keys=True)
def awesomePrint(text):
print('\033[1;32m{}\033[0;39m'.format(text))
if __name__ == "__main__":
taxonomies = fetchTaxonomies()
manifest = generateManifest(taxonomies)
saveManifest(manifest)
awesomePrint('> Manifest saved!')

49
tools/gen_markdown.py Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env python3
import json
from pathlib import Path
from datetime import datetime
TAXONOMY_ROOT_PATH = Path(__file__).resolve().parent.parent
def fetchTaxonomies():
taxonomiesFolder = TAXONOMY_ROOT_PATH
taxonomies = []
for taxonomyFile in taxonomiesFolder.glob('./*/machinetag.json'):
with open(taxonomyFile) as f:
taxonomy = json.load(f)
taxonomies.append(taxonomy)
return taxonomies
def generateMarkdown(taxonomies):
markdown_line_array = []
markdown_line_array.append("# Taxonomies")
markdown_line_array.append("- Generation date: %s" % datetime.now().isoformat().split('T')[0])
markdown_line_array.append("- license: %s" % 'CC-0')
markdown_line_array.append("- description: %s" % 'Manifest file of MISP taxonomies available.')
markdown_line_array.append("")
markdown_line_array.append("## Taxonomies")
markdown_line_array.append("")
for taxonomy in taxonomies:
markdown_line_array.append("### %s" % taxonomy['namespace'])
markdown_line_array.append("- description: %s" % taxonomy['description'])
markdown_line_array.append("- version: %s" % taxonomy['version'])
markdown_line_array.append("- Predicates")
markdown_line_array = markdown_line_array + [' - '+p['value'] for p in taxonomy['predicates']]
markdown = '\n'.join(markdown_line_array)
return markdown
def saveMarkdown(markdown):
with open(TAXONOMY_ROOT_PATH / 'Summary.md', 'w') as f:
f.write(markdown)
def awesomePrint(text):
print('\033[1;32m{}\033[0;39m'.format(text))
if __name__ == "__main__":
taxonomies = fetchTaxonomies()
markdown = generateMarkdown(taxonomies)
saveMarkdown(markdown)
awesomePrint('> Markdown saved!')