From f78468a107266d0b6e02cc1833824cebe3ef117e Mon Sep 17 00:00:00 2001 From: Wei Wei Date: Mon, 28 Oct 2024 10:59:34 +0000 Subject: [PATCH] [Storage] Added a breaking warning : download blob will block input parameter -AbsoluteUri and -Context together (#26377) * [Storage] Added a warning for an upcoming breaking change for download blob with parameter -AbsoluteUri will not allow parameter -Context be input together. * add 1 more change log * fix warning not show problem --- src/Storage/Storage.Management/ChangeLog.md | 3 +++ .../Blob/Cmdlet/GetAzureStorageBlobContent.cs | 2 ++ .../Storage/Blob/StorageDataMovementCmdletBase.cs | 15 +-------------- src/Storage/Storage/Common/AzureStorageBlob.cs | 6 +++--- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Storage/Storage.Management/ChangeLog.md b/src/Storage/Storage.Management/ChangeLog.md index ffbab2c9f460..b2dd8e5de9fe 100644 --- a/src/Storage/Storage.Management/ChangeLog.md +++ b/src/Storage/Storage.Management/ChangeLog.md @@ -18,6 +18,9 @@ - Additional information about change #1 --> ## Upcoming Release +* Added a warning for an upcoming breaking change for download blob will block input parameter -AbsoluteUri and -Context together. + - `Get-AzStorageBlobContent` +* Revised AzureStorageBlob construct logic to make it more stable. ## Version 7.4.0 * Added a warning for an upcoming breaking change for removing references to "Microsoft.Azure.Storage.File" diff --git a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs index 67b526c0dc09..30699d24cd5e 100644 --- a/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs +++ b/src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs @@ -30,6 +30,7 @@ using Track2Models = global::Azure.Storage.Blobs.Models; using Azure.Storage.Blobs; using Azure.Storage; +using Microsoft.WindowsAzure.Commands.Common.CustomAttributes; namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet { @@ -112,6 +113,7 @@ public SwitchParameter CheckMd5 private bool checkMd5; + [CmdletParameterBreakingChangeWithVersion("AbsoluteUri", "13.0.0", "8.0.0", ChangeDescription = "When download blob with parameter AbsoluteUri (alias Uri, BlobUri), parameter Context will not be allowed to input together.")] [Alias("Uri", "BlobUri")] [Parameter(HelpMessage = "Blob uri to download from.", Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = UriParameterSet)] diff --git a/src/Storage/Storage/Blob/StorageDataMovementCmdletBase.cs b/src/Storage/Storage/Blob/StorageDataMovementCmdletBase.cs index 2788b7e6718a..230da745264b 100644 --- a/src/Storage/Storage/Blob/StorageDataMovementCmdletBase.cs +++ b/src/Storage/Storage/Blob/StorageDataMovementCmdletBase.cs @@ -112,20 +112,7 @@ protected override void BeginProcessing() protected virtual void DoBeginProcessing() { - CmdletOperationContext.Init(); - CmdletCancellationToken = _cancellationTokenSource.Token; - WriteDebugLog(String.Format(Resources.InitOperationContextLog, GetType().Name, CmdletOperationContext.ClientRequestId)); - - if (_enableMultiThread) - { - SetUpMultiThreadEnvironment(); - } - - OpContext.GlobalSendingRequest += - (sender, args) => - { - //https://github.com/Azure/azure-storage-net/issues/658 - }; + base.BeginProcessing(); OutputStream.ConfirmWriter = (s1, s2, s3) => ShouldContinue(s2, s3); diff --git a/src/Storage/Storage/Common/AzureStorageBlob.cs b/src/Storage/Storage/Common/AzureStorageBlob.cs index 76221baebd31..4fea5b79baa9 100644 --- a/src/Storage/Storage/Common/AzureStorageBlob.cs +++ b/src/Storage/Storage/Common/AzureStorageBlob.cs @@ -414,7 +414,7 @@ public static CloudBlob GetTrack1Blob(BlobBaseClient track2BlobClient, StorageCr return new InvalidCloudBlob(track2BlobClient.Uri, credentials); } - if (credentials.IsSAS) // the Uri already contains credentail. + if (credentials != null && credentials.IsSAS) // the Uri already contains credentail. { credentials = null; } @@ -497,12 +497,12 @@ public static BlobClient GetTrack2BlobClient(BlobBaseClient blobBaseClient, Azur return (BlobClient)blobBaseClient; } BlobClient blobClient; - if (context.StorageAccount != null && context.StorageAccount.Credentials != null && context.StorageAccount.Credentials.IsToken) //Oauth + if (context != null && context.StorageAccount != null && context.StorageAccount.Credentials != null && context.StorageAccount.Credentials.IsToken) //Oauth { blobClient = new BlobClient(blobBaseClient.Uri, context.Track2OauthToken, options); } - else if (context.StorageAccount != null && context.StorageAccount.Credentials != null && context.StorageAccount.Credentials.IsSharedKey) //Shared Key + else if (context != null && context.StorageAccount != null && context.StorageAccount.Credentials != null && context.StorageAccount.Credentials.IsSharedKey) //Shared Key { blobClient = new BlobClient(blobBaseClient.Uri, new StorageSharedKeyCredential(context.StorageAccountName, context.StorageAccount.Credentials.ExportBase64EncodedKey()), options);