-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_copy.py
More file actions
110 lines (82 loc) · 4.32 KB
/
Copy pathmain_copy.py
File metadata and controls
110 lines (82 loc) · 4.32 KB
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
import requests
import json
from methods import init_session
from methods import recursively_get_parameters, convert_event_from_get_to_post
from methods import check_for_prefix
rh, settings, src_project, target_project = init_session(validate_src=True, validate_target=True)
org_id = settings["srcOrgId"]
project_id = settings["srcProjectId"]
environment_id = settings["srcEnvId"]
target_environment_id = settings["trgtEnvId"]
target_project_id = settings["trgtProjectId"]
target_org_id = settings["trgtOrgId"]
print("-------------------------------------------------")
print("Here's a link to the SOURCE project:")
print(f"https://cloud.unity.com/home/organizations/{org_id}/projects/{project_id}/settings/environments/{environment_id}")
input("If this is correct, press enter to continue... If not, terminate the script and change the settings.json file.")
print("-------------------------------------------------")
print("Here's a link to the TARGET project:")
print(f"https://cloud.unity.com/home/organizations/{target_org_id}/projects/{target_project_id}/settings/environments/{target_environment_id}")
input("If this is correct, press enter to continue... If not, terminate the script and change the settings.json file. \n THERE WILL BE NO FURTHER CONFIRMATIONS.")
print("thanks! beginning...")
#------------------------------get the source schemas and parameters--------------------
src_schemas = rh.get_schemas(org_id, project_id, environment_id)
if not src_schemas:
print("No schemas found in source project. This probably means your token is expired. Look in the cookie for https://cloud.unity.com/, under 'token'.")
print("Store the latest token in token.auth and re-run the script.")
print("Exiting...")
exit(1)
schema_names = [x["name"] for x in src_schemas if not x["isRestricted"] ]
src_schemas = {x["name"]: x for x in src_schemas}
needed_parameter_names = {}
needed_schemas = {}
for schema_name in schema_names:
print(f"fetching source event {schema_name}")
resp = rh.get_schema_by_id(org_id, project_id, environment_id, schema_name)
if not resp:
continue
needed_schemas[schema_name] = resp
if resp["isRestricted"]:
continue
for parameter in resp["parameters"]:
recursively_get_parameters(parameter, existing_dict=needed_parameter_names)
# read token from token.auth
#-------------------------------get the target schemas and parameters--------------------
#-------------------------------these already exist, and should not be created--------------------
destination_events = rh.get_schemas(target_org_id, target_project_id, target_environment_id)
destination_events = {x["name"]: x for x in destination_events}
destination_params = rh.get_parameters(target_org_id, target_project_id, target_environment_id)
destination_params = {x["name"]: x for x in destination_params}
for name,parameter in needed_parameter_names.items():
if name in destination_params:
print(f"Parameter {name} already exists in destination")
continue
else:
print(f"Creating parameter {name}")
target_body = (parameter)
if not check_for_prefix(name):
print(f"Parameter {name} has a reserved prefix. Skipping.")
continue
try:
resp = rh.create_parameter(target_org_id, target_project_id, target_environment_id, parameter["name"], parameter["type"], parameter["description"], parameter.get("format",None), parameter.get("enumeration",None))
except ValueError as e:
print(f"Error creating parameter {name}: {e}")
continue
if not resp:
print(f"Failed to create parameter {name}")
continue
for schema_name in needed_schemas:
if schema_name not in destination_events:
print(f"Creating event {schema_name}")
target_body = convert_event_from_get_to_post(needed_schemas[schema_name])
if not check_for_prefix(schema_name):
print(f"event {schema_name} has a reserved prefix. Skipping.")
continue
resp = rh.create_event(target_org_id, target_project_id, target_environment_id, target_body)
if not resp:
print(f"Failed to create event {schema_name}")
continue
else:
print(f"Event {schema_name} already exists in destination")
pass
# compare the keys of