How to pull some files from artifactory and place in home location for the user based on auth state?

I am attempting to pull files from Artifactory and place them in the user’s home directory based on their authentication state, which is provided by a custom authenticator. Currently, I am using the pre_spawn_hook() method, but I am encountering a ‘Permission Denied’ error when trying to save files to the /home/jovyan location.

At risk of stating the obvious, have you checked the permissions on the mounted volume are correct? Do you have problems when you’re not using the pre_spawn_hook? What user-id are you using when copying the files? Can you share your full configuration?

1 Like

Hi @manics Thanks for the quick reply. Here is the code for the pre_spawn_hook, we are using user id as 1000

async def pre_spawn_hook(self, spawner):
user = self.user
auth_state = await user.get_auth_state()
if auth_state:
tenant = auth_state.get(‘tenant’)
groups = auth_state.get(“oauth_user”, {}).get(“groups”, )
self.logger.info(f"User : {self.user.name} - Selected spawning options - {self.user_options} “)
jfrog_url = ‘https://jfrog.in/artifactory/repo/file/1.0.0/file.tar
temp_tar_path = ‘./file.tar’
extract_dir = ‘/home/jovyan’
self.download_tar(jfrog_url, temp_tar_path)
print(f"Downloaded tar file to {temp_tar_path}”)
self.extract_tar(temp_tar_path, extract_dir)
print(f"Extracted tar file to {extract_dir}")
def download_tar(self,jfrog_url, temp_tar_path):
response = requests.get(jfrog_url)
with open(temp_tar_path, ‘wb’) as f:
f.write(response.content)
def extract_tar(self,temp_tar_path, extract_dir):
print(os.getcwd())
if not os.path.exists(extract_dir):
os.makedirs(extract_dir)
with tarfile.open(temp_tar_path, ‘r:*’) as tar:
tar.extractall(path=extract_dir)

`

pre_spawn_hook runs in the hub pod, so it won’t have access to the singleuser server storage. You’ll need to run a hook in the singleuser pod instead, for example see