-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
It looks like all the BinderSpawner code is kept as an extra config and plonked into the spawner ( c.JupyterHub.spawner_class = BinderSpawner). As such, you can get the entire query string from hub_login_url and the current profile_list from c.KubeSpawner.profile_list. c.KubeSpawner.profile_list[0] is then the default profile which can be switched in based on whatever you like. I'd think the easiest (safest) would be having a list of profiles baked in that the user could choose from (profile 1/2/3 with details somewhere); the simpler but more dangerous option is letting the user provide a JSON in the query string that is taken as the profile.
Example:
# extraConfig:
# binder: |
import os
import sys
import yaml
from tornado import web
# get cors config from values.custom.cors
import z2jh
cors = z2jh.get_config('custom.cors', {})
# image & token are set via spawn options
from kubespawner import KubeSpawner
class BinderSpawner(KubeSpawner):
def get_args(self):
args = [
'--ip=0.0.0.0',
'--port=%i' % self.port,
'--NotebookApp.base_url=%s' % self.server.base_url,
'--NotebookApp.token=%s' % self.user_options['token'],
'--NotebookApp.trust_xheaders=True',
]
allow_origin = cors.get('allowOrigin')
if allow_origin:
args.append('--NotebookApp.allow_origin=' + allow_origin)
return args + self.args
def start(self):
if 'token' not in self.user_options:
raise web.HTTPError(400, "token required")
if 'image' not in self.user_options:
raise web.HTTPError(400, "image required")
self.image = self.user_options['image']
return super().start()
hub_login_url = c.BinderHub.hub_login_url
def get_json_profile_from_url(hub_login_url):
json = hub_login_url.get_query("profile={json}")
# self.profile_json = json
return json
c.JupyterHub.spawner_class = BinderSpawner
default = c.KubeSpawner.profile_list[0]
c.KubeSpawner.profile_list = [get_json_profile_from_url(hub_login_url)]
Metadata
Metadata
Assignees
Labels
No labels