From 2c7f99b57c9e75a007ab8c5b6e8cb4ff2bc62325 Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Mon, 16 Jul 2018 12:03:45 -0700 Subject: [PATCH] Support arbitrary authenticators - Removes all need for special casing authenticators. - Install them in hub environment, directly start using them. - Consider if we should special case any *at all* --- tests/test_configurer.py | 18 ++++++++++++++++++ tljh/configurer.py | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/test_configurer.py b/tests/test_configurer.py index cb4f2b7..5f7ad2b 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -125,3 +125,21 @@ def test_auth_firstuse(): }) assert c.JupyterHub.authenticator_class == 'firstuseauthenticator.FirstUseAuthenticator' assert c.FirstUseAuthenticator.create_users + + +def test_auth_github(): + """ + Test using GitHub authenticator, which is not explicitly special cased. + """ + c = apply_mock_config({ + 'auth': { + 'type': 'oauthenticator.github.GitHubOAuthenticator', + 'GitHubOAuthenticator': { + 'client_id': 'something', + 'client_secret': 'something-else' + } + } + }) + assert c.JupyterHub.authenticator_class == 'oauthenticator.github.GitHubOAuthenticator' + assert c.GitHubOAuthenticator.client_id == 'something' + assert c.GitHubOAuthenticator.client_secret == 'something-else' diff --git a/tljh/configurer.py b/tljh/configurer.py index 0626132..c4bd2f2 100644 --- a/tljh/configurer.py +++ b/tljh/configurer.py @@ -70,13 +70,22 @@ def update_auth(c, config): 'firstuse': 'firstuseauthenticator.FirstUseAuthenticator' } - authenticator_classname = authenticator_class_map[auth['type']] - c.JupyterHub.authenticator_class = authenticator_classname + if auth['type'] in authenticator_class_map: + authenticator_class = authenticator_class_map[auth['type']] + authenticator_configname = auth['type'] + else: + # FIXME: Make sure this is something importable. + # FIXME: SECURITY: Class must inherit from Authenticator, to prevent us being + # used to set arbitrary properties on arbitrary types of objects! + authenticator_class = auth['type'] + # When specifying fully qualified name, use classname as key for config + authenticator_configname = authenticator_class.split('.')[-1] + c.JupyterHub.authenticator_class = authenticator_class # Use just class name when setting config. If authenticator is dummyauthenticator.DummyAuthenticator, # its config will be set under c.DummyAuthenticator - authenticator_parent = getattr(c, authenticator_classname.split('.')[-1]) + authenticator_parent = getattr(c, authenticator_class.split('.')[-1]) - for k, v in auth[auth['type']].items(): + for k, v in auth.get(authenticator_configname, {}).items(): set_if_not_none(authenticator_parent, k, v)