From 02e8a8623e4b194dfd239edcb94f3fde1fcafd16 Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Fri, 8 Apr 2022 00:51:21 +0200
Subject: [PATCH] Fixes.

---
 services/standaloneworker/Dockerfile                 |  6 ++++--
 services/webapp/code/rosetta/core_app/api.py         |  9 ++++++---
 .../code/rosetta/core_app/computing_managers.py      | 12 ++++++------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/services/standaloneworker/Dockerfile b/services/standaloneworker/Dockerfile
index dbd134a..11ceace 100755
--- a/services/standaloneworker/Dockerfile
+++ b/services/standaloneworker/Dockerfile
@@ -21,8 +21,10 @@ RUN mkdir /home/testuser/.ssh
 COPY keys/id_rsa.pub /home/testuser/.ssh/authorized_keys
 RUN dnf install -y python wget
 
-# Install iputils (ping)
-RUN dnf install -y iputils
+# Install iputils (fpr ping) and openssh-clients (for scp)
+RUN dnf install -y iputils openssh-clients
+
+# TODO: Add the rosettta user
 
 # Copy registries.conf to allow insecure access to dregistry
 COPY registries.conf /etc/containers/registries.conf
diff --git a/services/webapp/code/rosetta/core_app/api.py b/services/webapp/code/rosetta/core_app/api.py
index 9a44798..c52dd77 100644
--- a/services/webapp/code/rosetta/core_app/api.py
+++ b/services/webapp/code/rosetta/core_app/api.py
@@ -321,7 +321,7 @@ print(port)
                 return HttpResponse('Port not valid (got "{}")'.format(task_interface_port))
               
             # Set fields
-            logger.info('Setting task "{}" to ip "{}" and port "{}"'.format(task.uuid, task_interface_ip, task_interface_port))
+            logger.info('Agent API setting task "{}" to ip "{}" and port "{}"'.format(task.uuid, task_interface_ip, task_interface_port))
             task.status = TaskStatuses.running
             task.interface_ip = task_interface_ip
             
@@ -349,7 +349,7 @@ print(port)
             # Notify the user that the task called back home if using a WMS
             if task.computing.wms:
                 if settings.DJANGO_EMAIL_APIKEY:
-                    logger.info('Sending task ready mail notification to "{}"'.format(task.user.email))
+                    logger.info('Agent API sending task ready mail notification to "{}"'.format(task.user.email))
                     mail_subject = 'Your Task "{}" is now starting up'.format(task.container.name)
                     mail_text = 'Hello,\n\nyour Task "{}" on {} is now starting up. Check logs or connect here: https://{}/tasks/?uuid={}\n\nThe Rosetta notifications bot.'.format(task.container.name, task.computing, settings.ROSETTA_HOST, task.uuid)
                     try:
@@ -449,7 +449,7 @@ class FileManagerAPI(PrivateGETAPI, PrivatePOSTAPI):
             else:
                 raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
         if '$USER' in base_path_expanded:
-            base_path_expanded = base_path_expanded.replace('$USER', user.name)
+            base_path_expanded = base_path_expanded.replace('$USER', user.username)
 
         # If the path is not starting with the base path, do it
         if not path.startswith(base_path_expanded):
@@ -757,6 +757,9 @@ class FileManagerAPI(PrivateGETAPI, PrivatePOSTAPI):
                     if not storage.type=='generic_posix'  and storage.access_mode=='ssh+cli':
                         continue
                     
+                    if storage.access_through_computing and not storage.computing.manager.is_configured_for(user=request.user):
+                        continue
+                    
                     data['data'].append({
                                          'id': '/{}/'.format(storage.id),
                                          'type': 'folder',
diff --git a/services/webapp/code/rosetta/core_app/computing_managers.py b/services/webapp/code/rosetta/core_app/computing_managers.py
index ff6dfcb..9a92361 100644
--- a/services/webapp/code/rosetta/core_app/computing_managers.py
+++ b/services/webapp/code/rosetta/core_app/computing_managers.py
@@ -249,7 +249,7 @@ class SSHStandaloneComputingManager(StandaloneComputingManager, SSHComputingMana
                         else:
                             raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
                     if '$USER' in expanded_base_path:
-                        expanded_base_path = expanded_base_path.replace('$USER', self.task.user.name)
+                        expanded_base_path = expanded_base_path.replace('$USER', task.user.username)
                         
                     # Expand the bind_path
                     expanded_bind_path = storage.bind_path        
@@ -259,7 +259,7 @@ class SSHStandaloneComputingManager(StandaloneComputingManager, SSHComputingMana
                         else:
                             raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
                     if '$USER' in expanded_bind_path:
-                        expanded_bind_path = expanded_bind_path.replace('$USER', self.task.user.name)
+                        expanded_bind_path = expanded_bind_path.replace('$USER', task.user.username)
                         
                     # Add the bind
                     if not binds:
@@ -309,7 +309,7 @@ class SSHStandaloneComputingManager(StandaloneComputingManager, SSHComputingMana
                         else:
                             raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
                     if '$USER' in expanded_base_path:
-                        expanded_base_path = expanded_base_path.replace('$USER', self.task.user.name)
+                        expanded_base_path = expanded_base_path.replace('$USER', task.user.username)
                         
                     # Expand the bind_path
                     expanded_bind_path = storage.bind_path        
@@ -319,7 +319,7 @@ class SSHStandaloneComputingManager(StandaloneComputingManager, SSHComputingMana
                         else:
                             raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
                     if '$USER' in expanded_bind_path:
-                        expanded_bind_path = expanded_bind_path.replace('$USER', self.task.user.name)
+                        expanded_bind_path = expanded_bind_path.replace('$USER', task.user.username)
                         
                     # Add the bind
                     if not binds:
@@ -502,7 +502,7 @@ class SlurmSSHClusterComputingManager(ClusterComputingManager, SSHComputingManag
                         else:
                             raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
                     if '$USER' in expanded_base_path:
-                        expanded_base_path = expanded_base_path.replace('$USER', self.task.user.name)
+                        expanded_base_path = expanded_base_path.replace('$USER', task.user.username)
                         
                     # Expand the bind_path
                     expanded_bind_path = storage.bind_path        
@@ -512,7 +512,7 @@ class SlurmSSHClusterComputingManager(ClusterComputingManager, SSHComputingManag
                         else:
                             raise NotImplementedError('Accessing a storage with ssh+cli without going through its computing resource is not implemented')
                     if '$USER' in expanded_bind_path:
-                        expanded_bind_path = expanded_bind_path.replace('$USER', self.task.user.name)
+                        expanded_bind_path = expanded_bind_path.replace('$USER', task.user.username)
                         
                     # Add the bind
                     if not binds:
-- 
GitLab