Spawner.start can return a URL

enables internal HTTPS, if setup by the Spawner
This commit is contained in:
Min RK
2018-05-03 16:41:02 +02:00
parent 3cae550b13
commit 804a9b7be8

View File

@@ -401,15 +401,30 @@ class User:
f = maybe_future(spawner.start()) f = maybe_future(spawner.start())
# commit any changes in spawner.start (always commit db changes before yield) # commit any changes in spawner.start (always commit db changes before yield)
db.commit() db.commit()
ip_port = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f) url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
if ip_port: if url:
# get ip, port info from return value of start() # get ip, port info from return value of start()
server.ip, server.port = ip_port if isinstance(url, str):
# >= 0.9 can return a full URL string
pass
else:
# >= 0.7 returns (ip, port)
url = 'http://%s:%i' % url
urlinfo = urlparse(url)
server.proto = urlinfo.scheme
server.ip = urlinfo.hostname
port = urlinfo.port
if not port:
if urlinfo.scheme == 'https':
port = 443
else:
port = 80
server.port = port
db.commit() db.commit()
else: else:
# prior to 0.7, spawners had to store this info in user.server themselves. # prior to 0.7, spawners had to store this info in user.server themselves.
# Handle < 0.7 behavior with a warning, assuming info was stored in db by the Spawner. # Handle < 0.7 behavior with a warning, assuming info was stored in db by the Spawner.
self.log.warning("DEPRECATION: Spawner.start should return (ip, port) in JupyterHub >= 0.7") self.log.warning("DEPRECATION: Spawner.start should return a url or (ip, port) tuple in JupyterHub >= 0.9")
if spawner.api_token and spawner.api_token != api_token: if spawner.api_token and spawner.api_token != api_token:
# Spawner re-used an API token, discard the unused api_token # Spawner re-used an API token, discard the unused api_token
orm_token = orm.APIToken.find(self.db, api_token) orm_token = orm.APIToken.find(self.db, api_token)