Do not special case *any* authenticator

No two ways to set authenticator options - just one way.
It's slightly 'ugly' because of the mixing of camel case &
snake case, but is worth the massive reductions in complexity!
This commit is contained in:
yuvipanda
2018-07-16 16:05:44 -07:00
parent 2c7f99b57c
commit cc5622995d
2 changed files with 13 additions and 24 deletions

View File

@@ -11,9 +11,8 @@ FIXME: A strong feeling that JSON Schema should be involved somehow.
# User provided config is merged into this
default = {
'auth': {
'type': 'firstuse',
'dummy': {},
'firstuse': {
'type': 'firstuseauthenticator.FirstUseAuthenticator',
'FirstUseAuthenticator': {
'create_users': False
}
},
@@ -64,22 +63,12 @@ def update_auth(c, config):
"""
auth = config.get('auth')
# Map value of 'auth.type' in config to a fully qualified name
authenticator_class_map = {
'dummy': 'dummyauthenticator.DummyAuthenticator',
'firstuse': 'firstuseauthenticator.FirstUseAuthenticator'
}
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]
# 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