misp-galaxy/tools/add_missing_uuid.py

25 lines
649 B
Python
Raw Permalink Normal View History

2018-10-12 10:41:19 +02:00
#!/usr/bin/env python3
2018-02-28 15:37:37 +01:00
# -*- coding: utf-8 -*-
import json
import argparse
import uuid
parser = argparse.ArgumentParser(description='Add missing uuids in clusters')
parser.add_argument("-f", "--filename", required=True, help="name of the cluster")
2018-02-28 15:37:37 +01:00
args = parser.parse_args()
2018-10-12 10:41:19 +02:00
if 'mitre-' in args.filename:
exit()
with open(args.filename) as json_file:
2018-02-28 15:37:37 +01:00
data = json.load(json_file)
json_file.close()
for value in data['values']:
2018-10-12 10:41:19 +02:00
if not value.get('uuid'):
2018-02-28 15:37:37 +01:00
value['uuid'] = str(uuid.uuid4())
with open(args.filename, 'w') as json_file:
2018-10-12 10:41:19 +02:00
json.dump(data, json_file, indent=2, sort_keys=True, ensure_ascii=False)