-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[DO NOT MERGE]Add support for delegation sas #28951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,7 +149,20 @@ public string ConnectionString { | |
| /// <param name="accountName">Storage account name</param> | ||
| /// <param name="DefaultContext"></param> | ||
| /// <param name="logWriter"></param> | ||
| public AzureStorageContext(CloudStorageAccount account, string accountName = null, IAzureContext DefaultContext = null, DebugLogWriter logWriter = null) | ||
| public AzureStorageContext(CloudStorageAccount account, string accountName = null, IAzureContext DefaultContext = null, DebugLogWriter logWriter = null) : | ||
| this(account, accountName, false, null, null) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create a storage context usign cloud storage account | ||
|
||
| /// </summary> | ||
| /// <param name="account">cloud storage account</param> | ||
| /// <param name="accountName">Storage account name</param> | ||
| /// <param name="isOAuthToken"></param> | ||
| /// <param name="DefaultContext"></param> | ||
| /// <param name="logWriter"></param> | ||
| public AzureStorageContext(CloudStorageAccount account, string accountName = null, bool isOAuthToken = false, IAzureContext DefaultContext = null, DebugLogWriter logWriter = null) | ||
| { | ||
| StorageAccount = account; | ||
| TableStorageAccount = XTable.CloudStorageAccount.Parse(StorageAccount.ToString(true)); | ||
|
|
@@ -195,7 +208,8 @@ public AzureStorageContext(CloudStorageAccount account, string accountName = nul | |
| StorageAccountName = "[Anonymous]"; | ||
| } | ||
| } | ||
| if (account.Credentials != null && account.Credentials.IsToken) | ||
| if ((account.Credentials != null && account.Credentials.IsToken) | ||
| || isOAuthToken) | ||
| { | ||
| Track2OauthToken = new AzureSessionCredential(DefaultContext, logWriter); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,20 +15,22 @@ | |||||
|
|
||||||
| namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet | ||||||
| { | ||||||
| using System; | ||||||
| using System.Collections.Generic; | ||||||
| using System.Management.Automation; | ||||||
| using System.Security.Permissions; | ||||||
| using System.Threading.Tasks; | ||||||
| using Azure.Commands.Common.Authentication.Abstractions; | ||||||
| using Commands.Common.Storage.ResourceModel; | ||||||
| using global::Azure; | ||||||
| using global::Azure.Core; | ||||||
| using global::Azure.Storage.Blobs; | ||||||
| using global::Azure.Storage.Blobs.Models; | ||||||
| using global::Azure.Storage.Blobs.Specialized; | ||||||
| using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||||||
| using Microsoft.Azure.Storage.Blob; | ||||||
| using Microsoft.WindowsAzure.Commands.Storage.Common; | ||||||
| using Microsoft.WindowsAzure.Commands.Storage.Model.Contract; | ||||||
| using System; | ||||||
| using System.Collections.Generic; | ||||||
| using System.Management.Automation; | ||||||
| using System.Security.Permissions; | ||||||
| using System.Threading.Tasks; | ||||||
| using Track2Models = global::Azure.Storage.Blobs.Models; | ||||||
|
|
||||||
| [Cmdlet("Copy", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlob", SupportsShouldProcess = true, DefaultParameterSetName = ContainerNameParameterSet),OutputType(typeof(AzureStorageBlob))] | ||||||
|
|
@@ -323,7 +325,7 @@ private void CopyBlobSync(IStorageBlobManagement destChannel, BlobBaseClient src | |||||
| destCloudBlob = Util.GetTrack2BlobClientWithType(destCloudBlob, destChannel.StorageContext, srcBlobType, ClientOptions); | ||||||
| } | ||||||
|
|
||||||
| Func<long, Task> taskGenerator = (taskId) => CopyFromUri(taskId, destChannel, srcCloudBlob.GenerateUriWithCredentials(Channel.StorageContext), destCloudBlob); | ||||||
| Func<long, Task> taskGenerator = (taskId) => CopyFromUri(taskId, destChannel, srcCloudBlob.GenerateUriWithCredentials(Channel.StorageContext), Channel, destCloudBlob); | ||||||
| RunTask(taskGenerator); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -332,15 +334,24 @@ private void CopyBlobSync(IStorageBlobManagement destChannel, string srcUri, str | |||||
| Track2Models.BlobType srcBlobType = Util.GetBlobType(new BlobBaseClient(new Uri(srcUri), ClientOptions), true).Value; | ||||||
|
|
||||||
| BlobBaseClient destBlob = this.GetDestBlob(destChannel, destContainer, destBlobName, srcBlobType); | ||||||
| Func<long, Task> taskGenerator = (taskId) => CopyFromUri(taskId, destChannel, new Uri(srcUri), destBlob); | ||||||
| Func<long, Task> taskGenerator = (taskId) => CopyFromUri(taskId, destChannel, new Uri(srcUri), Channel, destBlob); | ||||||
| RunTask(taskGenerator); | ||||||
| } | ||||||
|
|
||||||
| private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, BlobBaseClient destBlob) | ||||||
| private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, IStorageBlobManagement sourceChannel, BlobBaseClient destBlob) | ||||||
| { | ||||||
| bool destExist = true; | ||||||
| Track2Models.BlobType? srcBlobType = Util.GetBlobType(new BlobBaseClient(srcUri, ClientOptions), true).Value; | ||||||
| Track2Models.BlobType? destBlobType = Util.GetBlobType(new BlobBaseClient(srcUri, ClientOptions), true).Value; | ||||||
| BlobBaseClient srcBlobClient; | ||||||
| if (sourceChannel.StorageContext != null && sourceChannel.StorageContext.Track2OauthToken != null) | ||||||
| { | ||||||
| srcBlobClient = new BlobBaseClient(srcUri, sourceChannel.StorageContext.Track2OauthToken, ClientOptions); | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| srcBlobClient = new BlobBaseClient(srcUri, ClientOptions); | ||||||
| } | ||||||
| Track2Models.BlobType? srcBlobType = Util.GetBlobType(srcBlobClient, true).Value; | ||||||
| Track2Models.BlobType? destBlobType = srcBlobType; | ||||||
| Track2Models.BlobProperties properties = null; | ||||||
|
|
||||||
| try | ||||||
|
|
@@ -398,8 +409,6 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel, | |||||
|
|
||||||
| if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString())) | ||||||
| { | ||||||
|
|
||||||
| BlobBaseClient srcBlobClient= new BlobBaseClient(srcUri, ClientOptions); | ||||||
| Track2Models.BlobProperties srcProperties = srcBlobClient.GetProperties(cancellationToken: this.CmdletCancellationToken).Value; | ||||||
|
|
||||||
| Track2Models.BlobHttpHeaders httpHeaders = new Track2Models.BlobHttpHeaders | ||||||
|
|
@@ -453,6 +462,12 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel, | |||||
| destPageBlob.Create(srcProperties.ContentLength, pageBlobCreateOptions, this.CmdletCancellationToken); | ||||||
|
|
||||||
| Track2Models.PageBlobUploadPagesFromUriOptions pageBlobUploadPagesFromUriOptions = new Track2Models.PageBlobUploadPagesFromUriOptions(); | ||||||
| if (sourceChannel.StorageContext != null && sourceChannel.StorageContext.Track2OauthToken != null) | ||||||
| { | ||||||
| string oauthToken = sourceChannel.StorageContext.Track2OauthToken.GetToken(null, this.CmdletCancellationToken).TokenValue; | ||||||
| pageBlobUploadPagesFromUriOptions.SourceAuthentication = new HttpAuthorization("Bearer", oauthToken); | ||||||
| } | ||||||
|
|
||||||
| long pageCopyOffset = 0; | ||||||
| progressHandler.Report(pageCopyOffset); | ||||||
| long contentLenLeft = srcProperties.ContentLength; | ||||||
|
|
@@ -488,6 +503,12 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel, | |||||
| SourceRange = new global::Azure.HttpRange(appendCopyOffset, appendContentSize) | ||||||
| }; | ||||||
|
|
||||||
| if (sourceChannel.StorageContext != null && sourceChannel.StorageContext.Track2OauthToken != null) | ||||||
| { | ||||||
| string oauthToken = sourceChannel.StorageContext.Track2OauthToken.GetToken(null, this.CmdletCancellationToken).TokenValue; | ||||||
| appendBlobAppendBlockFromUriOptions.SourceAuthentication = new HttpAuthorization("Bearer", oauthToken); | ||||||
| } | ||||||
|
|
||||||
| destAppendBlob.AppendBlockFromUri(srcUri, appendBlobAppendBlockFromUriOptions, this.CmdletCancellationToken); | ||||||
| appendCopyOffset += appendContentSize; | ||||||
| progressHandler.Report(appendContentSize); | ||||||
|
|
@@ -513,6 +534,12 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel, | |||||
| options.Metadata = srcProperties.Metadata; | ||||||
| options.Tags = blobTags ?? null; | ||||||
|
|
||||||
| if (sourceChannel.StorageContext != null && sourceChannel.StorageContext.Track2OauthToken != null) | ||||||
| { | ||||||
| string oauthToken = sourceChannel.StorageContext.Track2OauthToken.GetToken(new TokenRequestContext(), this.CmdletCancellationToken).Token; | ||||||
|
||||||
| string oauthToken = sourceChannel.StorageContext.Track2OauthToken.GetToken(new TokenRequestContext(), this.CmdletCancellationToken).Token; | |
| string oauthToken = sourceChannel.StorageContext.Track2OauthToken.GetToken(null, this.CmdletCancellationToken).TokenValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The constructor chaining is incorrect. The original constructor accepts
DefaultContextandlogWriterparameters but passesnull, nullinstead ofDefaultContext, logWriterto the new constructor. This should be:this(account, accountName, false, DefaultContext, logWriter)to properly pass through these parameters.