Skip to content
Snippets Groups Projects
Commit baf5fa6f authored by Tim Kreuzer's avatar Tim Kreuzer
Browse files

support old shares

parent 03735449
Branches
Tags
No related merge requests found
......@@ -32,6 +32,59 @@ class ShareUserOptionsSpawnHandler(SpawnHandler):
"home.html", for_user=for_user, auth_state=auth_state, row=server_name
)
def upgrade_user_options(self, user_options):
# In the past we had a different structure for our share user options
# To support old share links, we have to upgrade them to the newest structure
if user_options.get("profile", "").startswith("JupyterLab/"):
name = user_options.get("name", "Unnamed")
option_dict = {
"JupyterLab/repo2docker": "repo2docker",
"JupyterLab/custom": "custom",
}
profile = option = option_dict.get(user_options.get("profile", ""))
service = "jupyterlab"
secret_keys = []
system = user_options.get("system", "unknown")
flavor = user_options.get("flavor", None)
r2dnotebooktype = user_options.get("notebook_type", "file")
r2drepo = user_options.get("repo", None)
if r2drepo and r2drepo.startswith("https://github.com/"):
r2dtype = "gh"
r2drepo = r2drepo[len("https://github.com/") :]
else:
r2dtype = "git"
r2dgitref = user_options.get("gitref", "")
r2dnotebook = user_options.get("notebook", None)
ret = {
"name": name,
"service": service,
"option": option,
"profile": profile,
"system": system,
"secrets": secret_keys,
}
if flavor:
ret["flavor"] = flavor
if r2drepo:
ret["repo2docker"] = {
"repotype": r2dtype,
"repourl": r2drepo,
"reporef": r2dgitref,
}
if r2dnotebook:
ret["repo2docker"]["repopath"] = r2dnotebook
ret["repo2docker"]["repopathtype"] = r2dnotebooktype
image = user_options.get("image", None)
if image:
ret["custom"] = {"customimage": image}
userdata_path = user_options.get("userdata_path", None)
if userdata_path:
ret["storage"] = {"localstoragepath": userdata_path}
return True, ret
else:
return False, user_options
@web.authenticated
async def get(self, secret):
user = self.current_user
......@@ -52,8 +105,12 @@ class ShareUserOptionsSpawnHandler(SpawnHandler):
server_name = generate_random_id()
spawner = user.get_spawner(server_name, replace_failed=True)
spawner.user_options = db_entry.user_options
upgrade, user_options = self.upgrade_user_options(db_entry.user_options)
if upgrade:
db_entry.user_options = user_options
self.db.add(db_entry)
self.db.commit()
spawner.user_options = user_options
service = db_entry.user_options.get("service", "jupyterlab")
spawner.user_options["share_id"] = secret
spawner.orm_spawner.user_options = db_entry.user_options
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment