diff --git a/spawners/__init__.py b/spawners/__init__.py new file mode 100644 index 00000000..ef919810 --- /dev/null +++ b/spawners/__init__.py @@ -0,0 +1 @@ +from .simplespawner import SimpleSpawner \ No newline at end of file diff --git a/spawners/simplespawner.py b/spawners/simplespawner.py new file mode 100644 index 00000000..8df323c9 --- /dev/null +++ b/spawners/simplespawner.py @@ -0,0 +1,43 @@ +import os +from traitlets import Unicode + +from jupyterhub.spawner import LocalProcessSpawner + + +class SimpleLocalProcessSpawner(LocalProcessSpawner): + """ + A version of LocalProcessSpawner that doesn't require users to exist on + the system beforehand. + + Note: DO NOT USE THIS FOR PRODUCTION USE CASES! It is very insecure, and + provides absolutely no isolation between different users! + """ + + home_path_template = Unicode( + '/tmp/{userid}', + config=True, + help='Template to expand to set the user home. {userid} and {username} are expanded' + ) + + @property + def home_path(self): + return self.home_path_template.format( + userid=self.user.id, + username=self.user.name + ) + + def make_preexec_fn(self, name): + home = self.home_path + def preexec(): + try: + os.makedirs(home, 0o755, exist_ok=True) + os.chdir(home) + except e: + print(e) + return preexec + + def user_env(self, env): + env['USER'] = self.user.name + env['HOME'] = self.home_path + env['SHELL'] = '/bin/bash' + return env \ No newline at end of file diff --git a/testing/jupyterhub_config.py b/testing/jupyterhub_config.py index 8cee48f9..84748415 100644 --- a/testing/jupyterhub_config.py +++ b/testing/jupyterhub_config.py @@ -1,5 +1,3 @@ -from jupyterhub.auth import DummyAuthenticator - """sample jupyterhub config file for testing configures jupyterhub with dummyauthenticator and simplespawner @@ -7,14 +5,12 @@ to enable testing without administrative privileges. """ c = get_config() # noqa + +from jupyterhub.auth import DummyAuthenticator c.JupyterHub.authenticator_class = DummyAuthenticator # Optionally set a global password that all users must use # c.DummyAuthenticator.password = "your_password" -try: - from simplespawner import SimpleLocalProcessSpawner -except ImportError: - print("simplespawner not available. Try: `pip install jupyterhub-simplespawner`") -else: - c.JupyterHub.spawner_class = SimpleLocalProcessSpawner +from jupyterhub.spawners import SimpleSpawner +c.JupyterHub.spawner_class = SimpleSpawner