Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the jupyterhub-configurator service #676

Merged
merged 6 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install and setup venv
- name: Install venv, git and setup venv
run: |
apt-get update --yes && apt-get install --yes python3-venv
apt-get update --yes && apt-get install --yes python3-venv git
python3 -m venv /srv/venv
echo '/srv/venv/bin' >> $GITHUB_PATH
- name: Cache pip deps
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/plugins/simplest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
entry_points={"tljh": ["simplest = tljh_simplest"]},
py_modules=["tljh_simplest"],
)


8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
'backoff',
'requests',
'bcrypt',
'jupyterhub-traefik-proxy==0.2.*'
'jupyterhub-traefik-proxy==0.2.*',
'jupyterhub-configurator @ git+https://github.com/yuvipanda/jupyterhub-configurator@ecca97e016e9a939dd48c6c0e66c40e4e2951fa7',
],
entry_points={
'jupyterhub_configurator': [
'schema = tljh.schemas.tljh_configurator',
],
'console_scripts': [
'tljh-config = tljh.config:main',
],
]
},
)
28 changes: 26 additions & 2 deletions tljh/configurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
'concurrency': 5,
'users': False,
'max_age': 0
},
'configurator': {
'enabled': False
}
}
}
Expand Down Expand Up @@ -175,8 +178,8 @@ def update_userlists(c, config):
"""
users = config['users']

c.Authenticator.whitelist = set(users['allowed'])
c.Authenticator.blacklist = set(users['banned'])
c.Authenticator.allowed_users = set(users['allowed'])
c.Authenticator.blocked_users = set(users['banned'])
c.Authenticator.admin_users = set(users['admin'])


Expand Down Expand Up @@ -249,10 +252,31 @@ def set_cull_idle_service(config):
return cull_service


def set_configurator(config):
"""
Set the JupyterHub Configurator service
"""
HERE = os.path.abspath(os.path.dirname(__file__))
configurator_cmd = [
sys.executable, "-m", "jupyterhub_configurator.app",
f"--Configurator.config_file={HERE}/jupyterhub_configurator_config.py"
]
configurator_service = {
'name': 'configurator',
'url': 'http://127.0.0.1:10101',
'command': configurator_cmd,
}

return configurator_service


def update_services(c, config):
c.JupyterHub.services = []

if config['services']['cull']['enabled']:
c.JupyterHub.services.append(set_cull_idle_service(config))
if config['services']['configurator']['enabled']:
c.JupyterHub.services.append(set_configurator(config))


def _merge_dictionaries(a, b, path=None, update=True):
Expand Down
Empty file added tljh/schemas/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions tljh/schemas/tljh_configurator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from jupyterhub_configurator.hooks import hookimpl
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved

@hookimpl
def jupyterhub_configurator_fields():
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
return {
"schema.default_interface": {
"type": "string",
"traitlet": "Spawner.default_url",
"title": "Default User Interface",
"enum": ["/tree", "/lab", "/nteract"],
"default": "/tree",
"enumMetadata": {
"/tree": {
"title": "Classic Notebook",
"description": "The original single-document interface for creating Jupyter Notebooks.",
},
"/lab": {
"title": "JupyterLab",
"description": "A Powerful next generation notebook interface",
},
"/nteract": {
"title": "Nteract",
"description": "Nteract notebook interface",
},
},
}
}
8 changes: 7 additions & 1 deletion tljh/user_creating_spawner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from tljh.normalize import generate_system_username
from tljh import user
from tljh import configurer
from systemdspawner import SystemdSpawner
from traitlets import Dict, Unicode, List

class UserCreatingSpawner(SystemdSpawner):
class CustomSpawner(SystemdSpawner):
"""
SystemdSpawner with user creation on spawn.

Expand Down Expand Up @@ -32,3 +33,8 @@ def start(self):
user.ensure_user_group(system_username, group)
return super().start()

cfg = configurer.load_config()
if cfg['services']['configurator']['enabled']:
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
UserCreatingSpawner = type('UserCreatingSpawner', (ConfiguratorSpawnerMixin, CustomSpawner), {})
else:
UserCreatingSpawner = type('UserCreatingSpawner', (CustomSpawner,), {})