Răsfoiți Sursa

[raz_adls] Improve rename operation and add chmod test

- We also need to sign the 'x-ms-rename-source' header for rename op with the separate SAS token.
- PS: Both the SAS tokens are different (the one required for signing the header and the one required for new renamed path).
Harshg999 4 ani în urmă
părinte
comite
7b2b22d24e

+ 1 - 1
desktop/core/src/desktop/lib/raz/raz_client.py

@@ -220,7 +220,7 @@ class RazClient(object):
         relative_path += lib_urlunquote(params['directory'])
     
     if method == 'PUT':
-      access_type = 'rename-destination'
+      access_type = 'rename-source'
       if params.get('resource') == 'file':
         access_type = 'create-file'
       elif params.get('resource') == 'directory':

+ 10 - 0
desktop/core/src/desktop/lib/raz/raz_client_test.py

@@ -263,6 +263,16 @@ class RazClientTest(unittest.TestCase):
     assert_equal(response['access_type'], 'write')
     assert_equal(response['relative_path'], '/user/csso_hueuser/customers.csv')
 
+    # Chmod
+    method = 'PATCH'
+    relative_path = '/user/csso_hueuser/customers.csv'
+    url_params = {'action': 'setAccessControl'}
+
+    response = client.handle_adls_req_mapping(method, url_params, relative_path)
+
+    assert_equal(response['access_type'], 'set-permission')
+    assert_equal(response['relative_path'], '/user/csso_hueuser/customers.csv')
+
 
   def test_get_raz_client_s3(self):
     with patch('desktop.lib.raz.raz_client.RazToken') as RazToken:

+ 12 - 1
desktop/libs/azure/src/azure/abfs/abfs.py

@@ -28,7 +28,7 @@ import threading
 import re
 
 from math import ceil
-from posixpath import join
+from posixpath import join, normpath
 
 from hadoop.hdfs_site import get_umask_mode
 from hadoop.fs.exceptions import WebHdfsException
@@ -36,6 +36,7 @@ from hadoop.fs.exceptions import WebHdfsException
 from desktop.conf import RAZ
 from desktop.lib.rest import http_client, resource
 from desktop.lib.rest.raz_http_client import RazHttpClient
+from desktop.lib.raz.clients import AdlsRazClient
 
 import azure.abfs.__init__ as Init_ABFS
 from azure.abfs.abfsfile import ABFSFile
@@ -572,6 +573,16 @@ class ABFS(object):
     Renames a file
     """
     headers = {'x-ms-rename-source': '/' + urllib_quote(Init_ABFS.strip_scheme(old))}
+
+    # Required to sign the header with SAS token for RAZ
+    if RAZ.IS_ENABLED.get():
+      raz_client = AdlsRazClient(username=self._user)
+      source_url = self._url + normpath('/' + headers['x-ms-rename-source'].lstrip('/'))
+
+      response = raz_client.get_url(action='PUT', path=source_url)
+      if response and response.get('token'):
+        headers['x-ms-rename-source'] += '?' + response['token']
+
     try:
       self._create_path(new, headers=headers, overwrite=True)
     except WebHdfsException as e: