diff --git a/docs/source/install.md b/docs/source/install.md index d5ea9858..7d9050b4 100644 --- a/docs/source/install.md +++ b/docs/source/install.md @@ -69,7 +69,7 @@ ## Enabling traefik-proxy in JupyterHub -[TraefikFileProviderProxy](https://github.com/jupyterhub/traefik-proxy/blob/Traefik_v2/jupyterhub_traefik_proxy/fileprovider.py), [TraefikEtcdProxy](https://github.com/jupyterhub/traefik-proxy/blob/Traefik_v2/jupyterhub_traefik_proxy/etcd.py) and [TraefikConsulProxy](https://github.com/jupyterhub/traefik-proxy/blob/Traefik_v2/jupyterhub_traefik_proxy/consul.py) are custom proxy implementations that subclass [Proxy](https://github.com/jupyterhub/jupyterhub/blob/Traefik_v2/jupyterhub/proxy.py) and can register in JupyterHub config using `c.JupyterHub.proxy_class` entrypoint. +[TraefikFileProviderProxy](https://github.com/jupyterhub/traefik-proxy/blob/traefik-v2/jupyterhub_traefik_proxy/fileprovider.py), [TraefikEtcdProxy](https://github.com/jupyterhub/traefik-proxy/blob/traefik-v2/jupyterhub_traefik_proxy/etcd.py) and [TraefikConsulProxy](https://github.com/jupyterhub/traefik-proxy/blob/traefik-v2/jupyterhub_traefik_proxy/consul.py) are custom proxy implementations that subclass [Proxy](https://github.com/jupyterhub/jupyterhub/blob/traefik-v2/jupyterhub/proxy.py) and can register in JupyterHub config using `c.JupyterHub.proxy_class` entrypoint. On startup, JupyterHub will look by default for a configuration file, *jupyterhub_config.py*, in the current working directory. If the configuration file is not in the current working directory, you can load a specific config file and start JupyterHub using: @@ -78,7 +78,7 @@ you can load a specific config file and start JupyterHub using: $ jupyterhub -f /path/to/jupyterhub_config.py ``` -There is an example configuration file [here](https://github.com/jupyterhub/traefik-proxy/blob/Traefik_v2/examples/jupyterhub_config.py) that configures JupyterHub to run with *TraefikEtcdProxy* as the proxy and uses dummyauthenticator and simplespawner to enable testing without administrative privileges. +There is an example configuration file [here](https://github.com/jupyterhub/traefik-proxy/blob/traefik-v2/examples/jupyterhub_config.py) that configures JupyterHub to run with *TraefikEtcdProxy* as the proxy and uses dummyauthenticator and simplespawner to enable testing without administrative privileges. In *jupyterhub_config.py*: diff --git a/jupyterhub_traefik_proxy/proxy.py b/jupyterhub_traefik_proxy/proxy.py index 3a83be69..0a785e61 100644 --- a/jupyterhub_traefik_proxy/proxy.py +++ b/jupyterhub_traefik_proxy/proxy.py @@ -299,16 +299,15 @@ async def _setup_traefik_dynamic_config(self): self.log.info("Setting up traefik's dynamic config...") self._generate_htpassword() api_url = urlparse(self.traefik_api_url) - api_path = api_url.path if api_url.path else '/api' - api_credentials = "{0}:{1}".format( - self.traefik_api_username, - self.traefik_api_hashed_password - ) + api_path = api_url.path if api_url.path else "/api" + api_credentials = f"{self.traefik_api_username}:" \ + f"{self.traefik_api_hashed_password}" self.dynamic_config.update({ "http": { "routers": { "route_api": { - "rule": f"Host(`{api_url.hostname}`) && (PathPrefix(`{api_path}`) || PathPrefix(`/dashboard`))", + "rule": f"Host(`{api_url.hostname}`) && " \ + f"(PathPrefix(`{api_path}`) || PathPrefix(`/dashboard`))", "entryPoints": ["enter_api"], "service": "api@internal", "middlewares": ["auth_api"] diff --git a/jupyterhub_traefik_proxy/traefik_utils.py b/jupyterhub_traefik_proxy/traefik_utils.py index 29bafcaa..297f1b94 100644 --- a/jupyterhub_traefik_proxy/traefik_utils.py +++ b/jupyterhub_traefik_proxy/traefik_utils.py @@ -13,7 +13,7 @@ class KVStorePrefix(Unicode): def validate(self, obj, value): u = super().validate(obj, value) - # We'll join the prefix with e.g. prefix.join(pathspec), + # We'll join the prefix with e.g. "/".join(pathspec), # therefore always strip the trailing "/" from any prefix if u.endswith("/"): u = u.rstrip("/") @@ -29,12 +29,11 @@ def generate_rule(routespec): routespec = unquote(routespec) if routespec.startswith("/"): # Path-based route, e.g. /proxy/path/ - rule = "PathPrefix(`{0}`)".format(routespec) + rule = f"PathPrefix(`{routespec}`)" else: # Host-based routing, e.g. host.tld/proxy/path/ host, path_prefix = routespec.split("/", 1) - path_prefix = "/" + path_prefix - rule = "Host(`{0}`) && PathPrefix(`{1}`)".format(host, path_prefix) + rule = f"Host(`{host}`) && PathPrefix(`/{path_prefix}`)" return rule