mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 13:03:01 +00:00
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
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 |