Skip to content

Commit

Permalink
JHub Apps: Filter conda envs by user (#2187)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Chuck McAndrew <6248903+dcmcand@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 10, 2024
1 parent d4fcdf2 commit 0d02ab4
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_username_hook(spawner):
)


def get_conda_store_environments(query_package: str = ""):
def get_conda_store_environments(user_info: dict):
import urllib3
import yarl

Expand All @@ -30,17 +30,19 @@ def get_conda_store_environments(query_package: str = ""):

url = yarl.URL(f"http://{external_url}/{endpoint}/")

if query_package:
url = url % {"packages": query_package}

http = urllib3.PoolManager()
response = http.request(
"GET", str(url), headers={"Authorization": f"Bearer {token}"}
)

# parse response
j = json.loads(response.data.decode("UTF-8"))
return [f"{env['namespace']['name']}-{env['name']}" for env in j.get("data", [])]
# Filter and return conda environments for the user
return [
f"{env['namespace']['name']}-{env['name']}"
for env in j.get("data", [])
if env["namespace"]["name"] == user_info.get("name")
]


c.Spawner.pre_spawn_hook = get_username_hook
Expand All @@ -63,6 +65,7 @@ def get_conda_store_environments(query_package: str = ""):
"/usr/local/etc/jupyterhub/jupyterhub_config.py"
)
c.JAppsConfig.hub_host = "hub"
c.JAppsConfig.service_workers = 4

def service_for_jhub_apps(name, url):
return {
Expand Down

0 comments on commit 0d02ab4

Please sign in to comment.