mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 22:13:00 +00:00
proxy needs user dict, which has proxy path
this won't be needed if/when I make a schema change, where domain is included in the Server table.
This commit is contained in:
@@ -28,7 +28,7 @@ class ProxyAPIHandler(APIHandler):
|
|||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def post(self):
|
def post(self):
|
||||||
"""POST checks the proxy to ensure"""
|
"""POST checks the proxy to ensure"""
|
||||||
yield self.proxy.check_routes()
|
yield self.proxy.check_routes(self.users)
|
||||||
|
|
||||||
|
|
||||||
@admin_only
|
@admin_only
|
||||||
@@ -59,7 +59,7 @@ class ProxyAPIHandler(APIHandler):
|
|||||||
self.proxy.auth_token = model['auth_token']
|
self.proxy.auth_token = model['auth_token']
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
self.log.info("Updated proxy at %s", server.bind_url)
|
self.log.info("Updated proxy at %s", server.bind_url)
|
||||||
yield self.proxy.check_routes()
|
yield self.proxy.check_routes(self.users)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -896,7 +896,7 @@ class JupyterHub(Application):
|
|||||||
)
|
)
|
||||||
yield self.start_proxy()
|
yield self.start_proxy()
|
||||||
self.log.info("Setting up routes on new proxy")
|
self.log.info("Setting up routes on new proxy")
|
||||||
yield self.proxy.add_all_users()
|
yield self.proxy.add_all_users(self.users)
|
||||||
self.log.info("New proxy back up, and good to go")
|
self.log.info("New proxy back up, and good to go")
|
||||||
|
|
||||||
def init_tornado_settings(self):
|
def init_tornado_settings(self):
|
||||||
@@ -1085,7 +1085,7 @@ class JupyterHub(Application):
|
|||||||
user.last_activity = max(user.last_activity, dt)
|
user.last_activity = max(user.last_activity, dt)
|
||||||
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
yield self.proxy.check_routes(routes)
|
yield self.proxy.check_routes(routes, self.users)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def start(self):
|
def start(self):
|
||||||
@@ -1120,7 +1120,7 @@ class JupyterHub(Application):
|
|||||||
self.exit(1)
|
self.exit(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
loop.add_callback(self.proxy.add_all_users)
|
loop.add_callback(self.proxy.add_all_users, self.users)
|
||||||
|
|
||||||
if self.proxy_process:
|
if self.proxy_process:
|
||||||
# only check / restart the proxy if we started it in the first place.
|
# only check / restart the proxy if we started it in the first place.
|
||||||
|
@@ -198,14 +198,21 @@ class Proxy(Base):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def add_all_users(self):
|
def get_routes(self, client=None):
|
||||||
|
"""Fetch the proxy's routes"""
|
||||||
|
resp = yield self.api_request('', client=client)
|
||||||
|
return json.loads(resp.body.decode('utf8', 'replace'))
|
||||||
|
|
||||||
|
@gen.coroutine
|
||||||
|
def add_all_users(self, user_dict):
|
||||||
"""Update the proxy table from the database.
|
"""Update the proxy table from the database.
|
||||||
|
|
||||||
Used when loading up a new proxy.
|
Used when loading up a new proxy.
|
||||||
"""
|
"""
|
||||||
db = inspect(self).session
|
db = inspect(self).session
|
||||||
futures = []
|
futures = []
|
||||||
for user in db.query(User):
|
for orm_user in db.query(User):
|
||||||
|
user = user_dict[orm_user]
|
||||||
if (user.server):
|
if (user.server):
|
||||||
futures.append(self.add_user(user))
|
futures.append(self.add_user(user))
|
||||||
# wait after submitting them all
|
# wait after submitting them all
|
||||||
@@ -213,21 +220,16 @@ class Proxy(Base):
|
|||||||
yield f
|
yield f
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def get_routes(self, client=None):
|
def check_routes(self, user_dict, routes=None):
|
||||||
"""Fetch the proxy's routes"""
|
"""Check that all users are properly routed on the proxy"""
|
||||||
resp = yield self.api_request('', client=client)
|
|
||||||
return json.loads(resp.body.decode('utf8', 'replace'))
|
|
||||||
|
|
||||||
@gen.coroutine
|
|
||||||
def check_routes(self, routes=None):
|
|
||||||
"""Check that all users are properly"""
|
|
||||||
if not routes:
|
if not routes:
|
||||||
routes = yield self.get_routes()
|
routes = yield self.get_routes()
|
||||||
|
|
||||||
have_routes = { r['user'] for r in routes.values() if 'user' in r }
|
have_routes = { r['user'] for r in routes.values() if 'user' in r }
|
||||||
futures = []
|
futures = []
|
||||||
db = inspect(self).session
|
db = inspect(self).session
|
||||||
for user in db.query(User).filter(User.server != None):
|
for orm_user in db.query(User).filter(User.server != None):
|
||||||
|
user = user_dict[orm_user]
|
||||||
if user.server is None:
|
if user.server is None:
|
||||||
# This should never be True, but seems to be on rare occasion.
|
# This should never be True, but seems to be on rare occasion.
|
||||||
# catch filter bug, either in sqlalchemy or my understanding of its behavior
|
# catch filter bug, either in sqlalchemy or my understanding of its behavior
|
||||||
|
@@ -123,13 +123,14 @@ def test_check_routes(app, io_loop):
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
zoe = orm.User.find(app.db, 'zoe')
|
zoe = orm.User.find(app.db, 'zoe')
|
||||||
assert zoe is not None
|
assert zoe is not None
|
||||||
|
zoe = app.users[zoe]
|
||||||
before = sorted(io_loop.run_sync(app.proxy.get_routes))
|
before = sorted(io_loop.run_sync(app.proxy.get_routes))
|
||||||
assert '/user/zoe' in before
|
assert '/user/zoe' in before
|
||||||
io_loop.run_sync(app.proxy.check_routes)
|
io_loop.run_sync(lambda : app.proxy.check_routes(app.users))
|
||||||
io_loop.run_sync(lambda : proxy.delete_user(zoe))
|
io_loop.run_sync(lambda : proxy.delete_user(zoe))
|
||||||
during = sorted(io_loop.run_sync(app.proxy.get_routes))
|
during = sorted(io_loop.run_sync(app.proxy.get_routes))
|
||||||
assert '/user/zoe' not in during
|
assert '/user/zoe' not in during
|
||||||
io_loop.run_sync(app.proxy.check_routes)
|
io_loop.run_sync(lambda : app.proxy.check_routes(app.users))
|
||||||
after = sorted(io_loop.run_sync(app.proxy.get_routes))
|
after = sorted(io_loop.run_sync(app.proxy.get_routes))
|
||||||
assert '/user/zoe' in after
|
assert '/user/zoe' in after
|
||||||
assert before == after
|
assert before == after
|
||||||
|
Reference in New Issue
Block a user