diff --git a/integration-tests/plugins/simplest/tljh_simplest.py b/integration-tests/plugins/simplest/tljh_simplest.py index 053b1fd..4e03f3c 100644 --- a/integration-tests/plugins/simplest/tljh_simplest.py +++ b/integration-tests/plugins/simplest/tljh_simplest.py @@ -35,4 +35,8 @@ def tljh_config_post_install(config): # Put an arbitrary marker we can test for config['simplest_plugin'] = { 'present': True - } \ No newline at end of file + } + +@hookimpl +def tljh_custom_jupyterhub_config(c): + c.JupyterHub.authenticator_class = 'tmpauthenticator.TmpAuthenticator' \ No newline at end of file diff --git a/integration-tests/test_simplest_plugin.py b/integration-tests/test_simplest_plugin.py index 81193dd..37d17c4 100644 --- a/integration-tests/test_simplest_plugin.py +++ b/integration-tests/test_simplest_plugin.py @@ -2,6 +2,7 @@ Test simplest plugin """ from ruamel.yaml import YAML +import requests import os import subprocess from tljh.config import CONFIG_FILE, USER_ENV_PREFIX, HUB_ENV_PREFIX @@ -52,3 +53,11 @@ def test_config_hook(): data = yaml.load(f) assert data['simplest_plugin']['present'] + +def test_jupyterhub_config_hook(): + """ + Test that tmpauthenticator is enabled by our custom config plugin + """ + resp = requests.get('http://localhost/hub/tmplogin', allow_redirects=False) + assert resp.status_code == 302 + assert resp.headers['Location'] == '/hub/spawn' diff --git a/tljh/hooks.py b/tljh/hooks.py index ece2a40..8ab8d13 100644 --- a/tljh/hooks.py +++ b/tljh/hooks.py @@ -38,6 +38,15 @@ def tljh_extra_apt_packages(): """ pass +@hookspec +def tljh_custom_jupyterhub_config(c): + """ + Provide custom traitlet based config to JupyterHub. + + Anything you can put in `jupyterhub_config.py` can + be here. + """ + pass @hookspec def tljh_config_post_install(config): diff --git a/tljh/jupyterhub_config.py b/tljh/jupyterhub_config.py index ff1a34a..2806032 100644 --- a/tljh/jupyterhub_config.py +++ b/tljh/jupyterhub_config.py @@ -6,7 +6,7 @@ from glob import glob import os from systemdspawner import SystemdSpawner -from tljh import configurer, user +from tljh import configurer, user, hooks from tljh.config import INSTALL_PREFIX, USER_ENV_PREFIX, CONFIG_DIR from tljh.normalize import generate_system_username from tljh.yaml import yaml @@ -57,6 +57,9 @@ c.SystemdSpawner.unit_name_template = 'jupyter-{USERNAME}' tljh_config = configurer.load_config() configurer.apply_config(tljh_config, c) +# Let TLJH hooks modify `c` if they want +hooks.tljh_custom_jupyterhub_config(c) + # Load arbitrary .py config files if they exist. # This is our escape hatch extra_configs = sorted(glob(os.path.join(CONFIG_DIR, 'jupyterhub_config.d', '*.py')))