Proxies#
Module: jupyterhub.proxy
#
API for JupyterHub’s proxy.
Custom proxy implementations can subclass Proxy
and register in JupyterHub config:
from mymodule import MyProxy
c.JupyterHub.proxy_class = MyProxy
Route Specification:
A routespec is a URL prefix ([host]/path/), e.g. ‘host.tld/path/’ for host-based routing or ‘/path/’ for default routing.
Route paths should be normalized to always start and end with ‘/’
Proxy
#
- class jupyterhub.proxy.Proxy(**kwargs: Any)#
Base class for configurable proxies that JupyterHub can use.
A proxy implementation should subclass this and must define the following methods:
get_all_routes()
return a dictionary of all JupyterHub-related routesadd_route()
adds a routedelete_route()
deletes a route
In addition to these, the following method(s) may need to be implemented:
start()
start the proxy, if it should be launched by the Hub instead of externally managed. If the proxy is externally managed, it should setshould_start
to False.
And the following method(s) are optional, but can be provided:
get_route()
gets a single route. There is a default implementation that extracts data fromget_all_routes()
, but implementations may choose to provide a more efficient implementation of fetching a single route.
- async add_all_services(service_dict)#
Update the proxy table from the database.
Used when loading up a new proxy.
- async add_all_users(user_dict)#
Update the proxy table from the database.
Used when loading up a new proxy.
- add_hub_route(hub)#
Add the default route for the Hub
- async add_route(routespec, target, data)#
Add a route to the proxy.
Subclasses must define this method
- Parameters
routespec (str) – A URL prefix ([host]/path/) for which this route will be matched, e.g. host.name/path/
target (str) – A full URL that will be the target of this route.
data (dict) – A JSONable dict that will be associated with this route, and will be returned when retrieving information about this route.
Will raise an appropriate Exception (FIXME: find what?) if the route could not be added.
The proxy implementation should also have a way to associate the fact that a route came from JupyterHub.
- async add_service(service, client=None)#
Add a service’s server to the proxy table.
- async add_user(user, server_name='', client=None)#
Add a user’s server to the proxy table.
- async check_routes(user_dict, service_dict, routes=None)#
Check that all users are properly routed on the proxy.
- async delete_route(routespec)#
Delete a route with a given routespec if it exists.
Subclasses must define this method
- async delete_service(service, client=None)#
Remove a service’s server from the proxy table.
- async delete_user(user, server_name='')#
Remove a user’s server from the proxy table.
- extra_routes c.Proxy.extra_routes = Dict()#
Additional routes to be maintained in the proxy.
A dictionary with a route specification as key, and a URL as target. The hub will ensure this route is present in the proxy.
If the hub is running in host based mode (with JupyterHub.subdomain_host set), the routespec must have a domain component (example.com/my-url/). If the hub is not running in host based mode, the routespec must not have a domain component (/my-url/).
Helpful when the hub is running in API-only mode.
- async get_all_routes()#
Fetch and return all the routes associated by JupyterHub from the proxy.
Subclasses must define this method
Should return a dictionary of routes, where the keys are routespecs and each value is a dict of the form:
{ 'routespec': the route specification ([host]/path/) 'target': the target host URL (proto://host) for this route 'data': the attached data dict for this route (as specified in add_route) }
- async get_route(routespec)#
Return the route info for a given routespec.
- Parameters
routespec (str) – A URI that was used to add this route, e.g.
host.tld/path/
- Returns
dict with the following keys:
'routespec': The normalized route specification passed in to add_route ([host]/path/) 'target': The target host for this route (proto://host) 'data': The arbitrary data dict that was passed in by JupyterHub when adding this route.
None: if there are no routes matching the given routespec
- Return type
result (dict)
- should_start c.Proxy.should_start = Bool(True)#
Should the Hub start the proxy
If True, the Hub will start the proxy and stop it. Set to False if the proxy is managed externally, such as by systemd, docker, or another service manager.
- start()#
Start the proxy.
Will be called during startup if should_start is True.
Subclasses must define this method if the proxy is to be started by the Hub
- stop()#
Stop the proxy.
Will be called during teardown if should_start is True.
Subclasses must define this method if the proxy is to be started by the Hub
- validate_routespec(routespec)#
Validate a routespec
Checks host value vs host-based routing.
Ensures trailing slash on path.
ConfigurableHTTPProxy
#
- class jupyterhub.proxy.ConfigurableHTTPProxy(**kwargs: Any)#
Proxy implementation for the default configurable-http-proxy.
This is the default proxy implementation for running the nodejs proxy
configurable-http-proxy
.If the proxy should not be run as a subprocess of the Hub, (e.g. in a separate container), set:
c.ConfigurableHTTPProxy.should_start = False
- api_url c.ConfigurableHTTPProxy.api_url = Unicode('')#
The ip (or hostname) of the proxy’s API endpoint
- auth_token c.ConfigurableHTTPProxy.auth_token = Unicode('')#
The Proxy auth token
Loaded from the CONFIGPROXY_AUTH_TOKEN env variable by default.
- check_running_interval c.ConfigurableHTTPProxy.check_running_interval = Int(5)#
Interval (in seconds) at which to check if the proxy is running.
- command c.ConfigurableHTTPProxy.command = Command()#
The command to start the proxy
- concurrency c.ConfigurableHTTPProxy.concurrency = Int(10)#
The number of requests allowed to be concurrently outstanding to the proxy
Limiting this number avoids potential timeout errors by sending too many requests to update the proxy at once
- debug c.ConfigurableHTTPProxy.debug = Bool(False)#
Add debug-level logging to the Proxy.
- extra_routes c.ConfigurableHTTPProxy.extra_routes = Dict()#
Additional routes to be maintained in the proxy.
A dictionary with a route specification as key, and a URL as target. The hub will ensure this route is present in the proxy.
If the hub is running in host based mode (with JupyterHub.subdomain_host set), the routespec must have a domain component (example.com/my-url/). If the hub is not running in host based mode, the routespec must not have a domain component (/my-url/).
Helpful when the hub is running in API-only mode.
- pid_file c.ConfigurableHTTPProxy.pid_file = Unicode('jupyterhub-proxy.pid')#
File in which to write the PID of the proxy process.
- should_start c.ConfigurableHTTPProxy.should_start = Bool(True)#
Should the Hub start the proxy
If True, the Hub will start the proxy and stop it. Set to False if the proxy is managed externally, such as by systemd, docker, or another service manager.