Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter environments based on URL parameters #176

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tljh-plasma/tljh_plasma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import pwd

from urllib.parse import urlparse, parse_qs

from dockerspawner import SystemUserSpawner
from jupyterhub.auth import PAMAuthenticator
from jupyterhub.handlers.static import CacheControlStaticFilesHandler
Expand Down Expand Up @@ -29,13 +31,25 @@ class PlasmaSpawner(SpawnerMixin, SystemUserSpawner):
)

async def list_images(self):
# filter images based on the group permissions
all_images = await super().list_images()
groups = [
group.gr_name for group in grp.getgrall() if self.user.name in group.gr_mem
]
permissions = self.db.query(Permissions).filter(Permissions.group.in_(groups))
whitelist = set(p.image for p in permissions)
images = [image for image in all_images if image["image_name"] in whitelist]

# filter images based on the url query parameter
next_url = self.handler.get_argument("next", default="")
query = urlparse(next_url).query
parsed = parse_qs(query)
if "environment-name" in parsed:
display_name = parsed["environment-name"][0]
images = [
image for image in images if image["display_name"] == display_name
]

return images

async def start(self, *args, **kwargs):
Expand Down