Skip to content

Commit 4e9d5aa

Browse files
authored
[Storage] Fix oauthCopySameAccount (#15152)
1 parent 8292e60 commit 4e9d5aa

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- `Update-AzRmStorageShare`
2424
* Supported enable Smb Multichannel on File service
2525
- `Update-AzStorageFileServiceProperty`
26+
* Fixed copy inside same account issue by access source with anynymous credentail, when copy Blob inside same account with Oauth credentail
2627

2728
## Version 3.7.0
2829
* Supported file share snapshot

src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,20 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha
626626
{
627627
try
628628
{
629-
await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false);
629+
Uri srcBlobUriWithCredentail = null;
630+
if (Channel!=null && destChannel != null &&
631+
Channel.StorageContext!= null && destChannel.StorageContext != null
632+
&& Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName
633+
&& Channel.StorageContext.StorageAccount.Credentials.IsToken)
634+
{
635+
// if inside same account, source blob can be anonumous
636+
srcBlobUriWithCredentail = srcBlob.SnapshotQualifiedUri;
637+
}
638+
else
639+
{
640+
srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials();
641+
}
642+
await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false);
630643
}
631644
catch (StorageException ex)
632645
{
@@ -648,7 +661,20 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha
648661
{
649662
try
650663
{
651-
await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(Channel.StorageContext), destBlob).ConfigureAwait(false);
664+
Uri srcBlobUriWithCredentail = null;
665+
if (Channel != null && destChannel != null &&
666+
Channel.StorageContext != null && destChannel.StorageContext != null
667+
&& Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName
668+
&& Channel.StorageContext.StorageAccount.Credentials.IsToken)
669+
{
670+
// if inside same account, source blob can be anonumous
671+
srcBlobUriWithCredentail = srcBlob.Uri;
672+
}
673+
else
674+
{
675+
srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials(Channel.StorageContext);
676+
}
677+
await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false);
652678
}
653679
catch (StorageException ex)
654680
{

0 commit comments

Comments
 (0)