mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-12 12:33:02 +00:00
make HTTP requests to the proxy async
This commit is contained in:
@@ -5,10 +5,11 @@
|
|||||||
|
|
||||||
import errno
|
import errno
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import requests
|
|
||||||
from tornado import gen
|
from tornado import gen
|
||||||
|
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
|
||||||
|
|
||||||
from sqlalchemy.types import TypeDecorator, VARCHAR
|
from sqlalchemy.types import TypeDecorator, VARCHAR
|
||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
@@ -133,32 +134,37 @@ class Proxy(Base):
|
|||||||
return "<%s [unconfigured]>" % self.__class__.__name__
|
return "<%s [unconfigured]>" % self.__class__.__name__
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def add_user(self, user):
|
def add_user(self, user, client=None):
|
||||||
"""Add a user's server to the proxy table."""
|
"""Add a user's server to the proxy table."""
|
||||||
r = requests.post(
|
client = client or AsyncHTTPClient()
|
||||||
url_path_join(
|
|
||||||
|
req = HTTPRequest(url_path_join(
|
||||||
self.api_server.url,
|
self.api_server.url,
|
||||||
user.server.base_url,
|
user.server.base_url,
|
||||||
),
|
),
|
||||||
data=json.dumps(dict(
|
method="POST",
|
||||||
|
headers={'Authorization': 'token {}'.format(self.auth_token)},
|
||||||
|
body=json.dumps(dict(
|
||||||
target=user.server.host,
|
target=user.server.host,
|
||||||
user=user.name,
|
user=user.name,
|
||||||
)),
|
)),
|
||||||
headers={'Authorization': "token %s" % self.auth_token},
|
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
|
||||||
|
res = yield client.fetch(req)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def delete_user(self, user):
|
def delete_user(self, user, client=None):
|
||||||
"""Remove a user's server to the proxy table."""
|
"""Remove a user's server to the proxy table."""
|
||||||
r = requests.delete(
|
client = client or AsyncHTTPClient()
|
||||||
url_path_join(
|
req = HTTPRequest(url_path_join(
|
||||||
self.api_server.url,
|
self.api_server.url,
|
||||||
user.server.base_url,
|
user.server.base_url,
|
||||||
),
|
),
|
||||||
headers={'Authorization': "token %s" % self.auth_token},
|
method="DELETE",
|
||||||
|
headers={'Authorization': 'token {}'.format(self.auth_token)},
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
|
||||||
|
res = yield client.fetch(req)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def add_all_users(self):
|
def add_all_users(self):
|
||||||
|
Reference in New Issue
Block a user