mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-07 01:54:09 +00:00
Add collaboration-users example and tutorial
This commit is contained in:
5
examples/collaboration-accounts/README.md
Normal file
5
examples/collaboration-accounts/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Collaboration accounts
|
||||
|
||||
An example of enabling real-time collaboration with dedicated accounts for collaborations.
|
||||
|
||||
See [collaboration account docs](docs/source/tutorial/collaboration-accounts.md) for details.
|
58
examples/collaboration-accounts/jupyterhub_config.py
Normal file
58
examples/collaboration-accounts/jupyterhub_config.py
Normal file
@@ -0,0 +1,58 @@
|
||||
c = get_config() # noqa
|
||||
|
||||
c.JupyterHub.authenticator_class = "dummy"
|
||||
c.JupyterHub.spawner_class = "docker"
|
||||
|
||||
|
||||
c.JupyterHub.log_level = 10
|
||||
c.JupyterHub.cleanup_servers = True
|
||||
|
||||
c.JupyterHub.load_roles = []
|
||||
|
||||
c.JupyterHub.load_groups = {
|
||||
# collaborative accounts get added to this group
|
||||
"collaborative": [],
|
||||
}
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
projects_yaml = Path(__file__).parent.resolve().joinpath("projects.yaml")
|
||||
with projects_yaml.open() as f:
|
||||
project_config = yaml.safe_load(f)
|
||||
|
||||
for project_name, project in project_config["projects"].items():
|
||||
members = project.get("members", [])
|
||||
print(f"Adding project {project_name} with members {members}")
|
||||
c.JupyterHub.load_groups[project_name] = members
|
||||
collab_user = f"{project_name}-collab"
|
||||
c.JupyterHub.load_groups["collaborative"].append(collab_user)
|
||||
c.JupyterHub.load_roles.append(
|
||||
{
|
||||
"name": f"collab-access-{project_name}",
|
||||
"scopes": [
|
||||
"admin-ui",
|
||||
f"admin:servers!user={collab_user}",
|
||||
f"list:users!user={collab_user}",
|
||||
f"access:servers!user={collab_user}",
|
||||
],
|
||||
"groups": [project_name],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
c.JupyterHub.bind_url = "http://127.0.0.1:8000/rtc/"
|
||||
|
||||
# default to hub home instead of spawning
|
||||
c.JupyterHub.default_url = "/rtc/hub/home"
|
||||
|
||||
|
||||
def pre_spawn_hook(spawner):
|
||||
group_names = {group.name for group in spawner.user.groups}
|
||||
if "collaborative" in group_names:
|
||||
spawner.log.info(f"Enabling RTC for user {spawner.user.name}")
|
||||
spawner.args.append("--LabApp.collaborative=True")
|
||||
|
||||
|
||||
c.Spawner.pre_spawn_hook = pre_spawn_hook
|
11
examples/collaboration-accounts/projects.yaml
Normal file
11
examples/collaboration-accounts/projects.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
projects:
|
||||
vox:
|
||||
members:
|
||||
- vex
|
||||
- vax
|
||||
- pike
|
||||
mighty:
|
||||
members:
|
||||
- fjord
|
||||
- beau
|
||||
- jester
|
Reference in New Issue
Block a user