Преглед изворни кода

HUE-9076 [editor] Support domain in azure URL

Jean-Francois Desjeans Gauthier пре 6 година
родитељ
комит
7f3fdc3946

+ 12 - 1
desktop/core/src/desktop/js/ko/components/assist/assistStorageEntry.js

@@ -349,7 +349,18 @@ class AssistStorageEntry {
       apiHelper: apiHelper
     });
 
-    path = (typeMatch ? typeMatch[2] : path).replace(/(?:^\/)|(?:\/$)/g, '').split('/');
+    if (type == 'abfs' || type == 'adls') {
+      // ABFS / ADLS can have domain name in path. To prevent regression with s3 which allow periods in bucket name handle separately.
+      const azureMatch = path.match(
+        /^([^:]+):\/(\/((\w+)@)?[\w]+([\-\.]{1}\w+)*\.[\w]*)?(\/.*)?\/?/i
+      );
+      path = (azureMatch ? azureMatch[6] || '' : path).replace(/(?:^\/)|(?:\/$)/g, '').split('/');
+      if (azureMatch && azureMatch[4]) {
+        path.unshift(azureMatch[4]);
+      }
+    } else {
+      path = (typeMatch ? typeMatch[2] : path).replace(/(?:^\/)|(?:\/$)/g, '').split('/');
+    }
 
     rootEntry.loadDeep(path, deferred.resolve);
 

+ 77 - 0
desktop/core/src/desktop/js/ko/components/assist/spec/assistStorageEntrySpec.js

@@ -0,0 +1,77 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import AssistStorageEntry from 'ko/components/assist/assistStorageEntry';
+
+describe('assistStorageEntry.js', () => {
+  beforeAll(() => {});
+
+  beforeEach(() => {
+    jasmine.Ajax.install();
+  });
+
+  afterEach(() => {
+    jasmine.Ajax.uninstall();
+  });
+
+  it('it should handle domain in ADLS/ABFS', () => {
+    jasmine.Ajax.stubRequest(
+      '/filebrowser/view=ABFS%3A%2F%2F?format=json&sortby=name&descending=false&pagesize=100&pagenum=1'
+    ).andReturn({
+      status: 200,
+      contentType: 'application/json',
+      responseText: JSON.stringify({
+        status: 0,
+        files: [{ name: 'path' }],
+        page: { next_page_number: 0 }
+      })
+    });
+    AssistStorageEntry.getEntry('abfs://test.com/path').always(entry => {
+      expect(entry.path).toBe('/path');
+    });
+    AssistStorageEntry.getEntry('abfs://path').always(entry => {
+      expect(entry.path).toBe('/path');
+    });
+    AssistStorageEntry.getEntry('abfs://path@test.com').always(entry => {
+      expect(entry.path).toBe('/path');
+    });
+    jasmine.Ajax.stubRequest(
+      '/filebrowser/view=ABFS%3A%2F%2F?format=json&sortby=name&descending=false&pagesize=100&pagenum=1'
+    ).andReturn({
+      status: 200,
+      contentType: 'application/json',
+      responseText: JSON.stringify({
+        status: 0,
+        files: [{ name: 'p1' }],
+        page: { next_page_number: 0 }
+      })
+    });
+    jasmine.Ajax.stubRequest(
+      '/filebrowser/view=ABFS%3A%2F%2Fp1?format=json&sortby=name&descending=false&pagesize=100&pagenum=1'
+    ).andReturn({
+      status: 200,
+      contentType: 'application/json',
+      responseText: JSON.stringify({
+        status: 0,
+        files: [{ name: 'p2' }],
+        page: { next_page_number: 0 }
+      })
+    });
+    AssistStorageEntry.getEntry('abfs://p1@test.com/p2').always(entry => {
+      expect(entry.path).toBe('/p1/p2');
+    });
+  });
+});