From cd97a786e858f3166b612ccae450082479f7a600 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Wed, 6 Jan 2021 13:50:41 +0800 Subject: [PATCH] [storage-blob] allow empty blobName to support root directory in datalake (#12890) * allow empty blobName to support root directory in datalake * remove .only * Merge branch 'master' into storage/issues/12813 * changelog --- sdk/storage/storage-blob/src/Clients.ts | 4 +- .../storage-file-datalake/CHANGELOG.md | 1 + ...rameters_for_root_directory_should_work.js | 109 ++++++++++++++++++ .../test/node/sas.spec.ts | 22 ++++ 4 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 sdk/storage/storage-file-datalake/recordings/node/sas_generation_nodejs_only_for_directory_sas/recording_generatedatalakesasqueryparameters_for_root_directory_should_work.js diff --git a/sdk/storage/storage-blob/src/Clients.ts b/sdk/storage/storage-blob/src/Clients.ts index 6672b3906cc6..558adecc22ca 100644 --- a/sdk/storage/storage-blob/src/Clients.ts +++ b/sdk/storage/storage-blob/src/Clients.ts @@ -2451,9 +2451,7 @@ export class BlobClient extends StorageClient { // doing the same in the SDK side so that the user doesn't have to replace "\" instances in the blobName blobName = blobName.replace(/\\/g, "/"); - if (!blobName) { - throw new Error("Provided blobName is invalid."); - } else if (!containerName) { + if (!containerName) { throw new Error("Provided containerName is invalid."); } diff --git a/sdk/storage/storage-file-datalake/CHANGELOG.md b/sdk/storage/storage-file-datalake/CHANGELOG.md index 684167753453..c912b1838bd3 100644 --- a/sdk/storage/storage-file-datalake/CHANGELOG.md +++ b/sdk/storage/storage-file-datalake/CHANGELOG.md @@ -2,6 +2,7 @@ ## 12.3.0-beta.2 (Unreleased) +- Now you can get the functionality of the root directory via the `DataLakeDirectoryClient` created via `FileSystemClient.getDirectoryClient("")`. Fixed bug [12813](https://github.com/Azure/azure-sdk-for-js/issues/12813). ## 12.3.0-beta.1 (2020-12-09) diff --git a/sdk/storage/storage-file-datalake/recordings/node/sas_generation_nodejs_only_for_directory_sas/recording_generatedatalakesasqueryparameters_for_root_directory_should_work.js b/sdk/storage/storage-file-datalake/recordings/node/sas_generation_nodejs_only_for_directory_sas/recording_generatedatalakesasqueryparameters_for_root_directory_should_work.js new file mode 100644 index 000000000000..ead18c6c89fa --- /dev/null +++ b/sdk/storage/storage-file-datalake/recordings/node/sas_generation_nodejs_only_for_directory_sas/recording_generatedatalakesasqueryparameters_for_root_directory_should_work.js @@ -0,0 +1,109 @@ +let nock = require('nock'); + +module.exports.hash = "b4b8deb6e1719c1d4d6d0f34b1905856"; + +module.exports.testInfo = {"uniqueName":{"filesystem":"filesystem160793974124704491","directory":"directory160793974271506132","file":"file160793974420506988"},"newDate":{"now":"2020-12-14T09:55:44.522Z","tmr":"2020-12-14T09:55:44.522Z"}} + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .put('/filesystem160793974124704491') + .query(true) + .reply(201, "", [ 'Content-Length', + '0', + 'Last-Modified', + 'Mon, 14 Dec 2020 09:55:42 GMT', + 'ETag', + '"0x8D8A0166B74058D"', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '7f24e959-d01e-002f-46ff-d1c4a4000000', + 'x-ms-client-request-id', + 'd61339dc-a836-445a-92f1-3297ff3b6dfa', + 'x-ms-version', + '2020-04-08', + 'Date', + 'Mon, 14 Dec 2020 09:55:42 GMT' ]); + +nock('https://fakestorageaccount.dfs.core.windows.net:443', {"encodedQueryParams":true}) + .put('/filesystem160793974124704491/directory160793974271506132') + .query(true) + .reply(201, "", [ 'Last-Modified', + 'Mon, 14 Dec 2020 09:55:44 GMT', + 'ETag', + '"0x8D8A0166C5BC1B3"', + 'Server', + 'Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'd0c75e86-f01f-007c-0bff-d1d8ab000000', + 'x-ms-version', + '2020-04-08', + 'x-ms-client-request-id', + 'c4ce70e2-2059-4efa-a52c-7a705df72aae', + 'Date', + 'Mon, 14 Dec 2020 09:55:43 GMT', + 'Content-Length', + '0' ]); + +nock('https://fakestorageaccount.dfs.core.windows.net:443', {"encodedQueryParams":true}) + .put('/filesystem160793974124704491/directory160793974271506132/file160793974420506988') + .query(true) + .reply(201, "", [ 'Last-Modified', + 'Mon, 14 Dec 2020 09:55:44 GMT', + 'ETag', + '"0x8D8A0166C8C691B"', + 'Server', + 'Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'd0c75e9c-f01f-007c-1fff-d1d8ab000000', + 'x-ms-version', + '2020-04-08', + 'x-ms-client-request-id', + '63dba480-6eb5-485b-b027-d1b64bad2a49', + 'Date', + 'Mon, 14 Dec 2020 09:55:43 GMT', + 'Content-Length', + '0' ]); + +nock('https://fakestorageaccount.dfs.core.windows.net:443', {"encodedQueryParams":true}) + .head('/filesystem160793974124704491/') + .query(true) + .reply(200, "", [ 'Last-Modified', + 'Mon, 14 Dec 2020 09:55:42 GMT', + 'ETag', + '"0x8D8A0166B75F9C6"', + 'Vary', + 'Origin', + 'Server', + 'Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-owner', + '$superuser', + 'x-ms-group', + '$superuser', + 'x-ms-permissions', + 'rwxr-x---', + 'x-ms-acl', + 'user::rwx,group::r-x,other::---', + 'x-ms-request-id', + 'd0c75eb6-f01f-007c-37ff-d1d8ab000000', + 'x-ms-version', + '2020-04-08', + 'x-ms-client-request-id', + '5ff65f53-8865-4378-afb8-044c06bd3ce5', + 'Date', + 'Mon, 14 Dec 2020 09:55:43 GMT' ]); + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .delete('/filesystem160793974124704491') + .query(true) + .reply(202, "", [ 'Content-Length', + '0', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '7f24eca7-d01e-002f-33ff-d1c4a4000000', + 'x-ms-client-request-id', + '3d00aa46-0ac5-473e-8772-bbf00e64352c', + 'x-ms-version', + '2020-04-08', + 'Date', + 'Mon, 14 Dec 2020 09:55:44 GMT' ]); diff --git a/sdk/storage/storage-file-datalake/test/node/sas.spec.ts b/sdk/storage/storage-file-datalake/test/node/sas.spec.ts index fa2ed7fc180e..4b481bb2f56d 100644 --- a/sdk/storage/storage-file-datalake/test/node/sas.spec.ts +++ b/sdk/storage/storage-file-datalake/test/node/sas.spec.ts @@ -920,6 +920,28 @@ describe("SAS generation Node.js only for directory SAS", () => { await directoryClientwithSAS.setPermissions(permissions); }); + it("generateDataLakeSASQueryParameters for root directory should work", async () => { + const rootDirName = ""; + const rootDirectoryClient = fileSystemClient.getDirectoryClient(rootDirName); + + const directorySAS = generateDataLakeSASQueryParameters( + { + fileSystemName: fileSystemClient.name, + pathName: rootDirectoryClient.name, + isDirectory: true, + directoryDepth: 1, + expiresOn: tmr, + permissions: DirectorySASPermissions.parse("racwdlmeop"), + version: "2020-02-10" + }, + sharedKeyCredential as StorageSharedKeyCredential + ); + const sasURL = `${rootDirectoryClient.url}?${directorySAS}`; + const directoryClientwithSAS = new DataLakeDirectoryClient(sasURL); + + await directoryClientwithSAS.getAccessControl(); + }); + function getDefualtDirctorySAS(directoryName: string): SASQueryParameters { return generateDataLakeSASQueryParameters( {