mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
Merge pull request #2198 from kshitija08/master
spawners/simplespawner.py
This commit is contained in:
1
spawners/__init__.py
Normal file
1
spawners/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .simplespawner import SimpleSpawner
|
43
spawners/simplespawner.py
Normal file
43
spawners/simplespawner.py
Normal 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
|
@@ -1,5 +1,3 @@
|
|||||||
from jupyterhub.auth import DummyAuthenticator
|
|
||||||
|
|
||||||
"""sample jupyterhub config file for testing
|
"""sample jupyterhub config file for testing
|
||||||
|
|
||||||
configures jupyterhub with dummyauthenticator and simplespawner
|
configures jupyterhub with dummyauthenticator and simplespawner
|
||||||
@@ -7,14 +5,12 @@ to enable testing without administrative privileges.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
c = get_config() # noqa
|
c = get_config() # noqa
|
||||||
|
|
||||||
|
from jupyterhub.auth import DummyAuthenticator
|
||||||
c.JupyterHub.authenticator_class = DummyAuthenticator
|
c.JupyterHub.authenticator_class = DummyAuthenticator
|
||||||
|
|
||||||
# Optionally set a global password that all users must use
|
# Optionally set a global password that all users must use
|
||||||
# c.DummyAuthenticator.password = "your_password"
|
# c.DummyAuthenticator.password = "your_password"
|
||||||
|
|
||||||
try:
|
from jupyterhub.spawners import SimpleSpawner
|
||||||
from simplespawner import SimpleLocalProcessSpawner
|
c.JupyterHub.spawner_class = SimpleSpawner
|
||||||
except ImportError:
|
|
||||||
print("simplespawner not available. Try: `pip install jupyterhub-simplespawner`")
|
|
||||||
else:
|
|
||||||
c.JupyterHub.spawner_class = SimpleLocalProcessSpawner
|
|
||||||
|
Reference in New Issue
Block a user