forked from jupyterhub/binderhub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
48 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
helm-chart/binderhub/files/etc/jupyterhub/binder_spawner.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import z2jh | ||
from tornado import web | ||
from kubespawner import KubeSpawner | ||
|
||
# get cors config from values.custom.cors | ||
cors = z2jh.get_config('custom.cors', {}) | ||
|
||
|
||
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): | ||
# image & token are set via spawn options | ||
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() | ||
|
||
def get_env(self): | ||
env = super(BinderSpawner, self).get_env() | ||
if 'repo_url' in self.user_options: | ||
env['BINDER_REPO_URL'] = self.user_options['repo_url'] | ||
for key in ( | ||
'binder_ref_url', | ||
'binder_launch_host', | ||
'binder_persistent_request', | ||
'binder_request'): | ||
if key in self.user_options: | ||
env[key.upper()] = self.user_options[key] | ||
return env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters