Skip to content

Commit

Permalink
call profile list with fake spawner object
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Jan 7, 2024
1 parent 5f0a514 commit b1c502a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 4 additions & 5 deletions jhub_apps/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,11 @@ async def conda_environments(user: User = Depends(get_current_user)):
@router.get("/spawner-profiles/", description="Get all spawner profiles")
async def spawner_profiles(user: User = Depends(get_current_user)):
hclient = HubClient()
logger.info("*"*100)
logger.info(f"USER FROM HUB CLIENT: {hclient.get_user(user.name)}")
logger.info("*"*100)
logging.info(f"Getting spawner profiles for user: {user}")
user_from_service = hclient.get_user(user.name)
auth_state = user_from_service.get("auth_state")
logging.info(f"Getting spawner profiles for user: {user.name}")
config = get_jupyterhub_config()
spawner_profiles_ = await get_spawner_profiles(config)
spawner_profiles_ = await get_spawner_profiles(config, auth_state=auth_state)
logger.info(f"Loaded spawner profiles: {spawner_profiles_}")
return spawner_profiles_

Expand Down
12 changes: 10 additions & 2 deletions jhub_apps/service/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import logging
import os
from unittest.mock import Mock

import requests
from jupyterhub.app import JupyterHub
Expand Down Expand Up @@ -44,7 +45,14 @@ def get_conda_envs(config):
)


async def get_spawner_profiles(config):
def get_fake_spawner_object(auth_state):
fake_spawner = Mock()
fake_spawner.user.get_auth_state.return_value = auth_state
fake_spawner.log = logger
return fake_spawner


async def get_spawner_profiles(config, auth_state=None):
"""This will extract spawner profiles from the JupyterHub config
If the Spawner is KubeSpawner
"""
Expand All @@ -56,7 +64,7 @@ async def get_spawner_profiles(config):
elif callable(profile_list):
try:
logger.info("config.KubeSpawner.profile_list is a callable, calling now..")
return await profile_list()
return await profile_list(get_fake_spawner_object(auth_state))
except Exception as e:
logger.exception(e)
return []
Expand Down

0 comments on commit b1c502a

Please sign in to comment.