pass hub's host to single-user servers via hub_host

This commit is contained in:
Min RK
2016-02-26 13:40:35 +01:00
parent a4ae2ec2d8
commit a9b8542ec7
4 changed files with 20 additions and 14 deletions

View File

@@ -239,10 +239,6 @@ class JupyterHub(Application):
Only used when subdomains are involved.
"""
)
def _subdomain_host_default(self):
# FIXME: use xip.io for debugging
return (self.ip or '127.0.0.1') + '.xip.io:%i' % self.port
port = Integer(8000, config=True,
help="The public facing port of the proxy"
@@ -312,7 +308,6 @@ class JupyterHub(Application):
hub_ip = Unicode('127.0.0.1', config=True,
help="The ip for this process"
)
hub_prefix = URLPrefix('/hub/', config=True,
help="The prefix for the hub server. Must not be '/'"
)
@@ -598,11 +593,15 @@ class JupyterHub(Application):
q = self.db.query(orm.Hub)
assert q.count() <= 1
self._local.hub = q.first()
if self.use_subdomains:
self._local.hub.host = self.subdomain_host
return self._local.hub
@hub.setter
def hub(self, hub):
self._local.hub = hub
if self.use_subdomains:
hub.host = self.subdomain_host
@property
def proxy(self):
@@ -655,6 +654,10 @@ class JupyterHub(Application):
server.ip = self.hub_ip
server.port = self.hub_port
server.base_url = self.hub_prefix
if self.use_subdomains:
if not self.subdomain_host:
raise ValueError("Must specify subdomain_host when using subdomains."
" This should be the public domain[:port] of the Hub.")
self.db.commit()
@@ -793,9 +796,6 @@ class JupyterHub(Application):
)
self.db.add(self.proxy)
self.db.commit()
if self.use_subdomains:
# assert not ip-address (self.ip)
assert self.subdomain_host
self.proxy.auth_token = self.proxy_auth_token # not persisted
self.proxy.log = self.log
self.proxy.public_server.ip = self.ip

View File

@@ -253,6 +253,7 @@ class Hub(Base):
id = Column(Integer, primary_key=True)
_server_id = Column(Integer, ForeignKey('servers.id'))
server = relationship(Server, primaryjoin=_server_id == Server.id)
host = ''
@property
def api_url(self):

View File

@@ -199,6 +199,7 @@ class Spawner(LoggingConfigurable):
'--port=%i' % self.user.server.port,
'--cookie-name=%s' % self.user.server.cookie_name,
'--base-url=%s' % self.user.server.base_url,
'--hub-host=%s' % ('//' + self.hub.host) if self.hub.host else '',
'--hub-prefix=%s' % self.hub.server.base_url,
'--hub-api-url=%s' % self.hub.api_url,
]

View File

@@ -104,7 +104,9 @@ class JupyterHubLoginHandler(LoginHandler):
class JupyterHubLogoutHandler(LogoutHandler):
def get(self):
self.redirect(url_path_join(self.settings['hub_prefix'], 'logout'))
self.redirect(
self.settings['hub_host'] +
url_path_join(self.settings['hub_prefix'], 'logout'))
# register new hub related command-line aliases
@@ -113,6 +115,7 @@ aliases.update({
'user' : 'SingleUserNotebookApp.user',
'cookie-name': 'SingleUserNotebookApp.cookie_name',
'hub-prefix': 'SingleUserNotebookApp.hub_prefix',
'hub-host': 'SingleUserNotebookApp.hub_host',
'hub-api-url': 'SingleUserNotebookApp.hub_api_url',
'base-url': 'SingleUserNotebookApp.base_url',
})
@@ -141,6 +144,7 @@ class SingleUserNotebookApp(NotebookApp):
self.log.name = new
cookie_name = Unicode(config=True)
hub_prefix = Unicode(config=True)
hub_host = Unicode(config=True)
hub_api_url = Unicode(config=True)
aliases = aliases
open_browser = False
@@ -194,22 +198,22 @@ class SingleUserNotebookApp(NotebookApp):
s['user'] = self.user
s['hub_api_key'] = env.pop('JPY_API_TOKEN')
s['hub_prefix'] = self.hub_prefix
s['hub_host'] = self.hub_host
s['cookie_name'] = self.cookie_name
s['login_url'] = self.hub_prefix
s['login_url'] = self.hub_host + self.hub_prefix
s['hub_api_url'] = self.hub_api_url
s['csp_report_uri'] = url_path_join(self.hub_prefix, 'security/csp-report')
s['csp_report_uri'] = self.hub_host + url_path_join(self.hub_prefix, 'security/csp-report')
super(SingleUserNotebookApp, self).init_webapp()
self.patch_templates()
def patch_templates(self):
"""Patch page templates to add Hub-related buttons"""
self.jinja_template_vars['logo_url'] = url_path_join(self.hub_prefix, 'logo')
self.jinja_template_vars['logo_url'] = self.hub_host + url_path_join(self.hub_prefix, 'logo')
env = self.web_app.settings['jinja2_env']
env.globals['hub_control_panel_url'] = \
url_path_join(self.hub_prefix, 'home')
self.hub_host + url_path_join(self.hub_prefix, 'home')
# patch jinja env loading to modify page template
def get_page(name):