Add collaboration-users example and tutorial

This commit is contained in:
Min RK
2023-02-20 11:45:58 +01:00
parent 63dcebadbe
commit c6598c797b
5 changed files with 242 additions and 0 deletions

View 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.

View 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

View File

@@ -0,0 +1,11 @@
projects:
vox:
members:
- vex
- vax
- pike
mighty:
members:
- fjord
- beau
- jester