Repository navigation
Expand file tree
/
Copy pathsetup_girder.py
More file actions
executable file
·188 lines (172 loc) · 6.91 KB
/
Copy pathsetup_girder.py
File metadata and controls
executable file
·188 lines (172 loc) · 6.91 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python3
import json
import requests
import time
import os
import sys
params = {
"login": "admin",
"email": "root@dev.null",
"firstName": "John",
"lastName": "Doe",
"password": "arglebargle123",
"admin": True,
}
headers = {"Content-Type": "application/json", "Accept": "application/json"}
domain = os.environ.get("domain", "local.xarthisius.xyz")
def final_msg():
print("-------------- You should be all set!! -------------")
print(f"try going to https://girder.{domain} and log in with: ")
print(" user : %s" % params["login"])
print(" pass : %s" % params["password"])
api_url = f"https://girder.{domain}/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": "/srv/data/base",
},
)
print("Setting up Plugin")
# ORCID and its sandbox are separate OAuth providers with separate client
# credentials and separate callback URLs; both can be enabled at once. The
# sandbox one only shows up if its credentials are in the environment.
enabled_oauth_providers = ["globus", "orcid"]
jsonforms_orcid_provider = "orcid"
jsonforms_research_resources = False
if os.environ.get("ORCID_SANDBOX_CLIENT_ID"):
enabled_oauth_providers.append("orcid_sandbox")
# girder-jsonforms defaults to production ORCID with research-resource
# registration off, because only the sandbox has the "/activities/update"
# scope that write needs. Configuring sandbox credentials on a dev stack
# means we want both pointed at the sandbox, so the feature stays
# exercised somewhere. Drop the second line to leave it off in dev too.
jsonforms_orcid_provider = "orcid_sandbox"
jsonforms_research_resources = True
settings = [
{
"key": "core.cors.allow_origin",
"value": (
f"https://dashboard.{domain},https://projects.{domain}"
",http://localhost:4200,http://localhost:5173"
),
},
{
"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": f".{domain}"},
# Girder builds absolute links off this. Left unset it defaults to empty,
# and anything joining it into a URL silently produces a relative one --
# which is how an IGSN landing page went to DataCite as "#igsn/JHBBMX00001"
# and came back 422 "URL is not valid".
{"key": "core.server_root", "value": f"https://girder.{domain}"},
{"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.orcid_sandbox_client_id",
"value": os.environ.get("ORCID_SANDBOX_CLIENT_ID", ""),
},
{
"key": "oauth.orcid_sandbox_client_secret",
"value": os.environ.get("ORCID_SANDBOX_CLIENT_SECRET", ""),
},
{"key": "oauth.providers_enabled", "value": enabled_oauth_providers},
{"key": "jsonforms.orcid_provider", "value": jsonforms_orcid_provider},
{
"key": "jsonforms.orcid_research_resources",
"value": jsonforms_research_resources,
},
# {"key": "dm.globus_gc_dir", "value": "/opt/globusconnectpersonal"},
# {
# "key": "wholetale.zenodo_extra_hosts",
# "value": ["https://sandbox.zenodo.org/record/"]
# },
{"key": "dm.private_storage_path", "value": "/srv/data/ps"},
{"key": "wholetale.homes_root", "value": "/srv/data/homes"},
{"key": "wholetale.workspaces_root", "value": "/srv/data/workspaces"},
{"key": "wholetale.runs_root", "value": "/srv/data/runs"},
{"key": "wholetale.versions_root", "value": "/srv/data/versions"},
{"key": "wholetale.dashboard_link_title", "value": "Tale Dashboard"},
{"key": "wholetale.catalog_link_title", "value": "Data Catalog"},
{"key": "wholetale.enable_data_catalog", "value": True},
]
# Centralized IGSN registry. Leaving IGSN_SERVICE_TOKEN unset keeps this Girder
# in local mode, where it allocates identifiers from its own counter exactly as
# it always has -- which is what you want until the registry has been backfilled
# from every instance. To switch over, mint a token with
#
# docker exec -it $(docker ps -qf name=wt_igsn) \
# igsn-service create-tenant --slug dev-girder --name 'Dev Girder' \
# --doi-prefix 10.83961 --repository-id jhu.igsn-test \
# --password-env DATACITE_PW_TEST --api-base https://api.test.datacite.org \
# --landing-template "https://girder.${domain}/#igsn/{igsn}"
#
# and put it in .env as igsn_service_token.
igsn_service_token = os.environ.get("IGSN_SERVICE_TOKEN")
if igsn_service_token:
settings += [
# In-cluster address: both services sit on traefik-net, so plugin
# traffic skips the proxy. The public igsn.<domain> router is for the
# resolver that published DOIs point at.
{"key": "jsonforms.igsn_service_url", "value": "http://igsn:8000"},
{"key": "jsonforms.igsn_service_token", "value": igsn_service_token},
]
else:
print(
"IGSN_SERVICE_TOKEN is unset; leaving Girder in local IGSN mode "
"(it will allocate identifiers from its own counter)."
)
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()