Skip to content

Commit

Permalink
Merge pull request #994 from manics/hub_url_public
Browse files Browse the repository at this point in the history
add hub_url_local as hub_url currently represents both public and local
  • Loading branch information
consideRatio authored Oct 31, 2020
2 parents 068b631 + 50e56a0 commit 7e04ad4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
20 changes: 18 additions & 2 deletions binderhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,22 @@ def _default_hub_token(self):
""",
config=True,
)
@validate('hub_url')

hub_url_local = Unicode(
help="""
The base URL of the JupyterHub instance for local/internal traffic
If local/internal network connections from the BinderHub process should access
JupyterHub using a different URL than public/external traffic set this, default
is hub_url
""",
config=True,
)
@default('hub_url_local')
def _default_hub_url_local(self):
return self.hub_url

@validate('hub_url', 'hub_url_local')
def _add_slash(self, proposal):
"""trait validator to ensure hub_url ends with a trailing slash"""
if proposal.value is not None and not proposal.value.endswith('/'):
Expand Down Expand Up @@ -577,6 +592,7 @@ def initialize(self, *args, **kwargs):
self.launcher = Launcher(
parent=self,
hub_url=self.hub_url,
hub_url_local=self.hub_url_local,
hub_api_token=self.hub_api_token,
create_user=not self.auth_enabled,
)
Expand Down Expand Up @@ -665,7 +681,7 @@ def initialize(self, *args, **kwargs):
tornado.web.StaticFileHandler,
{'path': os.path.join(self.tornado_settings['static_path'], 'images')}),
(r'/about', AboutHandler),
(r'/health', HealthHandler, {'hub_url': self.hub_url}),
(r'/health', HealthHandler, {'hub_url': self.hub_url_local}),
(r'/', MainHandler),
(r'.*', Custom404),
]
Expand Down
8 changes: 6 additions & 2 deletions binderhub/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tornado import web, gen
from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPError
from traitlets.config import LoggingConfigurable
from traitlets import Integer, Unicode, Bool
from traitlets import Integer, Unicode, Bool, default
from jupyterhub.traitlets import Callable
from jupyterhub.utils import maybe_future

Expand All @@ -34,6 +34,10 @@ class Launcher(LoggingConfigurable):

hub_api_token = Unicode(help="The API token for the Hub")
hub_url = Unicode(help="The URL of the Hub")
hub_url_local = Unicode(help="The internal URL of the Hub if different")
@default('hub_url_local')
def _default_hub_url_local(self):
return self.hub_url
create_user = Bool(True, help="Create a new Hub user")
allow_named_servers = Bool(
os.getenv('JUPYTERHUB_ALLOW_NAMED_SERVERS', "false") == "true",
Expand Down Expand Up @@ -81,7 +85,7 @@ async def api_request(self, url, *args, **kwargs):
"""Make an API request to JupyterHub"""
headers = kwargs.setdefault('headers', {})
headers.update({'Authorization': 'token %s' % self.hub_api_token})
hub_api_url = os.getenv('JUPYTERHUB_API_URL', '') or self.hub_url + 'hub/api/'
hub_api_url = os.getenv('JUPYTERHUB_API_URL', '') or self.hub_url_local + 'hub/api/'
request_url = hub_api_url + url
req = HTTPRequest(request_url, *args, **kwargs)
retry_delay = self.retry_delay
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/binderhub/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ spec:
key: "binder.hub-token"
{{- if .Values.config.BinderHub.auth_enabled }}
- name: JUPYTERHUB_API_URL
value: {{ (print (.Values.config.BinderHub.hub_url | trimSuffix "/") "/hub/api/") }}
value: {{ (print (.Values.config.BinderHub.hub_url_local | default .Values.config.BinderHub.hub_url | trimSuffix "/") "/hub/api/") }}
- name: JUPYTERHUB_BASE_URL
value: {{ .Values.jupyterhub.hub.baseUrl | quote }}
- name: JUPYTERHUB_CLIENT_ID
Expand Down

0 comments on commit 7e04ad4

Please sign in to comment.