-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup-2.py
115 lines (90 loc) · 3.79 KB
/
setup-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/local/bin/python3
#-*- coding:utf-8 -*-
# This script reads the fusion-app/objects.json file and does the following:
# 1. Index Pipeline Stages and Query Pipeline Stages
# a. Delete stage 'id'
# b. Delete stage 'secretSourceStageId'
# 2. Parser Stages
# a. Delete stage 'id'
# 3. Blobs
# a. Generate a random md5 hash and replace existing hash
# 4. Object Groups and Links
# a. Each object in objectGroups has an id which is mapped to multiple
# objects in 'links' - Generated a new ids that replace each unique
# instances of the existing id
from pprint import pprint
import hashlib
import uuid
import json
import os
objects_json_file = "fusion-app/objects.json"
objects = {}
with open(objects_json_file, mode='r') as json_file:
objects = json.load(json_file)
indexPipelines = objects["objects"]["indexPipelines"]
queryPipelines = objects["objects"]["queryPipelines"]
parsers = objects["objects"]["parsers"]
blobs = objects["objects"]["blobs"]
links = objects["objects"]["links"]
objectGroups = objects["objects"]["objectGroups"]
# =============================================================
# 1. Index Pipeline Stages and Query Pipeline Stage
# =============================================================
for pipeline in indexPipelines:
for stage in pipeline["stages"]:
if "id" in stage:
del stage["id"]
if "secretSourceStageId" in stage:
del stage["secretSourceStageId"]
for pipeline in queryPipelines:
for stage in pipeline["stages"]:
if "id" in stage:
del stage["id"]
if "secretSourceStageId" in stage:
del stage["secretSourceStageId"]
# Update objects json with modified indexPipelines and queryPipelines
objects["objects"]["indexPipelines"] = indexPipelines
objects["objects"]["queryPipelines"] = queryPipelines
# =============================================================
# 2. Parser Stages
# =============================================================
for parser in parsers:
for stage in parser["parserStages"]:
if "id" in stage:
del stage["id"]
# Update parsers in objects
objects["objects"]["parsers"] = parsers
# =============================================================
# 3. Blobs
# - Generate new md5 hash using id for each blob object
# =============================================================
for blob in blobs:
if "id" in blob:
idHash = hashlib.md5(blob["id"].encode())
blob["md5"] = idHash.hexdigest()
# Update blobs in objects
objects["objects"]["blobs"] = blobs
# =============================================================
# 4. Object Groups and Links
# =============================================================
# newObjectGroups = []
for group in objectGroups:
if "id" in group:
groupID = group["id"]
# Generate a new UUID using group name - using uuid1()
newGroupID = str(uuid.uuid1())
# Set the group's id to the new UUID
group["id"] = newGroupID
# Iterate through each link item and
for link in links:
if link["subject"] == "group:"+groupID:
link["subject"] = "group:"+newGroupID
# Update links in objects
objects["objects"]["links"] = links
# Update objectGroups in objects
objects["objects"]["objectGroups"] = objectGroups
json_file.close()
# Overwrite the objects.json file with the modified objects json
with open(objects_json_file, mode='w') as json_file:
json.dump(objects, json_file, indent=2)
json_file.close()