Make authenticator class assigning code more generic

This commit is contained in:
yuvipanda
2018-07-16 01:19:24 -07:00
parent 395b6543da
commit 66de7bb038

View File

@@ -64,12 +64,17 @@ def update_auth(c, config):
""" """
auth = config.get('auth') auth = config.get('auth')
if auth['type'] == 'dummy': # Map value of 'auth.type' in config to a fully qualified name
c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator' authenticator_class_map = {
authenticator_parent = c.DummyAuthenticator 'dummy': 'dummyauthenticator.DummyAuthenticator',
elif auth['type'] == 'firstuse': 'firstuse': 'firstuseauthenticator.FirstUseAuthenticator'
c.JupyterHub.authenticator_class = 'firstuseauthenticator.FirstUseAuthenticator' }
authenticator_parent = c.FirstUseAuthenticator
authenticator_classname = authenticator_class_map[auth['type']]
c.JupyterHub.authenticator_class = authenticator_classname
# 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])
for k, v in auth[auth['type']].items(): for k, v in auth[auth['type']].items():
set_if_not_none(authenticator_parent, k, v) set_if_not_none(authenticator_parent, k, v)