From c5575d74ef45ac1a4b8b22ae58cb59ddd7a989ae Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Tue, 4 Apr 2023 13:18:03 +0800 Subject: [PATCH 1/6] Fix for slash issue --- .../Blob/Cmdlet/GetAzureStorageBlob.cs | 3 ++- src/Storage/Storage/Common/Util.cs | 19 +++++++++++++++++++ src/Storage/Storage/Storage.csproj | 8 ++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs index f00732cbb2f7..b100c9426808 100644 --- a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs +++ b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs @@ -329,6 +329,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC { if (blobFilter == null || blobFilter(item.Name)) { + ClientOptions.TrimBlobNameSlashes = false; OutputStream.WriteObject(taskId, GetAzureStorageBlob(item, track2container, localChannel.StorageContext, page.ContinuationToken, ClientOptions)); } realListCount++; @@ -387,7 +388,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC public static AzureStorageBlob GetAzureStorageBlob(BlobItem blobItem, BlobContainerClient track2container, AzureStorageContext context, string continuationToken = null, BlobClientOptions options = null) { - BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType); + BlobBaseClient blobClient = Util.GetTrack2BlobClientNoSlashTrim(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType); AzureStorageBlob outputblob = new AzureStorageBlob(blobClient, context, options, blobItem); if (!string.IsNullOrEmpty(continuationToken)) { diff --git a/src/Storage/Storage/Common/Util.cs b/src/Storage/Storage/Common/Util.cs index 8897e4698dec..b5b4e247f968 100644 --- a/src/Storage/Storage/Common/Util.cs +++ b/src/Storage/Storage/Common/Util.cs @@ -419,6 +419,25 @@ public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2conta return GetTrack2BlobClient(blobUriBuilder.ToUri(), context, options, blobType); } + public static BlobBaseClient GetTrack2BlobClientNoSlashTrim(BlobContainerClient track2container, string blobName, AzureStorageContext context, string versionId = null, bool? IsCurrentVersion = null, string snapshot = null, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null) + { + //Get Track2 Blob Client Uri + BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri, false) + { + BlobName = blobName + }; + if (versionId != null && (IsCurrentVersion == null || !IsCurrentVersion.Value)) // only none current version blob need versionId in Uri + { + blobUriBuilder.VersionId = versionId; + } + if (snapshot != null) + { + blobUriBuilder.Snapshot = snapshot; + } + + return GetTrack2BlobClient(blobUriBuilder.ToUri(), context, options, blobType); + } + public static BlobBaseClient GetTrack2BlobClient(Uri blobUri, AzureStorageContext context, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null) { BlobBaseClient blobClient; diff --git a/src/Storage/Storage/Storage.csproj b/src/Storage/Storage/Storage.csproj index 2c1e7b7dbc3f..960623e26526 100644 --- a/src/Storage/Storage/Storage.csproj +++ b/src/Storage/Storage/Storage.csproj @@ -13,10 +13,10 @@ - - - - + + + + From f4a73601a09af7f9f54288f2b32c65efc5341a56 Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Mon, 10 Apr 2023 11:15:48 +0800 Subject: [PATCH 2/6] update GetTrack2BlobClient input --- src/Storage/Storage.Management/ChangeLog.md | 2 ++ .../Blob/Cmdlet/GetAzureStorageBlob.cs | 2 +- src/Storage/Storage/Common/Util.cs | 23 ++----------------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/Storage/Storage.Management/ChangeLog.md b/src/Storage/Storage.Management/ChangeLog.md index 6199d5b12e61..3bc59e98fea6 100644 --- a/src/Storage/Storage.Management/ChangeLog.md +++ b/src/Storage/Storage.Management/ChangeLog.md @@ -18,6 +18,8 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixed the issue of listing blobs with leading slashes + - `Get-AzStorageBlob` * Added warning messages for an upcoming cmdlet breaking change - `New-AzStorageAccount` - `Set-AzStorageAccount` diff --git a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs index b100c9426808..dbf3043992ff 100644 --- a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs +++ b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs @@ -388,7 +388,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC public static AzureStorageBlob GetAzureStorageBlob(BlobItem blobItem, BlobContainerClient track2container, AzureStorageContext context, string continuationToken = null, BlobClientOptions options = null) { - BlobBaseClient blobClient = Util.GetTrack2BlobClientNoSlashTrim(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType); + BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType, shouldTrimSlash: false); AzureStorageBlob outputblob = new AzureStorageBlob(blobClient, context, options, blobItem); if (!string.IsNullOrEmpty(continuationToken)) { diff --git a/src/Storage/Storage/Common/Util.cs b/src/Storage/Storage/Common/Util.cs index b5b4e247f968..fd21c2129cd8 100644 --- a/src/Storage/Storage/Common/Util.cs +++ b/src/Storage/Storage/Common/Util.cs @@ -400,29 +400,10 @@ public static Hashtable GetHashtableFromDictionary(IDictionary d } } - public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2container, string blobName, AzureStorageContext context, string versionId = null, bool? IsCurrentVersion = null, string snapshot = null, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null) + public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2container, string blobName, AzureStorageContext context, string versionId = null, bool? IsCurrentVersion = null, string snapshot = null, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null, bool shouldTrimSlash = true) { //Get Track2 Blob Client Uri - BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri) - { - BlobName = blobName - }; - if (versionId != null && (IsCurrentVersion == null || !IsCurrentVersion.Value)) // only none current version blob need versionId in Uri - { - blobUriBuilder.VersionId = versionId; - } - if (snapshot != null) - { - blobUriBuilder.Snapshot = snapshot; - } - - return GetTrack2BlobClient(blobUriBuilder.ToUri(), context, options, blobType); - } - - public static BlobBaseClient GetTrack2BlobClientNoSlashTrim(BlobContainerClient track2container, string blobName, AzureStorageContext context, string versionId = null, bool? IsCurrentVersion = null, string snapshot = null, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null) - { - //Get Track2 Blob Client Uri - BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri, false) + BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri, trimBlobNameSlashes: shouldTrimSlash) { BlobName = blobName }; From 9e99f926f8400cae1ded0f747d50e4133dc6f9a4 Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Wed, 12 Apr 2023 11:34:13 +0800 Subject: [PATCH 3/6] update sdk dependency --- .../Storage.Management.Test.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Storage/Storage.Management.Test/Storage.Management.Test.csproj b/src/Storage/Storage.Management.Test/Storage.Management.Test.csproj index 0dfbecdf7239..97ce5b63b9a5 100644 --- a/src/Storage/Storage.Management.Test/Storage.Management.Test.csproj +++ b/src/Storage/Storage.Management.Test/Storage.Management.Test.csproj @@ -11,10 +11,10 @@ - - - - + + + + From e707707d25e64e9ad5169c6fb9d2a6744d4e49b6 Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Thu, 13 Apr 2023 13:09:11 +0800 Subject: [PATCH 4/6] Add warning message for breaking change --- src/Storage/Storage.Management/ChangeLog.md | 2 ++ src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/Storage/Storage.Management/ChangeLog.md b/src/Storage/Storage.Management/ChangeLog.md index c9fb1ad4f1bd..963885357ad0 100644 --- a/src/Storage/Storage.Management/ChangeLog.md +++ b/src/Storage/Storage.Management/ChangeLog.md @@ -18,6 +18,8 @@ - Additional information about change #1 --> ## Upcoming Release +* Added a warning message for an upcoming breaking change when getting a single blob + - `Get-AzStorageBlob` * Fixed the issue of listing blobs with leading slashes - `Get-AzStorageBlob` * Added warning messages for an upcoming cmdlet breaking change diff --git a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs index dbf3043992ff..bc2a789acc08 100644 --- a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs +++ b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs @@ -34,6 +34,9 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet /// /// list azure blobs in specified azure container /// + [GenericBreakingChange("Leading and trailing slashes on the blob name will not be trimmed when getting a single blob", + OldWay = "Leading and trailing slashes on the blob name are trimmed", + NewWay = "Leading and trailing slashes on the blob name are not trimmed")] [Cmdlet("Get", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlob", DefaultParameterSetName = NameParameterSet),OutputType(typeof(AzureStorageBlob))] public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase { From 74b6dab6ac8c18452d039b17c197dea6ecfbee6e Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Thu, 13 Apr 2023 15:56:09 +0800 Subject: [PATCH 5/6] Update warning message --- src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs index bc2a789acc08..3ed6672a50ff 100644 --- a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs +++ b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs @@ -34,9 +34,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet /// /// list azure blobs in specified azure container /// - [GenericBreakingChange("Leading and trailing slashes on the blob name will not be trimmed when getting a single blob", - OldWay = "Leading and trailing slashes on the blob name are trimmed", - NewWay = "Leading and trailing slashes on the blob name are not trimmed")] + [GenericBreakingChange("Leading and trailing slashes on the blob name will not be trimmed when getting a single blob")] [Cmdlet("Get", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlob", DefaultParameterSetName = NameParameterSet),OutputType(typeof(AzureStorageBlob))] public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase { From 17fc4a555d1e24c6b68c116f06cb3668d7e2dc2a Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Thu, 13 Apr 2023 17:04:26 +0800 Subject: [PATCH 6/6] Update warning message to apply to just the parameter --- src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs index 3ed6672a50ff..7877c42758dd 100644 --- a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs +++ b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs @@ -34,7 +34,6 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet /// /// list azure blobs in specified azure container /// - [GenericBreakingChange("Leading and trailing slashes on the blob name will not be trimmed when getting a single blob")] [Cmdlet("Get", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlob", DefaultParameterSetName = NameParameterSet),OutputType(typeof(AzureStorageBlob))] public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase { @@ -58,6 +57,7 @@ public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase /// private const string SingleBlobVersionIDParameterSet = "SingleBlobVersionID"; + [CmdletParameterBreakingChange("Blob", ChangeDescription = "Leading and trailing slashes will not be trimmed in a future release.")] [Parameter(Position = 0, HelpMessage = "Blob name", ParameterSetName = NameParameterSet)] [Parameter(Position = 0, Mandatory = true, HelpMessage = "Blob name", ParameterSetName = SingleBlobSnapshotTimeParameterSet)] [Parameter(Position = 0, Mandatory = true, HelpMessage = "Blob name", ParameterSetName = SingleBlobVersionIDParameterSet)]