Merge pull request #2198 from kshitija08/master

spawners/simplespawner.py
This commit is contained in:
Min RK
2018-09-28 13:47:18 +02:00
committed by GitHub
3 changed files with 48 additions and 8 deletions

1
spawners/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .simplespawner import SimpleSpawner

43
spawners/simplespawner.py Normal file
View File

@@ -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

View File

@@ -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