new: Added Manifest and Markdown generators
parent
4999bb6172
commit
4e21962961
1048
MANIFEST.json
1048
MANIFEST.json
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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!')
|
|
@ -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!')
|
Loading…
Reference in New Issue