Browse Source

[api] Provide default fs

Romain Rigaux 4 years ago
parent
commit
cfbdfab5ae

+ 9 - 1
apps/filebrowser/src/filebrowser/views.py

@@ -47,6 +47,7 @@ from django.utils.html import escape
 from aws.s3.s3fs import S3FileSystemException, S3ListAllBucketsException, get_s3_home_directory
 from desktop import appmanager
 from desktop.auth.backend import is_admin
+from desktop.lib import fsmanager
 from desktop.lib import i18n
 from desktop.lib.conf import coerce_bool
 from desktop.lib.django_util import render, format_preserving_redirect
@@ -209,6 +210,12 @@ def view(request, path):
   if path != decoded_path:
     path = decoded_path
 
+  if request.path.startswith('/api/') and request.fs is None:
+    request.fs = fsmanager.get_filesystem(request.fs_ref)
+
+    if request.user.is_authenticated and request.fs is not None:
+      request.fs.setuser(request.user.username)
+
   # default_abfs_home is set in jquery.filechooser.js
   if 'default_abfs_home' in request.GET:
     from azure.abfs.__init__ import get_home_dir_for_ABFS
@@ -451,6 +458,7 @@ def listdir(request, path):
   data['files'] = [_massage_stats(request, stat_absolute_path(path, stat)) for stat in stats]
   return render('listdir.mako', request, data)
 
+
 def _massage_page(page, paginator):
   try:
     prev_num = page.previous_page_number()
@@ -517,7 +525,6 @@ def listdir_paged(request, path):
     s3_listing_not_allowed = str(e)
     all_stats = []
 
-
   # Filter first
   filter_str = request.GET.get('filter', None)
   if filter_str:
@@ -596,6 +603,7 @@ def listdir_paged(request, path):
   }
   return render('listdir.mako', request, data)
 
+
 def scheme_absolute_path(root, path):
   splitPath = lib_urlparse(path)
   splitRoot = lib_urlparse(root)

+ 2 - 2
desktop/core/src/desktop/lib/view_util.py

@@ -92,10 +92,10 @@ def format_duration_in_millis(duration=0):
 
 def is_ajax(request):
   if sys.version_info[0] > 2:
-    _is_ajax = request.headers.get('x-requested-with') == 'XMLHttpRequest'
+    _is_ajax = request.headers.get('x-requested-with') == 'XMLHttpRequest' or request.path.startswith('/api/')
   else:
     _is_ajax = request.is_ajax()
-  
+
   return _is_ajax
 
 def location_to_url(location, strict=True, is_embeddable=False):

+ 2 - 3
desktop/core/src/desktop/settings.py

@@ -294,12 +294,11 @@ REST_FRAMEWORK = {
 }
 
 SIMPLE_JWT = {
-  'ACCESS_TOKEN_LIFETIME': datetime.timedelta(minutes=55),
-  'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=1),
+  'ACCESS_TOKEN_LIFETIME': datetime.timedelta(days=1),
+  'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=7),
   'ROTATE_REFRESH_TOKENS': False,
   'BLACKLIST_AFTER_ROTATION': True,
   'UPDATE_LAST_LOGIN': False,
-  # 'SIGNING_KEY': SECRET_KEY,
   'AUTH_HEADER_TYPES': ('Bearer',),
 }
 

+ 27 - 8
docs/docs-site/content/developer/api/rest/_index.md

@@ -305,11 +305,11 @@ For a specific function/UDF details (e.g. trunc):
 
 ### List
 
-Hue's [File Browser](https://docs.gethue.com/user/browsing/#data) offer uploads, downloads and listing of data in HDFS, S3, ADLS storages.
+Hue's [File Browser](https://docs.gethue.com/user/browsing/#data) offer uploads, downloads, operations (create, delete, chmod...) and listing of data in HDFS (hdfs:// or no prefix), S3 (s3a:// prefix), ADLS (adls:// or abfs:// prefixes) storages.
 
-Here is how to list the content of a path, here the S3 bucket `S3A://gethue-demo`:
+Here is how to list the content of a path, here a S3 bucket `s3a://gethue-demo`:
 
-    curl -X GET "https://demo.gethue.com/filebrowser/view=S3A://gethue-demo?pagesize=45&pagenum=1&filter=&sortby=name&descending=false&format=json"
+    curl -X GET "https://demo.gethue.com/api/storage/view=s3a://gethue-demo"
 
     {
       ...........
@@ -360,11 +360,22 @@ Here is how to list the content of a path, here the S3 bucket `S3A://gethue-demo
       ...........
     }
 
-### Get file content
+Some of the parameters:
+ - pagesize=45
+ - pagenum=1
+ - filter=
+ - sortby=name
+ - descending=false
 
-How to get the file content and its metadata. Here with the public file of demo.gethue.com [s3a://demo-hue/web_log_data/index_data.csv](https://demo.gethue.com/hue/filebrowser/view=s3a%3A%2F%2Fdemo-hue%2Fweb_log_data%2Findex_data.csv):
+e.g. pagesize=45&pagenum=1&filter=&sortby=name&descending=false
 
-    curl -X GET https://demo.gethue.com/api/storage/view=s3a://demo-hue/web_log_data/index_data.csv?offset=0&length=204800&compression=none&mode=text
+### Preview
+
+How to get the some of the file content and its stats/metadata.
+
+Example with a S3 file:
+
+    curl -X GET https://demo.gethue.com/api/storage/view=s3a://demo-hue/web_log_data/index_data.csv
 
     {
       "show_download_button": true,
@@ -385,11 +396,19 @@ How to get the file content and its metadata. Here with the public file of demo.
       ...............
     }
 
-### Download a file
+Some of the parameters:
+- offset=0
+- length=204800
+- compression=none
+- mode=text
+
+e.g. ?offset=0&length=204800&compression=none&mode=text
+
+### Download
 
     GET http://127.0.0.1:9000/filebrowser/download=s3a://demo-hue/web_log_data/index_data.csv
 
-### Upload a file
+### Upload
 
     POST http://127.0.0.1:9000/filebrowser/upload/file?dest=s3a://demo-hue