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

Rename url to urlpath where it is possible and appropriate #105

Merged
merged 4 commits into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions remoteappmanager/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self,
settings.update(as_dict(command_line_config))
settings.update(as_dict(file_config))
settings["static_url_prefix"] = (
self._command_line_config.base_url + "static/")
self._command_line_config.base_urlpath + "static/")

self._jinja_init(settings)

Expand Down Expand Up @@ -99,7 +99,7 @@ def _reverse_proxy_default(self):
return ReverseProxy(
endpoint_url=self.command_line_config.proxy_api_url,
auth_token=auth_token,
base_urlpath=self.command_line_config.base_url
base_urlpath=self.command_line_config.base_urlpath
)

@default("hub")
Expand Down Expand Up @@ -149,11 +149,11 @@ def start(self):
def _get_handlers(self):
"""Returns the registered handlers"""

base_url = self.command_line_config.base_url
base_urlpath = self.command_line_config.base_urlpath
return [
(base_url, HomeHandler),
(base_url.rstrip('/'),
web.RedirectHandler, {"url": base_url}),
(base_urlpath, HomeHandler),
(base_urlpath.rstrip('/'),
web.RedirectHandler, {"url": base_urlpath}),
]

def _jinja_init(self, settings):
Expand Down
6 changes: 3 additions & 3 deletions remoteappmanager/command_line_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CommandLineConfig(HasTraits):

# This is the url path that the user sees and which leads to this server.
# typically, it's /user/username
base_url = Unicode(help="The base url where the server resides")
base_urlpath = Unicode(help="The base url where the server resides")

# This is the host of the hub. It's always empty (jupyterhub decision)
hub_host = Unicode(help="The url of the jupyterhub server")
Expand Down Expand Up @@ -64,5 +64,5 @@ def parse_config(self):

set_traits_from_dict(self, options)

# Normalize the base_url to end with a slash
self.base_url = with_end_slash(self.base_url)
# Normalize the base_urlpath to end with a slash
self.base_urlpath = with_end_slash(self.base_urlpath)
2 changes: 1 addition & 1 deletion remoteappmanager/handlers/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def render(self, template_name, **kwargs):
"""
args = dict(
user=self.current_user,
base_url=self.application.command_line_config.base_url,
base_url=self.application.command_line_config.base_urlpath,
logout_url=urljoin(
self.application.command_line_config.hub_prefix,
"logout")
Expand Down
16 changes: 8 additions & 8 deletions remoteappmanager/handlers/home_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def _actionhandler_start(self, options):

# The server is up and running. Now contact the proxy and add
# the container url to it.
url = yield self.application.reverse_proxy.add_container(container)
urlpath = yield self.application.reverse_proxy.add_container(container)

# Redirect the user
self.log.info('Redirecting to {}'.format(url))
self.redirect(url)
self.log.info('Redirecting to {}'.format(urlpath))
self.redirect(urlpath)

@gen.coroutine
def _actionhandler_view(self, options):
Expand All @@ -136,10 +136,10 @@ def _actionhandler_view(self, options):
yield self._wait_for_container_ready(container)

# in case the reverse proxy is not already set up
url = yield self.application.reverse_proxy.add_container(container)
urlpath = yield self.application.reverse_proxy.add_container(container)

self.log.info('Redirecting to {}'.format(url))
self.redirect(url)
self.log.info('Redirecting to {}'.format(urlpath))
self.redirect(urlpath)

@gen.coroutine
def _actionhandler_stop(self, options):
Expand All @@ -166,7 +166,7 @@ def _actionhandler_stop(self, options):

# We don't have fancy stuff at the moment to change the button, so
# we just reload the page.
self.redirect(self.application.command_line_config.base_url)
self.redirect(self.application.command_line_config.base_urlpath)

# private

Expand Down Expand Up @@ -302,7 +302,7 @@ def _wait_for_container_ready(self, container):
server_url = "http://{}:{}{}/".format(
container.ip,
container.port,
url_path_join(self.application.command_line_config.base_url,
url_path_join(self.application.command_line_config.base_urlpath,
container.urlpath))

yield _wait_for_http_server_2xx(
Expand Down
8 changes: 8 additions & 0 deletions remoteappmanager/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def __init__(self, **kwargs):

def get_args(self):
args = super().get_args()

for iarg, arg in enumerate(args):
args[iarg] = arg.replace('--base-url=', '--base-urlpath=')

args.append("--proxy-api-url={}".format(self.proxy.api_server.url))
args.append("--config-file={}".format(self.config_file_path))
return args
Expand Down Expand Up @@ -103,6 +107,10 @@ def clear_state(self):

def get_args(self):
args = super().get_args()

for iarg, arg in enumerate(args):
args[iarg] = arg.replace('--base-url=', '--base-urlpath=')

args.append("--proxy-api-url={}".format(self.proxy.api_server.url))
args.append("--config-file={}".format(self.config_file_path))
return args
Expand Down
4 changes: 3 additions & 1 deletion remoteappmanager/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
def url_path_join(*pieces):
"""Join components of url into a relative url
"""Join components of url into a relative url path
Use to prevent double slash when joining subpath. This will leave the
initial and final / in place

Assume pieces do not contain protocol (e.g. http://)
"""
stripped = [s.strip('/') for s in pieces]
result = '/'.join(s for s in stripped if s)
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_home_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_app(self):
'pending': None,
'name': command_line_config.user,
'admin': False,
'server': command_line_config.base_url})
'server': command_line_config.base_urlpath})
app.db = mock.Mock(spec=ABCAccounting)
app.container_manager = mock.Mock(spec=ContainerManager)
app.container_manager.start_container = mock_coro_factory(Container())
Expand Down
1 change: 1 addition & 0 deletions tests/spawner/test_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_args(self):
args = self.spawner.get_args()
self.assertIn("--proxy-api-url=http://127.0.0.1:12345/foo/bar/", args)
self.assertIn("--config-file={}".format(path), args)
self.assertIn("--base-urlpath=/", args)

def test_cmd(self):
self.assertEqual(self.spawner.cmd, ['remoteappmanager'])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_command_line_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):

def test_initialization(self):
for key, value in arguments.items():
if key == "base-url":
if key == "base-urlpath":
value = with_end_slash(value)

self.assertEqual(getattr(self.config, key.replace("-", "_")),
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def containers_dict():
"user": "username",
"port": 57022,
"cookie-name": "jupyter-hub-token-username",
"base-url": "/user/username/",
"base-urlpath": "/user/username/",
"hub-host": "",
"hub-prefix": "/hub/",
"hub-api-url": "http://172.17.5.167:8081/hub/api",
Expand Down