Skip to content

Commit 05981de

Browse files
committed
ssh: automatically cast hub_url strings to yarl.URL objects
1 parent 3fe6155 commit 05981de

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

jupyterhub_ssh/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from traitlets import Bool
1010
from traitlets import Integer
1111
from traitlets import Unicode
12+
from traitlets import validate
1213
from traitlets.config import Application
1314
from yarl import URL
1415

@@ -221,7 +222,6 @@ class JupyterHubSSH(Application):
221222
config=True,
222223
)
223224

224-
# FIXME: Make this a yarl.URL object?
225225
hub_url = Any(
226226
"",
227227
help="""
@@ -232,6 +232,15 @@ class JupyterHubSSH(Application):
232232
config=True,
233233
)
234234

235+
@validate("hub_url")
236+
def _hub_url_cast_string_to_yarl_url(self, proposal):
237+
if isinstance(proposal.value, str):
238+
return URL(proposal.value)
239+
elif isinstance(proposal.value, URL):
240+
return proposal.value
241+
else:
242+
raise ValueError("hub_url must either be a string or a yarl.URL")
243+
235244
host_key_path = Unicode(
236245
"",
237246
help="""
@@ -266,10 +275,6 @@ def initialize(self, *args, **kwargs):
266275
self.load_config_file(self.config_file)
267276
self.init_logging()
268277

269-
# FIXME: Do this as a traitlet instead somehow?
270-
# THIS IS DIRTY MAKES ME SAD
271-
self.hub_url = URL(self.hub_url)
272-
273278
async def start_server(self):
274279
await asyncssh.listen(
275280
host="",

0 commit comments

Comments
 (0)