From 9ecdbd5b75c2ee1e2ca0e21a3c736a0c28a1d410 Mon Sep 17 00:00:00 2001 From: Wei Wei Date: Fri, 28 May 2021 17:44:04 +0800 Subject: [PATCH] [Storage] Fix oauthCopySameAccount --- src/Storage/Storage.Management/ChangeLog.md | 1 + .../Blob/Cmdlet/StartAzureStorageBlobCopy.cs | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Storage/Storage.Management/ChangeLog.md b/src/Storage/Storage.Management/ChangeLog.md index d6d363376904..4b8a44524c19 100644 --- a/src/Storage/Storage.Management/ChangeLog.md +++ b/src/Storage/Storage.Management/ChangeLog.md @@ -23,6 +23,7 @@ - `Update-AzRmStorageShare` * Supported enable Smb Multichannel on File service - `Update-AzStorageFileServiceProperty` +* Fixed copy inside same account issue by access source with anynymous credentail, when copy Blob inside same account with Oauth credentail ## Version 3.7.0 * Supported file share snapshot diff --git a/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs b/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs index be81d99a50d8..80e130284dc0 100644 --- a/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs +++ b/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs @@ -626,7 +626,20 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha { try { - await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false); + Uri srcBlobUriWithCredentail = null; + if (Channel!=null && destChannel != null && + Channel.StorageContext!= null && destChannel.StorageContext != null + && Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName + && Channel.StorageContext.StorageAccount.Credentials.IsToken) + { + // if inside same account, source blob can be anonumous + srcBlobUriWithCredentail = srcBlob.SnapshotQualifiedUri; + } + else + { + srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials(); + } + await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false); } catch (StorageException ex) { @@ -648,7 +661,20 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha { try { - await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(Channel.StorageContext), destBlob).ConfigureAwait(false); + Uri srcBlobUriWithCredentail = null; + if (Channel != null && destChannel != null && + Channel.StorageContext != null && destChannel.StorageContext != null + && Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName + && Channel.StorageContext.StorageAccount.Credentials.IsToken) + { + // if inside same account, source blob can be anonumous + srcBlobUriWithCredentail = srcBlob.Uri; + } + else + { + srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials(Channel.StorageContext); + } + await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false); } catch (StorageException ex) {