Try and try again
This commit is contained in:
parent
f6eaea5e12
commit
6e74400870
|
@ -148,7 +148,7 @@ hub:
|
||||||
'display': False,
|
'display': False,
|
||||||
'oauth_no_confirm': True,
|
'oauth_no_confirm': True,
|
||||||
'api_token': os.environ['JUPYTERHUB_CRYPT_KEY'],
|
'api_token': os.environ['JUPYTERHUB_CRYPT_KEY'],
|
||||||
# 'command': [sys.executable, '/usr/local/etc/jupyterhub/refresh-token.py']
|
'command': [sys.executable, '/usr/local/etc/jupyterhub/refresh-token.py']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
extraFiles:
|
extraFiles:
|
||||||
|
@ -163,68 +163,18 @@ hub:
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import tornado.options
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
|
||||||
from tornado.httpserver import HTTPServer
|
from tornado.httpserver import HTTPServer
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
from tornado.log import app_log
|
from tornado.log import app_log
|
||||||
from tornado.web import Application, HTTPError, RequestHandler, authenticated
|
from tornado.web import Application, RequestHandler, authenticated
|
||||||
from jupyterhub.services.auth import HubAuthenticated
|
from jupyterhub.services.auth import HubAuthenticated
|
||||||
|
|
||||||
|
|
||||||
class RefreshHandler(HubAuthenticated, RequestHandler):
|
class RefreshHandler(HubAuthenticated, RequestHandler):
|
||||||
def api_request(self, method, url, **kwargs):
|
|
||||||
"""Make an API request"""
|
|
||||||
url = url_path_join(self.hub_auth.api_url, url)
|
|
||||||
allow_404 = kwargs.pop('allow_404', False)
|
|
||||||
headers = kwargs.setdefault('headers', {})
|
|
||||||
headers.setdefault('Authorization',
|
|
||||||
'token %s' % self.hub_auth.api_token)
|
|
||||||
try:
|
|
||||||
r = requests.request(method, url, **kwargs)
|
|
||||||
except requests.ConnectionError as e:
|
|
||||||
app_log.error("Error connecting to %s: %s", url, e)
|
|
||||||
msg = "Failed to connect to Hub API at %r." % url
|
|
||||||
msg += " Is the Hub accessible at this URL (from host: %s)?" % socket.gethostname(
|
|
||||||
)
|
|
||||||
if '127.0.0.1' in url:
|
|
||||||
msg += " Make sure to set c.JupyterHub.hub_ip to an IP accessible to" + \
|
|
||||||
" single-user servers if the servers are not on the same host as the Hub."
|
|
||||||
raise HTTPError(500, msg)
|
|
||||||
|
|
||||||
data = None
|
|
||||||
if r.status_code == 404 and allow_404:
|
|
||||||
pass
|
|
||||||
elif r.status_code == 403:
|
|
||||||
app_log.error(
|
|
||||||
"I don't have permission to check authorization with JupyterHub, my auth token may have expired: [%i] %s",
|
|
||||||
r.status_code, r.reason)
|
|
||||||
app_log.error(r.text)
|
|
||||||
raise HTTPError(
|
|
||||||
500,
|
|
||||||
"Permission failure checking authorization, I may need a new token"
|
|
||||||
)
|
|
||||||
elif r.status_code >= 500:
|
|
||||||
app_log.error("Upstream failure verifying auth token: [%i] %s",
|
|
||||||
r.status_code, r.reason)
|
|
||||||
app_log.error(r.text)
|
|
||||||
raise HTTPError(
|
|
||||||
502, "Failed to check authorization (upstream problem)")
|
|
||||||
elif r.status_code >= 400:
|
|
||||||
app_log.warning("Failed to check authorization: [%i] %s",
|
|
||||||
r.status_code, r.reason)
|
|
||||||
app_log.warning(r.text)
|
|
||||||
raise HTTPError(500, "Failed to check authorization")
|
|
||||||
else:
|
|
||||||
data = r.json()
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
@authenticated
|
@authenticated
|
||||||
def get(self):
|
def get(self):
|
||||||
app_log.error("DEBUG: In auth get")
|
app_log.info(f"DEBUG: In refresh get {os.environ}")
|
||||||
print("DEBUG: In auth get")
|
|
||||||
user_model = self.get_current_user()
|
user_model = self.get_current_user()
|
||||||
user_model = {'helloooooo': 'hej'}
|
user_model = {'helloooooo': 'hej'}
|
||||||
self.set_header('content-type', 'application/json')
|
self.set_header('content-type', 'application/json')
|
||||||
|
@ -233,16 +183,12 @@ hub:
|
||||||
class PingHandler(RequestHandler):
|
class PingHandler(RequestHandler):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
app_log.error("DEBUG: In get")
|
app_log.info(f"DEBUG: In ping get {os.environ}")
|
||||||
print("DEBUG: In ping get")
|
|
||||||
self.set_header('content-type', 'application/json')
|
self.set_header('content-type', 'application/json')
|
||||||
self.write(json.dumps({'ping': 1}))
|
self.write(json.dumps({'ping': 1}))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app_log.error("DEBUG: In main")
|
|
||||||
print("DEBUG: In main")
|
|
||||||
tornado.options.parse_command_line()
|
|
||||||
app = Application([
|
app = Application([
|
||||||
(os.environ['JUPYTERHUB_SERVICE_PREFIX'] + 'tokens', RefreshHandler),
|
(os.environ['JUPYTERHUB_SERVICE_PREFIX'] + 'tokens', RefreshHandler),
|
||||||
(os.environ['JUPYTERHUB_SERVICE_PREFIX'] + '/?', PingHandler),
|
(os.environ['JUPYTERHUB_SERVICE_PREFIX'] + '/?', PingHandler),
|
||||||
|
|
Loading…
Reference in a new issue