Skip to content

Commit

Permalink
Tidy up a couple of files.
Browse files Browse the repository at this point in the history
Correct traefik-v2 documentation URLs in install.md.

Reduce line-lengths of f-strings in proxy.py and traefik_utils.py.

Co-authored-by: GeorgianaElena <[email protected]>
  • Loading branch information
alexleach and GeorgianaElena committed Jul 17, 2021
1 parent 400189f commit ff4fba5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/source/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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*:
Expand Down
11 changes: 5 additions & 6 deletions jupyterhub_traefik_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 3 additions & 4 deletions jupyterhub_traefik_proxy/traefik_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand All @@ -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


Expand Down

0 comments on commit ff4fba5

Please sign in to comment.