Skip to content
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

add hub_url_local as hub_url currently represents both public and local #994

Merged
merged 5 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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