mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-17 15:03:02 +00:00
spawners/simplespawner.py
This commit is contained in:
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
|
Reference in New Issue
Block a user