fix: automatically fix missing uuids

pull/283/head
Christophe Vandeplas 2018-10-12 10:41:19 +02:00
bovenliggende 2fbd8ce485
commit 65eb66a739
4 gewijzigde bestanden met toevoegingen van 10 en 5 verwijderingen

Bestand weergeven

@ -899,6 +899,7 @@
"https://www.bleepingcomputer.com/news/security/new-iot-botnet-torii-uses-six-methods-for-persistence-has-no-clear-purpose/"
]
},
"uuid": "92f38212-94e2-4d70-9b5e-e977eb1e7b79",
"value": "Torii"
},
{

Bestand weergeven

@ -13413,7 +13413,7 @@
"synonyms": [],
"type": []
},
"uuid": "",
"uuid": "39f609e3-e6fe-4c2c-af0e-b28bc81b2ecf",
"value": ""
},
{
@ -14429,7 +14429,7 @@
"synonyms": [],
"type": []
},
"uuid": "",
"uuid": "4db80a62-d318-48e7-b70b-759924ff515e",
"value": ""
},
{

Bestand weergeven

@ -17,6 +17,7 @@ set -x
for dir in clusters/*.json
do
python3 tools/add_missing_uuid.py -f ${dir}
# Beautify it
cat ${dir} | jq --sort-keys . | sponge ${dir}
done

9
tools/add_missing_uuid.py Normal file → Executable file
Bestand weergeven

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
@ -9,13 +9,16 @@ parser = argparse.ArgumentParser(description='Add missing uuids in clusters')
parser.add_argument("-f", "--filename", required=True, help="name of the cluster")
args = parser.parse_args()
if 'mitre-' in args.filename:
exit()
with open(args.filename) as json_file:
data = json.load(json_file)
json_file.close()
for value in data['values']:
if 'uuid' not in value:
if not value.get('uuid'):
value['uuid'] = str(uuid.uuid4())
with open(args.filename, 'w') as json_file:
json.dump(data, json_file, indent=4)
json.dump(data, json_file, indent=2, sort_keys=True, ensure_ascii=False)