Browse Source

[api] Add user home directory in /get_filesystems public API (#3075)

- Change it to a new API method and point it to public API endpoint.
- Goal is to keep both the public and private API methods different for now because we are transitioning the file chooser component to React and once that is don't, we can faze out the private API methods and related code to clean it up.
- This commit does not break the old existing file chooser and its API for now.

Sample response:

[{"file_system": "hdfs", "user_home_directory": "/user/demo"}, {"file_system": "s3a", "user_home_directory": "s3a://<some_s3_path>"}, {"file_system": "abfs", "user_home_directory": "abfs://<some_abfs_path>"}]
Harsh Gupta 3 years ago
parent
commit
1f06507eb2
2 changed files with 24 additions and 2 deletions
  1. 23 1
      apps/filebrowser/src/filebrowser/api.py
  2. 1 1
      desktop/core/src/desktop/api_public.py

+ 23 - 1
apps/filebrowser/src/filebrowser/api.py

@@ -21,7 +21,8 @@ from desktop.lib.django_util import JsonResponse
 from desktop.lib import fsmanager
 from desktop.lib.i18n import smart_unicode
 
-from aws.conf import has_s3_access
+from azure.abfs.__init__ import get_home_dir_for_abfs
+from aws.s3.s3fs import get_s3_home_directory
 
 
 LOG = logging.getLogger(__name__)
@@ -52,3 +53,24 @@ def get_filesystems(request):
   response['filesystems'] = filesystems
 
   return JsonResponse(response)
+
+
+@error_handler
+def get_filesystems_with_home_dirs(request): # Using as a public API only for now
+  filesystems = []
+  user_home_dir = ''
+
+  for fs in fsmanager.get_filesystems(request.user):
+    if fs == 'hdfs':
+      user_home_dir = request.user.get_home_directory()
+    elif fs == 's3a':
+      user_home_dir = get_s3_home_directory(request.user)
+    elif fs == 'abfs':
+      user_home_dir = get_home_dir_for_abfs(request.user)
+
+    filesystems.append({
+      'file_system': fs,
+      'user_home_directory': user_home_dir,
+    })
+
+  return JsonResponse(filesystems, safe=False)

+ 1 - 1
desktop/core/src/desktop/api_public.py

@@ -192,7 +192,7 @@ def analyze_table(request, dialect, database, table, columns=None):
 @api_view(["POST"])
 def storage_get_filesystems(request):
   django_request = get_django_request(request)
-  return filebrowser_api.get_filesystems(django_request)
+  return filebrowser_api.get_filesystems_with_home_dirs(django_request)
 
 @api_view(["GET"])
 def storage_view(request, path):