-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it a standalone service #1
Comments
@minrk this seem to work for me (tested against #!/usr/bin/python3
import json
import pprint
import os
import re
import sys
from urllib.parse import urlparse
import requests
from tornado import web, httpserver, ioloop
from jupyterhub.services.auth import HubOAuthenticated, HubOAuthCallbackHandler
import nbserverproxy
class APIHandler(web.RequestHandler):
"""Relay API requests to the Hub's API using the service's API token."""
def get(self, path):
api_token = os.environ['JUPYTERHUB_API_TOKEN']
api_url = os.environ['JUPYTERHUB_API_URL']
r = requests.get(api_url + '/' + path,
headers={'Authorization': 'token %s' % api_token},
)
r.raise_for_status()
self.set_header('Content-Type', 'application/json')
self.write(r.text)
class EchoHandler(HubOAuthenticated, web.RequestHandler):
"""Reply to an HTTP request with the path of the request."""
@web.authenticated
def get(self):
self.write(self.request.path)
def main():
pprint.pprint(dict(os.environ), stream=sys.stderr)
StandaloneLocalProxyHandler = type(
'StandaloneLocalProxyHandler',
(HubOAuthenticated, nbserverproxy.handlers.WebSocketHandlerMixin, web.RequestHandler),
dict(nbserverproxy.handlers.LocalProxyHandler.__dict__)
)
app = web.Application([
(r'.*/api/(.*)', APIHandler),
(os.getenv('JUPYTERHUB_OAUTH_CALLBACK_URL'), HubOAuthCallbackHandler),
(os.getenv('JUPYTERHUB_SERVICE_PREFIX') + r'proxy/(\d+)(.*)', StandaloneLocalProxyHandler),
(r'.*', EchoHandler),
], cookie_secret=os.urandom(32))
r = re.compile('--port=(\d+)')
port = next( (r.match(p).group(1) for p in sys.argv if r.match(p)), '8888')
server = httpserver.HTTPServer(app)
server.listen(port)
try:
ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print('\nInterrupted')
if __name__ == '__main__':
main() (inspired by |
Would you like to create a PR to contribute the above code? |
@betatim ehm... Contribute where? Everyone may get the above script, put it into a container with, for example, Xpra and spawn desktops instead of Jupyter notebooks in their k8s cloud (if their Hub is configured to use KubeSpawner). I don't think the short script posted above is related to this repo in the sense that it should be contributed into it. |
This issue is about making nbserverproxy ready to be a standalone service, so I assumed you wanted to contribute to that effort with the script you posted. Having random bits of code strewn around the issues increases the chances that they will become dead code that doesn't work/isn't maintained. So it should go in the documentation, examples or other bit of the repo somewhere. |
It all depends on what to understand under "standalone". As you can see, I do not run
(See the OP message). In this sense it is already standalone, no action is required. The issue can be closed right now. It is quite another matter if by "standalone" one means "doesn't inherit from (But the There are also several things I'm not happy about: the URL pattern the proxy handles, the way it creates websocket connection to the back-end, the fact that it instantiates httpclient instead of receiving it in the constructor (I would like to provide mine one with custom resolver able to return unix sockets instead of TCP ones). |
Thanks for your contribution. |
Ok, @minrk It would be great to have |
https://github.com/BerserkerTroll/tornado_proxy — a (yet another) standalone Tornado proxy, a rewrite of the See also https://github.com/BerserkerTroll/nbxpra/tree/nbserverproxy (HTML5 remote desktop notebook extension similar to Do not forget to add the |
Cool! Really excited to try this out. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@ryanlovett I was expecting to focus on the standalonization here. The link to |
Good point, I'll copy my comments to nbxpra. |
For those who want to follow: https://github.com/BerserkerTroll/nbxpra/issues/1 is the new issue for nbxpra discussion. |
I've extracted
|
This sounds like https://github.com/ideonate/jhsingle-native-proxy 😄 There's a lot of duplicated code, though there's also several custom additions specific to ContainDS Dashboards. Should we aim to merge the standalone features added by jhsingle-native-proxy back into jupyter-server-proxy, or should we keep them as separate projects and close this issue? |
It would be fantastic if jupyter-server-proxy could also be a standalone service as https://github.com/ideonate/jhsingle-native-proxy is missing the new cool feature of |
Add a test for eventstreams
It would be useful to have this as a standalone service, to enable deploying any web application behind
JupyterHub auth, not just as a notebook extension.
The package could still provide a serverextension for the existing case.
The text was updated successfully, but these errors were encountered: