-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup_girder.py
executable file
·165 lines (147 loc) · 4.78 KB
/
setup_girder.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
import json
import requests
import time
import os
import sys
params = {
"login": "admin",
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"password": "arglebargle123",
"admin": True,
}
headers = {"Content-Type": "application/json", "Accept": "application/json"}
def final_msg():
print("-------------- You should be all set!! -------------")
print("try going to https://girder.local.wholetale.org and log in with: ")
print(" user : %s" % params["login"])
print(" pass : %s" % params["password"])
api_url = "https://girder.local.wholetale.org/api/v1"
# Give girder time to start
while True:
print("Waiting for Girder to start")
r = requests.get(api_url)
if r.status_code == 200:
break
time.sleep(2)
print("Creating admin user")
r = requests.post(api_url + "/user", params=params, headers=headers)
if r.status_code == 400:
print("Admin user already exists. Database was not purged.")
print("If that is OK:")
final_msg()
sys.exit()
# Store token for future requests
headers["Girder-Token"] = r.json()["authToken"]["token"]
print("Creating default assetstore")
r = requests.post(
api_url + "/assetstore",
headers=headers,
params={
"type": 0,
"name": "Base",
"root": "/tmp/data/base",
},
)
print("Enabling plugins")
plugins = [
"oauth",
"gravatar",
"jobs",
"worker",
"globus_handler",
"virtual_resources",
"wt_data_manager",
"wholetale",
"wt_home_dir",
"wt_versioning",
]
r = requests.put(
api_url + "/system/plugins",
headers=headers,
params={"plugins": json.dumps(plugins)},
)
r.raise_for_status()
print("Restarting girder to load plugins")
r = requests.put(api_url + "/system/restart", headers=headers)
r.raise_for_status()
# Give girder time to restart
while True:
print("Waiting for Girder to restart")
r = requests.get(
api_url + "/oauth/provider",
headers=headers,
params={"redirect": "http://blah.com"},
)
if r.status_code == 200:
break
time.sleep(2)
print("Setting up Plugin")
settings = [
{
"key": "core.cors.allow_origin",
"value": "https://dashboard.local.wholetale.org,http://localhost:4200,https://legacy.local.wholetale.org",
},
{
"key": "core.cors.allow_headers",
"value": (
"Accept-Encoding, Authorization, Content-Disposition, Set-Cookie, "
"Content-Type, Cookie, Girder-Authorization, Girder-Token, "
"X-Requested-With, X-Forwarded-Server, X-Forwarded-For, "
"X-Forwarded-Host, Remote-Addr, Cache-Control"
),
},
{"key": "core.cookie_domain", "value": ".local.wholetale.org"},
{"key": "core.secure_cookie", "value": True},
{"key": "worker.api_url", "value": "http://girder:8080/api/v1"},
{"key": "worker.broker", "value": "redis://redis/"},
{"key": "worker.backend", "value": "redis://redis/"},
{"key": "oauth.globus_client_id", "value": os.environ.get("GLOBUS_CLIENT_ID")},
{
"key": "oauth.globus_client_secret",
"value": os.environ.get("GLOBUS_CLIENT_SECRET"),
},
{"key": "oauth.orcid_client_id", "value": os.environ.get("ORCID_CLIENT_ID")},
{
"key": "oauth.orcid_client_secret",
"value": os.environ.get("ORCID_CLIENT_SECRET"),
},
{"key": "oauth.providers_enabled", "value": ["globus"]},
{"key": "dm.globus_gc_dir", "value": "/opt/globusconnectpersonal"},
{
"key": "wholetale.dataverse_extra_hosts",
"value": ["dev2.dataverse.org", "demo.dataverse.org"],
},
{
"key": "wholetale.zenodo_extra_hosts",
"value": ["https://sandbox.zenodo.org/record/"]
},
{"key": "dm.private_storage_path", "value": "/tmp/data/ps"},
{"key": "wthome.homedir_root", "value": "/tmp/data/homes"},
{"key": "wthome.taledir_root", "value": "/tmp/data/workspaces"},
{"key": "wtversioning.runs_root", "value": "/tmp/data/runs"},
{"key": "wtversioning.versions_root", "value": "/tmp/data/versions"},
]
r = requests.put(
api_url + "/system/setting", headers=headers, params={"list": json.dumps(settings)}
)
try:
r.raise_for_status()
except requests.exceptions.HTTPError:
if r.status_code >= 400 and r.status_code < 500:
print(f"Request died with {r.status_code}: {r.reason}")
print(f"Returned: {r.text}")
raise
with open("dev_images.json", "r") as fp:
images = json.load(fp)
for image in images:
print(f"Creating {image['name']} image")
image["config"] = json.dumps(image["config"])
r = requests.post(api_url + "/image", headers=headers, params=image)
r.raise_for_status()
print("Restarting girder to update WebDav roots")
r = requests.put(api_url + "/system/restart", headers=headers)
r.raise_for_status()
final_msg()