diff --git a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.net6.0.cs b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.net6.0.cs index 3a0dae703547e..4a664e98f0cac 100644 --- a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.net6.0.cs +++ b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.net6.0.cs @@ -161,7 +161,9 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCr public virtual System.Uri Uri { get { throw null; } } public virtual Azure.Response CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] protected static Azure.Storage.Blobs.BlobServiceClient CreateClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy authentication, Azure.Core.Pipeline.HttpPipeline pipeline) { throw null; } + protected static Azure.Storage.Blobs.BlobServiceClient CreateClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy authentication, Azure.Core.Pipeline.HttpPipeline pipeline, Azure.Storage.StorageSharedKeyCredential sharedKeyCredential, Azure.AzureSasCredential sasCredential, Azure.Core.TokenCredential tokenCredential) { throw null; } public virtual Azure.Response DeleteBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Pageable FindBlobsByTags(string tagFilterSqlExpression, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs index 3a0dae703547e..4a664e98f0cac 100644 --- a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs @@ -161,7 +161,9 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCr public virtual System.Uri Uri { get { throw null; } } public virtual Azure.Response CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] protected static Azure.Storage.Blobs.BlobServiceClient CreateClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy authentication, Azure.Core.Pipeline.HttpPipeline pipeline) { throw null; } + protected static Azure.Storage.Blobs.BlobServiceClient CreateClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy authentication, Azure.Core.Pipeline.HttpPipeline pipeline, Azure.Storage.StorageSharedKeyCredential sharedKeyCredential, Azure.AzureSasCredential sasCredential, Azure.Core.TokenCredential tokenCredential) { throw null; } public virtual Azure.Response DeleteBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Pageable FindBlobsByTags(string tagFilterSqlExpression, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.1.cs b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.1.cs index 3a0dae703547e..4a664e98f0cac 100644 --- a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.1.cs +++ b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.1.cs @@ -161,7 +161,9 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCr public virtual System.Uri Uri { get { throw null; } } public virtual Azure.Response CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] protected static Azure.Storage.Blobs.BlobServiceClient CreateClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy authentication, Azure.Core.Pipeline.HttpPipeline pipeline) { throw null; } + protected static Azure.Storage.Blobs.BlobServiceClient CreateClient(System.Uri serviceUri, Azure.Storage.Blobs.BlobClientOptions options, Azure.Core.Pipeline.HttpPipelinePolicy authentication, Azure.Core.Pipeline.HttpPipeline pipeline, Azure.Storage.StorageSharedKeyCredential sharedKeyCredential, Azure.AzureSasCredential sasCredential, Azure.Core.TokenCredential tokenCredential) { throw null; } public virtual Azure.Response DeleteBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Pageable FindBlobsByTags(string tagFilterSqlExpression, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs index 94e5239b29ed4..049374af768fb 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs @@ -238,7 +238,13 @@ public BlobBaseClient(string connectionString, string blobContainerName, string /// every request. /// public BlobBaseClient(Uri blobUri, BlobClientOptions options = default) - : this(blobUri, (HttpPipelinePolicy)null, options, storageSharedKeyCredential: null) + : this( + blobUri, + (HttpPipelinePolicy)null, + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -261,7 +267,13 @@ public BlobBaseClient(Uri blobUri, BlobClientOptions options = default) /// every request. /// public BlobBaseClient(Uri blobUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) - : this(blobUri, credential.AsPolicy(), options, storageSharedKeyCredential: credential) + : this( + blobUri, + credential.AsPolicy(), + options, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -288,7 +300,13 @@ public BlobBaseClient(Uri blobUri, StorageSharedKeyCredential credential, BlobCl /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public BlobBaseClient(Uri blobUri, AzureSasCredential credential, BlobClientOptions options = default) - : this(blobUri, credential.AsPolicy(blobUri), options, storageSharedKeyCredential: null) + : this( + blobUri, + credential.AsPolicy(blobUri), + options, + storageSharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -311,7 +329,13 @@ public BlobBaseClient(Uri blobUri, AzureSasCredential credential, BlobClientOpti /// every request. /// public BlobBaseClient(Uri blobUri, TokenCredential credential, BlobClientOptions options = default) - : this(blobUri, credential.AsPolicy(options), options, credential) + : this( + blobUri, + credential.AsPolicy(options), + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(blobUri); } @@ -334,6 +358,12 @@ public BlobBaseClient(Uri blobUri, TokenCredential credential, BlobClientOptions /// policies for authentication, retries, etc., that are applied to /// every request. /// + /// + /// The shared key credential used to sign requests. + /// + /// + /// The SAS credential used to sign requests. + /// /// /// The token credential used to sign requests. /// @@ -341,6 +371,8 @@ internal BlobBaseClient( Uri blobUri, HttpPipelinePolicy authentication, BlobClientOptions options, + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, TokenCredential tokenCredential) { Argument.AssertNotNull(blobUri, nameof(blobUri)); @@ -359,69 +391,11 @@ internal BlobBaseClient( } } - _clientConfiguration = new BlobClientConfiguration( - pipeline: options.Build(authentication), - tokenCredential: tokenCredential, - clientDiagnostics: new ClientDiagnostics(options), - version: options.Version, - customerProvidedKey: options.CustomerProvidedKey, - transferValidation: options.TransferValidation, - encryptionScope: options.EncryptionScope, - trimBlobNameSlashes: options.TrimBlobNameSlashes); - - _clientSideEncryption = options._clientSideEncryptionOptions?.Clone(); - _blobRestClient = BuildBlobRestClient(blobUri); - - BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); - BlobErrors.VerifyCpkAndEncryptionScopeNotBothSet(_clientConfiguration.CustomerProvidedKey, _clientConfiguration.EncryptionScope); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the blob that includes the - /// name of the account, the name of the container, and the name of - /// the blob. - /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}". - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - /// - /// The shared key credential used to sign requests. - /// - internal BlobBaseClient( - Uri blobUri, - HttpPipelinePolicy authentication, - BlobClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(blobUri, nameof(blobUri)); - options ??= new BlobClientOptions(); - _uri = blobUri; - if (!string.IsNullOrEmpty(blobUri.Query)) - { - UriQueryParamsCollection queryParamsCollection = new UriQueryParamsCollection(blobUri.Query); - if (queryParamsCollection.ContainsKey(Constants.SnapshotParameterName)) - { - _snapshot = System.Web.HttpUtility.ParseQueryString(blobUri.Query).Get(Constants.SnapshotParameterName); - } - if (queryParamsCollection.ContainsKey(Constants.VersionIdParameterName)) - { - _blobVersionId = System.Web.HttpUtility.ParseQueryString(blobUri.Query).Get(Constants.VersionIdParameterName); - } - } - _clientConfiguration = new BlobClientConfiguration( pipeline: options.Build(authentication), sharedKeyCredential: storageSharedKeyCredential, + sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), version: options.Version, customerProvidedKey: options.CustomerProvidedKey, @@ -651,9 +625,9 @@ protected static async Task GetCopyAuthorizationHeaderAsync( BlobBaseClient client, CancellationToken cancellationToken = default) { - if (client.ClientConfiguration.OAuthTokenCredential != default) + if (client.ClientConfiguration.TokenCredential != default) { - return await client.ClientConfiguration.OAuthTokenCredential.GetCopyAuthorizationHeaderAsync(cancellationToken).ConfigureAwait(false); + return await client.ClientConfiguration.TokenCredential.GetCopyAuthorizationHeaderAsync(cancellationToken).ConfigureAwait(false); } return default; } diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs index 4e38669a05cd5..f28a92e42523e 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs @@ -6,6 +6,7 @@ using System.ComponentModel; using System.IO; using System.Linq; +using System.Net; using System.Threading; using System.Threading.Tasks; using Azure.Core; @@ -226,8 +227,29 @@ public BlobContainerClient(string connectionString, string blobContainerName, Bl /// every request. /// public BlobContainerClient(Uri blobContainerUri, BlobClientOptions options = default) - : this(blobContainerUri, (HttpPipelinePolicy)null, options) { + Argument.AssertNotNull(blobContainerUri, nameof(blobContainerUri)); + _uri = blobContainerUri; + _authenticationPolicy = null; + options ??= new BlobClientOptions(); + + _clientConfiguration = new BlobClientConfiguration( + pipeline: options.Build(null), + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: null, + clientDiagnostics: new ClientDiagnostics(options), + version: options.Version, + customerProvidedKey: options.CustomerProvidedKey, + transferValidation: options.TransferValidation, + encryptionScope: options.EncryptionScope, + trimBlobNameSlashes: options.TrimBlobNameSlashes); + + _clientSideEncryption = options._clientSideEncryptionOptions?.Clone(); + _containerRestClient = BuildContainerRestClient(blobContainerUri); + + BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); + BlobErrors.VerifyCpkAndEncryptionScopeNotBothSet(_clientConfiguration.CustomerProvidedKey, _clientConfiguration.EncryptionScope); } /// @@ -294,38 +316,15 @@ public BlobContainerClient(Uri blobContainerUri, StorageSharedKeyCredential cred /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public BlobContainerClient(Uri blobContainerUri, AzureSasCredential credential, BlobClientOptions options = default) - : this(blobContainerUri, credential.AsPolicy(blobContainerUri), options) { - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the blob container that includes the - /// name of the account and the name of the container. - /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}". - /// - /// - /// The token credential used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - public BlobContainerClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) - { - Errors.VerifyHttpsTokenAuth(blobContainerUri); Argument.AssertNotNull(blobContainerUri, nameof(blobContainerUri)); _uri = blobContainerUri; - _authenticationPolicy = credential.AsPolicy(options); + _authenticationPolicy = credential.AsPolicy(blobContainerUri); options ??= new BlobClientOptions(); _clientConfiguration = new BlobClientConfiguration( pipeline: options.Build(_authenticationPolicy), - tokenCredential: credential, + sasCredential: credential, clientDiagnostics: new ClientDiagnostics(options), version: options.Version, customerProvidedKey: options.CustomerProvidedKey, @@ -349,27 +348,25 @@ public BlobContainerClient(Uri blobContainerUri, TokenCredential credential, Blo /// name of the account and the name of the container. /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}". /// - /// - /// An optional authentication policy used to sign requests. + /// + /// The token credential used to sign requests. /// /// /// Optional client options that define the transport pipeline /// policies for authentication, retries, etc., that are applied to /// every request. /// - internal BlobContainerClient( - Uri blobContainerUri, - HttpPipelinePolicy authentication, - BlobClientOptions options) + public BlobContainerClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) { + Errors.VerifyHttpsTokenAuth(blobContainerUri); Argument.AssertNotNull(blobContainerUri, nameof(blobContainerUri)); _uri = blobContainerUri; - _authenticationPolicy = authentication; + _authenticationPolicy = credential.AsPolicy(options); options ??= new BlobClientOptions(); _clientConfiguration = new BlobClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: null, + pipeline: options.Build(_authenticationPolicy), + tokenCredential: credential, clientDiagnostics: new ClientDiagnostics(options), version: options.Version, customerProvidedKey: options.CustomerProvidedKey, diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs index d4ca2ad868241..08af5e3580d60 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs @@ -225,7 +225,7 @@ public BlobServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public BlobServiceClient(Uri serviceUri, AzureSasCredential credential, BlobClientOptions options = default) - : this(serviceUri, credential.AsPolicy(serviceUri), options ?? new BlobClientOptions()) + : this(serviceUri, credential.AsPolicy(serviceUri), credential, options ?? new BlobClientOptions()) { } @@ -364,6 +364,45 @@ internal BlobServiceClient( { } + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// A referencing the blob service. + /// This is likely to be similar to "https://{account_name}.blob.core.windows.net". + /// + /// + /// An optional authentication policy used to sign requests. + /// + /// + /// Optional SAS credential used to sign requests and generate sas. + /// + /// + /// Optional client options that define the transport pipeline + /// policies for authentication, retries, etc., that are applied to + /// every request. + /// + internal BlobServiceClient( + Uri serviceUri, + HttpPipelinePolicy authentication, + AzureSasCredential sasCredential, + BlobClientOptions options) + : this(serviceUri, + new BlobClientConfiguration( + pipeline: options.Build(authentication), + sasCredential: sasCredential, + clientDiagnostics: new ClientDiagnostics(options), + version: options?.Version ?? BlobClientOptions.LatestVersion, + customerProvidedKey: options?.CustomerProvidedKey, + transferValidation: options.TransferValidation, + encryptionScope: options?.EncryptionScope, + trimBlobNameSlashes: options?.TrimBlobNameSlashes ?? false), + authentication, + options?._clientSideEncryptionOptions?.Clone()) + { + } + /// /// Initializes a new instance of the /// class. @@ -397,6 +436,66 @@ internal BlobServiceClient( BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); } + /// + /// Intended for DataLake to create a backing blob client. + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// A referencing the block blob that includes the + /// name of the account, the name of the container, and the name of + /// the blob. + /// + /// + /// Optional client options that define the transport pipeline + /// policies for authentication, retries, etc., that are applied to + /// every request. + /// + /// + /// An optional authentication policy used to sign requests. + /// + /// + /// The transport pipeline used to send every request. + /// + /// + /// The shared key credential used to sign requests. + /// + /// + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. + /// + /// + /// New instanc of the class. + /// + protected static BlobServiceClient CreateClient( + Uri serviceUri, + BlobClientOptions options, + HttpPipelinePolicy authentication, + HttpPipeline pipeline, + StorageSharedKeyCredential sharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) + { + return new BlobServiceClient( + serviceUri, + new BlobClientConfiguration( + pipeline: pipeline, + sharedKeyCredential: sharedKeyCredential, + sasCredential: sasCredential, + tokenCredential: tokenCredential, + clientDiagnostics: new ClientDiagnostics(options), + version: options.Version, + customerProvidedKey: null, + transferValidation: options.TransferValidation, + encryptionScope: null, + trimBlobNameSlashes: options.TrimBlobNameSlashes), + authentication, + clientSideEncryption: null); + } + /// /// Intended for DataLake to create a backing blob client. /// @@ -422,6 +521,7 @@ internal BlobServiceClient( /// /// New instanc of the class. /// + [EditorBrowsable(EditorBrowsableState.Never)] protected static BlobServiceClient CreateClient( Uri serviceUri, BlobClientOptions options, diff --git a/sdk/storage/Azure.Storage.Blobs/src/Shared/BlobClientConfiguration.cs b/sdk/storage/Azure.Storage.Blobs/src/Shared/BlobClientConfiguration.cs index a145b396d7c8d..26b6627453269 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Shared/BlobClientConfiguration.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Shared/BlobClientConfiguration.cs @@ -35,6 +35,10 @@ internal class BlobClientConfiguration : StorageClientConfiguration public bool TrimBlobNameSlashes { get; internal set; } + /// + /// Create a with token authentication. + /// + public BlobClientConfiguration( HttpPipeline pipeline, TokenCredential tokenCredential, @@ -53,6 +57,9 @@ public BlobClientConfiguration( TrimBlobNameSlashes = trimBlobNameSlashes; } + /// + /// Create a with shared key authentication. + /// public BlobClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, @@ -71,10 +78,78 @@ public BlobClientConfiguration( TrimBlobNameSlashes = trimBlobNameSlashes; } + /// + /// Create a with SAS authentication. + /// + public BlobClientConfiguration( + HttpPipeline pipeline, + AzureSasCredential sasCredential, + ClientDiagnostics clientDiagnostics, + BlobClientOptions.ServiceVersion version, + CustomerProvidedKey? customerProvidedKey, + TransferValidationOptions transferValidation, + string encryptionScope, + bool trimBlobNameSlashes) + : base(pipeline, sasCredential, clientDiagnostics) + { + Version = version; + CustomerProvidedKey = customerProvidedKey; + TransferValidation = transferValidation; + EncryptionScope = encryptionScope; + TrimBlobNameSlashes = trimBlobNameSlashes; + } + + /// + /// Create a without authentication, + /// or with SAS that was provided as part of the URL. + /// + + public BlobClientConfiguration( + HttpPipeline pipeline, + ClientDiagnostics clientDiagnostics, + BlobClientOptions.ServiceVersion version, + CustomerProvidedKey? customerProvidedKey, + TransferValidationOptions transferValidation, + string encryptionScope, + bool trimBlobNameSlashes) + : base(pipeline, clientDiagnostics) + { + Version = version; + CustomerProvidedKey = customerProvidedKey; + TransferValidation = transferValidation; + EncryptionScope = encryptionScope; + TrimBlobNameSlashes = trimBlobNameSlashes; + } + + /// + /// Used for internal Client Constructors that accept multiple types of authentication. + /// + internal BlobClientConfiguration( + HttpPipeline pipeline, + StorageSharedKeyCredential sharedKeyCredential, + TokenCredential tokenCredential, + AzureSasCredential sasCredential, + ClientDiagnostics clientDiagnostics, + BlobClientOptions.ServiceVersion version, + CustomerProvidedKey? customerProvidedKey, + TransferValidationOptions transferValidation, + string encryptionScope, + bool trimBlobNameSlashes) + : base(pipeline, sharedKeyCredential, sasCredential, tokenCredential, clientDiagnostics) + { + Version = version; + CustomerProvidedKey = customerProvidedKey; + TransferValidation = transferValidation; + EncryptionScope = encryptionScope; + TrimBlobNameSlashes = trimBlobNameSlashes; + } + internal static BlobClientConfiguration DeepCopy(BlobClientConfiguration originalClientConfiguration) => new BlobClientConfiguration( pipeline: originalClientConfiguration.Pipeline, sharedKeyCredential: originalClientConfiguration.SharedKeyCredential, + tokenCredential: originalClientConfiguration.TokenCredential, + sasCredential: originalClientConfiguration.SasCredential, clientDiagnostics: originalClientConfiguration.ClientDiagnostics, version: originalClientConfiguration.Version, customerProvidedKey: originalClientConfiguration.CustomerProvidedKey, diff --git a/sdk/storage/Azure.Storage.Common/src/Shared/StorageClientConfiguration.cs b/sdk/storage/Azure.Storage.Common/src/Shared/StorageClientConfiguration.cs index 9c1e21109dc72..4274111c7fd33 100644 --- a/sdk/storage/Azure.Storage.Common/src/Shared/StorageClientConfiguration.cs +++ b/sdk/storage/Azure.Storage.Common/src/Shared/StorageClientConfiguration.cs @@ -16,12 +16,15 @@ internal class StorageClientConfiguration public virtual StorageSharedKeyCredential SharedKeyCredential { get; private set; } - public virtual TokenCredential OAuthTokenCredential { get; private set; } + public virtual TokenCredential TokenCredential { get; private set; } public virtual AzureSasCredential SasCredential { get; private set; } public virtual ClientDiagnostics ClientDiagnostics { get; private set; } + /// + /// Create a with shared key authentication. + /// public StorageClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, @@ -31,6 +34,9 @@ public StorageClientConfiguration( SharedKeyCredential = sharedKeyCredential; } + /// + /// Create a with SAS authentication. + /// public StorageClientConfiguration( HttpPipeline pipeline, AzureSasCredential sasCredential, @@ -40,15 +46,21 @@ public StorageClientConfiguration( SasCredential = sasCredential; } + /// + /// Create a with token authentication. + /// public StorageClientConfiguration( HttpPipeline pipeline, TokenCredential tokenCredential, ClientDiagnostics clientDiagnostics) : this(pipeline, clientDiagnostics) { - OAuthTokenCredential = tokenCredential; + TokenCredential = tokenCredential; } + /// + /// Only use for creating a deep copy of a . + /// internal StorageClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, @@ -59,10 +71,14 @@ internal StorageClientConfiguration( Pipeline = pipeline; SharedKeyCredential = sharedKeyCredential; SasCredential = sasCredential; - OAuthTokenCredential = tokenCredential; + TokenCredential = tokenCredential; ClientDiagnostics = clientDiagnostics; } + /// + /// Create a without authentication, + /// or with SAS that was provided as part of the URL. + /// internal StorageClientConfiguration( HttpPipeline pipeline, ClientDiagnostics clientDiagnostics) diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeClientConfiguration.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeClientConfiguration.cs index 7dddb730bc205..d0e3d2e9032a5 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeClientConfiguration.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeClientConfiguration.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.Core; using Azure.Core.Pipeline; using Azure.Storage.Files.DataLake.Models; using Azure.Storage.Shared; @@ -15,6 +16,25 @@ internal class DataLakeClientConfiguration : StorageClientConfiguration public virtual TransferValidationOptions TransferValidation { get; } = new(); + /// + /// Create a without authentication, + /// or with SAS that was provided as part of the URL. + /// + public DataLakeClientConfiguration( + HttpPipeline pipeline, + ClientDiagnostics clientDiagnostics, + DataLakeClientOptions clientOptions, + DataLakeCustomerProvidedKey? customerProvidedKey) + : base(pipeline, clientDiagnostics) + { + ClientOptions = clientOptions; + CustomerProvidedKey = customerProvidedKey; + TransferValidation = clientOptions.TransferValidation; + } + + /// + /// Create a with shared key authentication. + /// public DataLakeClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, @@ -28,6 +48,9 @@ public DataLakeClientConfiguration( TransferValidation = clientOptions.TransferValidation; } + /// + /// Create a with SAS authentication. + /// public DataLakeClientConfiguration( HttpPipeline pipeline, AzureSasCredential sasCredential, @@ -41,14 +64,34 @@ public DataLakeClientConfiguration( TransferValidation = clientOptions.TransferValidation; } + /// + /// Create a with token authentication. + /// + public DataLakeClientConfiguration( + HttpPipeline pipeline, + TokenCredential tokenCredential, + ClientDiagnostics clientDiagnostics, + DataLakeClientOptions clientOptions, + DataLakeCustomerProvidedKey? customerProvidedKey) + : base(pipeline, tokenCredential, clientDiagnostics) + { + ClientOptions = clientOptions; + CustomerProvidedKey = customerProvidedKey; + TransferValidation = clientOptions.TransferValidation; + } + + /// + /// For internal Client Constructors that accept multiple types of authentication. + /// internal DataLakeClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, AzureSasCredential sasCredential, + TokenCredential tokenCredential, ClientDiagnostics clientDiagnostics, DataLakeClientOptions clientOptions, DataLakeCustomerProvidedKey? customerProvidedKey) - : base(pipeline, sharedKeyCredential, sasCredential, default, clientDiagnostics) + : base(pipeline, sharedKeyCredential, sasCredential, tokenCredential, clientDiagnostics) { ClientOptions = clientOptions; CustomerProvidedKey = customerProvidedKey; @@ -60,6 +103,7 @@ internal static DataLakeClientConfiguration DeepCopy(DataLakeClientConfiguration pipeline: originalClientConfiguration.Pipeline, sharedKeyCredential: originalClientConfiguration.SharedKeyCredential, sasCredential: originalClientConfiguration.SasCredential, + tokenCredential: originalClientConfiguration.TokenCredential, clientDiagnostics: originalClientConfiguration.ClientDiagnostics, clientOptions: originalClientConfiguration.ClientOptions, customerProvidedKey: originalClientConfiguration.CustomerProvidedKey); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs index 48b7dd6e22bc1..eefd6242a39c0 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs @@ -272,7 +272,13 @@ internal DataLakeDirectoryClient HttpPipelinePolicy authentication, DataLakeClientOptions options, StorageSharedKeyCredential storageSharedKeyCredential) - : base(directoryUri, authentication, options, storageSharedKeyCredential) + : base( + directoryUri, + authentication, + options, + storageSharedKeyCredential: storageSharedKeyCredential, + sasCredential: null, + tokenCredential: null) { } @@ -301,7 +307,13 @@ internal DataLakeDirectoryClient HttpPipelinePolicy authentication, DataLakeClientOptions options, AzureSasCredential sasCredential) - : base(directoryUri, authentication, options, sasCredential) + : base( + directoryUri, + authentication, + options, + storageSharedKeyCredential: null, + sasCredential: sasCredential, + tokenCredential: null) { } diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs index 0d4ff604d7cae..55a00856b1bbb 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs @@ -288,7 +288,13 @@ internal DataLakeFileClient( HttpPipelinePolicy authentication, DataLakeClientOptions options, StorageSharedKeyCredential storageSharedKeyCredential) - : base(fileUri, authentication, options, storageSharedKeyCredential) + : base( + fileUri, + authentication, + options, + storageSharedKeyCredential: storageSharedKeyCredential, + sasCredential: null, + tokenCredential: null) { } @@ -317,7 +323,12 @@ internal DataLakeFileClient( HttpPipelinePolicy authentication, DataLakeClientOptions options, AzureSasCredential sasCredential) - : base(fileUri, authentication, options, sasCredential) + : base(fileUri, + authentication, + options, + storageSharedKeyCredential: null, + sasCredential: sasCredential, + tokenCredential: null) { } diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs index 3938994706ca5..77abac7108f1c 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs @@ -146,7 +146,13 @@ protected DataLakeFileSystemClient() /// name of the account and the name of the file system. /// public DataLakeFileSystemClient(Uri fileSystemUri) - : this(fileSystemUri, (HttpPipelinePolicy)null, null, storageSharedKeyCredential: null) + : this( + fileSystemUri, + (HttpPipelinePolicy)null, + options: null, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -164,7 +170,13 @@ public DataLakeFileSystemClient(Uri fileSystemUri) /// every request. /// public DataLakeFileSystemClient(Uri fileSystemUri, DataLakeClientOptions options) - : this(fileSystemUri, (HttpPipelinePolicy)null, options, storageSharedKeyCredential: null) + : this( + fileSystemUri, + (HttpPipelinePolicy)null, + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -254,7 +266,13 @@ public DataLakeFileSystemClient(string connectionString, string fileSystemName, /// The shared key credential used to sign requests. /// public DataLakeFileSystemClient(Uri fileSystemUri, StorageSharedKeyCredential credential) - : this(fileSystemUri, credential.AsPolicy(), null, credential) + : this( + fileSystemUri, + credential.AsPolicy(), + options: null, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -275,7 +293,13 @@ public DataLakeFileSystemClient(Uri fileSystemUri, StorageSharedKeyCredential cr /// every request. /// public DataLakeFileSystemClient(Uri fileSystemUri, StorageSharedKeyCredential credential, DataLakeClientOptions options) - : this(fileSystemUri, credential.AsPolicy(), options, credential) + : this( + fileSystemUri, + credential.AsPolicy(), + options, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -320,7 +344,13 @@ public DataLakeFileSystemClient(Uri fileSystemUri, AzureSasCredential credential /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public DataLakeFileSystemClient(Uri fileSystemUri, AzureSasCredential credential, DataLakeClientOptions options) - : this(fileSystemUri, credential.AsPolicy(fileSystemUri), options, credential) + : this( + fileSystemUri, + credential.AsPolicy(fileSystemUri), + options, + storageSharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -336,7 +366,13 @@ public DataLakeFileSystemClient(Uri fileSystemUri, AzureSasCredential credential /// The token credential used to sign requests. /// public DataLakeFileSystemClient(Uri fileSystemUri, TokenCredential credential) - : this(fileSystemUri, credential.AsPolicy(new DataLakeClientOptions()), null, storageSharedKeyCredential:null) + : this( + fileSystemUri, + credential.AsPolicy(new DataLakeClientOptions()), + options: null, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(fileSystemUri); } @@ -358,7 +394,13 @@ public DataLakeFileSystemClient(Uri fileSystemUri, TokenCredential credential) /// every request. /// public DataLakeFileSystemClient(Uri fileSystemUri, TokenCredential credential, DataLakeClientOptions options) - : this(fileSystemUri, credential.AsPolicy(options), options, storageSharedKeyCredential:null) + : this( + fileSystemUri, + credential.AsPolicy(options), + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(fileSystemUri); } @@ -382,61 +424,19 @@ public DataLakeFileSystemClient(Uri fileSystemUri, TokenCredential credential, D /// /// The shared key credential used to sign requests. /// - internal DataLakeFileSystemClient( - Uri fileSystemUri, - HttpPipelinePolicy authentication, - DataLakeClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(fileSystemUri, nameof(fileSystemUri)); - DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(fileSystemUri); - options ??= new DataLakeClientOptions(); - _uri = fileSystemUri; - _blobUri = uriBuilder.ToBlobUri(); - _dfsUri = uriBuilder.ToDfsUri(); - - _clientConfiguration = new DataLakeClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - clientDiagnostics: new ClientDiagnostics(options), - clientOptions: options, - customerProvidedKey: options.CustomerProvidedKey); - - _containerClient = BlobContainerClientInternals.Create( - _blobUri, - _clientConfiguration); - - (FileSystemRestClient dfsFileSystemRestClient, FileSystemRestClient blobFileSystemRestClient) = BuildFileSystemRestClients(_dfsUri, _blobUri); - _fileSystemRestClient = dfsFileSystemRestClient; - _blobFileSystemRestClient = blobFileSystemRestClient; - - DataLakeErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the file system that includes the - /// name of the account and the name of the file system. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// /// - /// The shared key credential used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal DataLakeFileSystemClient( Uri fileSystemUri, HttpPipelinePolicy authentication, DataLakeClientOptions options, - AzureSasCredential sasCredential) + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(fileSystemUri, nameof(fileSystemUri)); DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(fileSystemUri); @@ -447,7 +447,9 @@ internal DataLakeFileSystemClient( _clientConfiguration = new DataLakeClientConfiguration( pipeline: options.Build(authentication), + sharedKeyCredential: storageSharedKeyCredential, sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), clientOptions: options, customerProvidedKey: options.CustomerProvidedKey); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs index 62025096c62a0..eebfb201803fa 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs @@ -220,7 +220,13 @@ public DataLakePathClient(Uri pathUri) /// applied to every request. /// public DataLakePathClient(Uri pathUri, DataLakeClientOptions options) - : this(pathUri, (HttpPipelinePolicy)null, options, storageSharedKeyCredential: null) + : this( + pathUri, + (HttpPipelinePolicy)null, + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -320,7 +326,13 @@ public DataLakePathClient( /// The shared key credential used to sign requests. /// public DataLakePathClient(Uri pathUri, StorageSharedKeyCredential credential) - : this(pathUri, credential.AsPolicy(), null, credential) + : this( + pathUri, + credential.AsPolicy(), + options: null, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -342,7 +354,13 @@ public DataLakePathClient(Uri pathUri, StorageSharedKeyCredential credential) /// every request. /// public DataLakePathClient(Uri pathUri, StorageSharedKeyCredential credential, DataLakeClientOptions options) - : this(pathUri, credential.AsPolicy(), options, credential) + : this( + pathUri, + credential.AsPolicy(), + options, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -389,7 +407,13 @@ public DataLakePathClient(Uri pathUri, AzureSasCredential credential) /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public DataLakePathClient(Uri pathUri, AzureSasCredential credential, DataLakeClientOptions options) - : this(pathUri, credential.AsPolicy(pathUri), options, credential) + : this( + pathUri, + credential.AsPolicy(pathUri), + options, + storageSharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -429,7 +453,13 @@ public DataLakePathClient(Uri pathUri, TokenCredential credential) /// every request. /// public DataLakePathClient(Uri pathUri, TokenCredential credential, DataLakeClientOptions options) - : this(pathUri, credential.AsPolicy(options), options, storageSharedKeyCredential: null) + : this( + pathUri, + credential.AsPolicy(options), + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(pathUri); } @@ -521,66 +551,19 @@ internal DataLakePathClient( /// /// The shared key credential used to sign requests. /// - internal DataLakePathClient( - Uri pathUri, - HttpPipelinePolicy authentication, - DataLakeClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(pathUri, nameof(pathUri)); - DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(pathUri); - options ??= new DataLakeClientOptions(); - _uri = pathUri; - _blobUri = uriBuilder.ToBlobUri(); - _dfsUri = uriBuilder.ToDfsUri(); - - _clientConfiguration = new DataLakeClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - clientDiagnostics: new ClientDiagnostics(options), - clientOptions: options, - customerProvidedKey: options.CustomerProvidedKey); - - _blockBlobClient = BlockBlobClientInternals.Create(_blobUri, _clientConfiguration); - - uriBuilder.DirectoryOrFilePath = null; - - _fileSystemClient = new DataLakeFileSystemClient( - uriBuilder.ToDfsUri(), - _clientConfiguration); - - (PathRestClient dfsPathRestClient, PathRestClient blobPathRestClient) = BuildPathRestClients(_dfsUri, _blobUri); - _pathRestClient = dfsPathRestClient; - _blobPathRestClient = blobPathRestClient; - - DataLakeErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the path that includes the - /// name of the account, the name of the file system, and the path to - /// the resource. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// /// - /// The shared key credential used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal DataLakePathClient( Uri pathUri, HttpPipelinePolicy authentication, DataLakeClientOptions options, - AzureSasCredential sasCredential) + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(pathUri, nameof(pathUri)); DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(pathUri); @@ -591,7 +574,9 @@ internal DataLakePathClient( _clientConfiguration = new DataLakeClientConfiguration( pipeline: options.Build(authentication), + sharedKeyCredential: storageSharedKeyCredential, sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), clientOptions: options, customerProvidedKey: options.CustomerProvidedKey); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs index 9760abf9fe0a3..c6fe10255581a 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs @@ -96,7 +96,13 @@ protected DataLakeServiceClient() /// A referencing the Data Lake service. /// public DataLakeServiceClient(Uri serviceUri) - : this(serviceUri, (HttpPipelinePolicy)null, null, storageSharedKeyCredential:null) + : this( + serviceUri, + (HttpPipelinePolicy)null, + options: null, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -113,7 +119,13 @@ public DataLakeServiceClient(Uri serviceUri) /// every request. /// public DataLakeServiceClient(Uri serviceUri, DataLakeClientOptions options) - : this(serviceUri, (HttpPipelinePolicy)null, options, storageSharedKeyCredential:null) + : this( + serviceUri, + (HttpPipelinePolicy)null, + options, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -168,10 +180,8 @@ public DataLakeServiceClient(string connectionString, DataLakeClientOptions opti _blobServiceClient = BlobServiceClientInternals.Create( _blobUri, - _clientConfiguration.Pipeline, - authPolicy, - _clientConfiguration.ClientOptions.Version.AsBlobsVersion(), - _clientConfiguration.ClientDiagnostics); + _clientConfiguration, + authPolicy); DataLakeErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); } @@ -187,7 +197,13 @@ public DataLakeServiceClient(string connectionString, DataLakeClientOptions opti /// The shared key credential used to sign requests. /// public DataLakeServiceClient(Uri serviceUri, StorageSharedKeyCredential credential) - : this(serviceUri, credential.AsPolicy(), null, credential) + : this( + serviceUri, + credential.AsPolicy(), + options: null, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -207,7 +223,13 @@ public DataLakeServiceClient(Uri serviceUri, StorageSharedKeyCredential credenti /// every request. /// public DataLakeServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, DataLakeClientOptions options) - : this(serviceUri, credential.AsPolicy(), options, null, credential) + : this( + serviceUri, + credential.AsPolicy(), + options, + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -250,7 +272,13 @@ public DataLakeServiceClient(Uri serviceUri, AzureSasCredential credential) /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public DataLakeServiceClient(Uri serviceUri, AzureSasCredential credential, DataLakeClientOptions options) - : this(serviceUri, credential.AsPolicy(serviceUri), options, null, credential) + : this( + serviceUri, + credential.AsPolicy(serviceUri), + options, + storageSharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -265,7 +293,13 @@ public DataLakeServiceClient(Uri serviceUri, AzureSasCredential credential, Data /// The token credential used to sign requests. /// public DataLakeServiceClient(Uri serviceUri, TokenCredential credential) - : this(serviceUri, credential.AsPolicy(new DataLakeClientOptions()), null, storageSharedKeyCredential:null) + : this( + serviceUri, + credential.AsPolicy(new DataLakeClientOptions()), + options: null, + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(serviceUri); } @@ -286,65 +320,17 @@ public DataLakeServiceClient(Uri serviceUri, TokenCredential credential) /// every request. /// public DataLakeServiceClient(Uri serviceUri, TokenCredential credential, DataLakeClientOptions options) - : this(serviceUri, credential.AsPolicy(options), options, storageSharedKeyCredential:null) + : this( + serviceUri, + credential.AsPolicy(options), + options, + storageSharedKeyCredential:null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(serviceUri); } - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the Data Lake service - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - /// - /// The shared key credential used to sign requests. - /// - internal DataLakeServiceClient( - Uri serviceUri, - HttpPipelinePolicy authentication, - DataLakeClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - : this(serviceUri, authentication, options, null, storageSharedKeyCredential) - { - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the Data Lake service - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - /// - /// The shared key credential used to sign requests. - /// - internal DataLakeServiceClient( - Uri serviceUri, - HttpPipelinePolicy authentication, - DataLakeClientOptions options, - AzureSasCredential sasCredential) - : this(serviceUri, authentication, options, null, sasCredential) - { - } - /// /// Initializes a new instance of the /// class. @@ -368,12 +354,10 @@ internal DataLakeServiceClient( _blobServiceClient = BlobServiceClientInternals.Create( _blobUri, - _clientConfiguration.Pipeline, + _clientConfiguration, // auth is included in pipeline in client configuration. // blobs keeps it separate for niche use cases that are inaccessible from datalake clients - authentication: default, - _clientConfiguration.ClientOptions.Version.AsBlobsVersion(), - _clientConfiguration.ClientDiagnostics); + authentication: default); } /// @@ -391,65 +375,22 @@ internal DataLakeServiceClient( /// policies for authentication, retries, etc., that are applied to /// every request. /// - /// /// /// The shared key credential used to sign requests. /// - internal DataLakeServiceClient( - Uri serviceUri, - HttpPipelinePolicy authentication, - DataLakeClientOptions options, - ClientDiagnostics clientDiagnostics, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(serviceUri, nameof(serviceUri)); - options ??= new DataLakeClientOptions(); - - _uri = serviceUri; - _blobUri = new DataLakeUriBuilder(serviceUri).ToBlobUri(); - - _clientConfiguration = new DataLakeClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - clientDiagnostics: clientDiagnostics ?? new ClientDiagnostics(options), - clientOptions: options, - customerProvidedKey: options.CustomerProvidedKey); - - _blobServiceClient = BlobServiceClientInternals.Create( - _blobUri, - _clientConfiguration.Pipeline, - authentication, - _clientConfiguration.ClientOptions.Version.AsBlobsVersion(), - _clientConfiguration.ClientDiagnostics); - - DataLakeErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the Data Lake service. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - /// /// - /// The shared key credential used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal DataLakeServiceClient( Uri serviceUri, HttpPipelinePolicy authentication, DataLakeClientOptions options, - ClientDiagnostics clientDiagnostics, - AzureSasCredential sasCredential) + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(serviceUri, nameof(serviceUri)); options ??= new DataLakeClientOptions(); @@ -459,17 +400,17 @@ internal DataLakeServiceClient( _clientConfiguration = new DataLakeClientConfiguration( pipeline: options.Build(authentication), + sharedKeyCredential: storageSharedKeyCredential, sasCredential: sasCredential, - clientDiagnostics: clientDiagnostics ?? new ClientDiagnostics(options), + tokenCredential: tokenCredential, + clientDiagnostics: new ClientDiagnostics(options), clientOptions: options, customerProvidedKey: options.CustomerProvidedKey); _blobServiceClient = BlobServiceClientInternals.Create( _blobUri, - _clientConfiguration.Pipeline, - authentication, - _clientConfiguration.ClientOptions.Version.AsBlobsVersion(), - _clientConfiguration.ClientDiagnostics); + _clientConfiguration, + authentication); DataLakeErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey); } @@ -482,19 +423,20 @@ private class BlobServiceClientInternals : BlobServiceClient { public static BlobServiceClient Create( Uri uri, - HttpPipeline pipeline, - HttpPipelinePolicy authentication, - BlobClientOptions.ServiceVersion version, - ClientDiagnostics diagnostics) + DataLakeClientConfiguration clientConfiguration, + HttpPipelinePolicy authentication) { return BlobServiceClient.CreateClient( uri, - new BlobClientOptions(version) + new BlobClientOptions(clientConfiguration.ClientOptions.Version.AsBlobsVersion()) { - Diagnostics = { IsDistributedTracingEnabled = diagnostics.IsActivityEnabled } + Diagnostics = { IsDistributedTracingEnabled = clientConfiguration.ClientDiagnostics.IsActivityEnabled } }, authentication, - pipeline); + clientConfiguration.Pipeline, + clientConfiguration.SharedKeyCredential, + clientConfiguration.SasCredential, + clientConfiguration.TokenCredential); } } #endregion ctors diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs index d5341abd516c5..b9603c3758ba3 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs @@ -182,7 +182,13 @@ public ShareClient( public ShareClient( Uri shareUri, ShareClientOptions options = default) - : this(shareUri, (HttpPipelinePolicy)null, options, sasCredential: null) + : this( + shareUri, + (HttpPipelinePolicy)null, + options, + storageSharedKeyCredential: default, + sasCredential: default, + tokenCredential: default) { } @@ -206,7 +212,13 @@ public ShareClient( Uri shareUri, StorageSharedKeyCredential credential, ShareClientOptions options = default) - : this(shareUri, credential.AsPolicy(), options, credential) + : this( + shareUri, + credential.AsPolicy(), + options, + storageSharedKeyCredential: credential, + sasCredential: default, + tokenCredential: default) { } @@ -238,7 +250,13 @@ public ShareClient( Uri shareUri, AzureSasCredential credential, ShareClientOptions options = default) - : this(shareUri, credential.AsPolicy(shareUri), options, sasCredential: credential) + : this( + shareUri, + credential.AsPolicy(shareUri), + options, + storageSharedKeyCredential: default, + sasCredential: credential, + tokenCredential: default) { } @@ -277,7 +295,9 @@ public ShareClient( shareUri: shareUri, authentication: credential.AsPolicy(options), options: options ?? new ShareClientOptions(), - storageSharedKeyCredential: default) + storageSharedKeyCredential: default, + sasCredential: default, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(shareUri); } @@ -301,55 +321,28 @@ public ShareClient( /// /// The shared key credential used to sign requests. /// - internal ShareClient( - Uri shareUri, - HttpPipelinePolicy authentication, - ShareClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(shareUri, nameof(shareUri)); - options ??= new ShareClientOptions(); - _uri = shareUri; - _clientConfiguration = new ShareClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - sasCredential: default, - clientDiagnostics: new ClientDiagnostics(options), - clientOptions: options); - _shareRestClient = BuildShareRestClient(shareUri); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the share that includes the - /// name of the account and the name of the share. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// /// - /// The shared access signature used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal ShareClient( Uri shareUri, HttpPipelinePolicy authentication, ShareClientOptions options, - AzureSasCredential sasCredential) + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(shareUri, nameof(shareUri)); options ??= new ShareClientOptions(); _uri = shareUri; _clientConfiguration = new ShareClientConfiguration( pipeline: options.Build(authentication), + sharedKeyCredential: storageSharedKeyCredential, sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), clientOptions: options); _shareRestClient = BuildShareRestClient(shareUri); diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareClientConfiguration.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareClientConfiguration.cs index baadc154fc7dd..1d799e1515166 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareClientConfiguration.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareClientConfiguration.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.Core; using Azure.Core.Pipeline; using Azure.Storage.Files.Shares.Models; using Azure.Storage.Shared; @@ -13,31 +14,65 @@ internal class ShareClientConfiguration : StorageClientConfiguration public TransferValidationOptions TransferValidation { get; internal set; } + /// + /// Create a with shared key authentication. + /// public ShareClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, ClientDiagnostics clientDiagnostics, ShareClientOptions clientOptions) - : this(pipeline, sharedKeyCredential, default, clientDiagnostics, clientOptions) + : this(pipeline, sharedKeyCredential, default, default, clientDiagnostics, clientOptions) { } + /// + /// Create a with SAS authentication. + /// public ShareClientConfiguration( HttpPipeline pipeline, AzureSasCredential sasCredential, ClientDiagnostics clientDiagnostics, ShareClientOptions clientOptions) - : this(pipeline, default, sasCredential, clientDiagnostics, clientOptions) + : this(pipeline, default, sasCredential, default, clientDiagnostics, clientOptions) { } + /// + /// Create a with token authentication. + /// + public ShareClientConfiguration( + HttpPipeline pipeline, + TokenCredential tokenCredential, + ClientDiagnostics clientDiagnostics, + ShareClientOptions clientOptions) + : this(pipeline, default, default, tokenCredential, clientDiagnostics, clientOptions) + { + } + + /// + /// Create a without authentication, + /// or with SAS that was provided as part of the URL. + /// + public ShareClientConfiguration( + HttpPipeline pipeline, + ClientDiagnostics clientDiagnostics, + ShareClientOptions clientOptions) + : this(pipeline, default, default, default, clientDiagnostics, clientOptions) + { + } + + /// + /// For internal Client Constructors that accept multiple types of authentication. + /// internal ShareClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, AzureSasCredential sasCredential, + TokenCredential tokenCredential, ClientDiagnostics clientDiagnostics, ShareClientOptions clientOptions) - : base(pipeline, sharedKeyCredential, sasCredential, default, clientDiagnostics) + : base(pipeline, sharedKeyCredential, sasCredential, tokenCredential, clientDiagnostics) { ClientOptions = clientOptions; TransferValidation = clientOptions.TransferValidation; diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs index ff5f1a2be9ab6..bb7f99dc0e89f 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs @@ -228,7 +228,9 @@ public ShareDirectoryClient( directoryUri: directoryUri, authentication: (HttpPipelinePolicy)null, options: options, - storageSharedKeyCredential: null) + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -257,7 +259,9 @@ public ShareDirectoryClient( directoryUri: directoryUri, authentication: credential.AsPolicy(), options: options, - storageSharedKeyCredential: credential) + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -286,7 +290,13 @@ public ShareDirectoryClient( Uri directoryUri, AzureSasCredential credential, ShareClientOptions options = default) - : this(directoryUri, credential.AsPolicy(directoryUri), options, sasCredential:credential) + : this( + directoryUri, + credential.AsPolicy(directoryUri), + options, + storageSharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -317,7 +327,9 @@ public ShareDirectoryClient( directoryUri: directoryUri, authentication: credential.AsPolicy(options), options: options ?? new ShareClientOptions(), - storageSharedKeyCredential: null) + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(directoryUri); } @@ -342,99 +354,33 @@ public ShareDirectoryClient( /// /// The shared key credential used to sign requests. /// - internal ShareDirectoryClient( - Uri directoryUri, - HttpPipelinePolicy authentication, - ShareClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(directoryUri, nameof(directoryUri)); - options ??= new ShareClientOptions(); - _uri = directoryUri; - _clientConfiguration = new ShareClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - sasCredential: default, - clientDiagnostics: new ClientDiagnostics(options), - clientOptions: options); - _directoryRestClient = BuildDirectoryRestClient(directoryUri); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the directory that includes the - /// name of the account, the name of the share, and the path of the - /// directory. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// /// - /// The shared access signature used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal ShareDirectoryClient( Uri directoryUri, HttpPipelinePolicy authentication, ShareClientOptions options, - AzureSasCredential sasCredential) + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(directoryUri, nameof(directoryUri)); options ??= new ShareClientOptions(); _uri = directoryUri; _clientConfiguration = new ShareClientConfiguration( pipeline: options.Build(authentication), + sharedKeyCredential: storageSharedKeyCredential, sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), clientOptions: options); _directoryRestClient = BuildDirectoryRestClient(directoryUri); } - /// - /// Initializes a new instance of the - /// class. - /// - /// This will create an instance that uses the same diagnostics as another - /// client. This client will be used within another API call of the parent - /// client (namely Rename). This is in the case that the new child client - /// has different credentials than the parent client. - /// - /// - /// A referencing the directory that includes the - /// name of the account, the name of the share, and the path of the - /// directory. - /// - /// - /// The diagnostics from the parent client. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - internal ShareDirectoryClient( - Uri directoryUri, - ClientDiagnostics diagnostics, - ShareClientOptions options) - { - Argument.AssertNotNull(directoryUri, nameof(directoryUri)); - options ??= new ShareClientOptions(); - _uri = directoryUri; - _clientConfiguration = new ShareClientConfiguration( - pipeline: options.Build(), - sharedKeyCredential: default, - clientDiagnostics: diagnostics, - clientOptions: options); - _directoryRestClient = BuildDirectoryRestClient(directoryUri); - } - /// /// Initializes a new instance of the /// class. @@ -2613,8 +2559,7 @@ private async Task> RenameInternal( // Create the destination path with the destination SAS destDirectoryClient = new ShareDirectoryClient( destUriBuilder.ToUri(), - ClientConfiguration.ClientDiagnostics, - ClientConfiguration.ClientOptions); + ClientConfiguration); } } else diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs index 5a812432eb602..b671bb3763a24 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs @@ -238,7 +238,9 @@ public ShareFileClient( fileUri: fileUri, authentication: (HttpPipelinePolicy)null, options: options, - storageSharedKeyCredential: null) + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -266,7 +268,9 @@ public ShareFileClient( fileUri: fileUri, authentication: credential.AsPolicy(), options: options, - storageSharedKeyCredential: credential) + storageSharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -294,7 +298,13 @@ public ShareFileClient( Uri fileUri, AzureSasCredential credential, ShareClientOptions options = default) - : this(fileUri, credential.AsPolicy(fileUri), options, credential) + : this( + fileUri, + credential.AsPolicy(fileUri), + options, + storageSharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -325,7 +335,9 @@ public ShareFileClient( fileUri: fileUri, authentication: credential.AsPolicy(options), options: options ?? new ShareClientOptions(), - storageSharedKeyCredential: null) + storageSharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(fileUri); } @@ -350,99 +362,33 @@ public ShareFileClient( /// /// The shared key credential used to sign requests. /// - internal ShareFileClient( - Uri fileUri, - HttpPipelinePolicy authentication, - ShareClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) - { - Argument.AssertNotNull(fileUri, nameof(fileUri)); - options ??= new ShareClientOptions(); - _uri = fileUri; - _clientConfiguration = new ShareClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - sasCredential: null, - clientDiagnostics: new ClientDiagnostics(options), - clientOptions: options); - _fileRestClient = BuildFileRestClient(fileUri); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the file that includes the - /// name of the account, the name of the share, and the path of the - /// file. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// /// - /// The shared access signature used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal ShareFileClient( Uri fileUri, HttpPipelinePolicy authentication, ShareClientOptions options, - AzureSasCredential sasCredential) + StorageSharedKeyCredential storageSharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(fileUri, nameof(fileUri)); options ??= new ShareClientOptions(); _uri = fileUri; _clientConfiguration = new ShareClientConfiguration( pipeline: options.Build(authentication), + sharedKeyCredential: storageSharedKeyCredential, sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), clientOptions: options); _fileRestClient = BuildFileRestClient(fileUri); } - /// - /// Initializes a new instance of the - /// class. - /// - /// This will create an instance that uses the same diagnostics as another - /// client. This client will be used within another API call of the parent - /// client (namely Rename). This is in the case that the new child client - /// has different credentials than the parent client. - /// - /// - /// A referencing the file that includes the - /// name of the account, the name of the share, and the path of the - /// file. - /// - /// - /// The diagnostics from the parent client. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// - internal ShareFileClient( - Uri fileUri, - ClientDiagnostics diagnostics, - ShareClientOptions options) - { - Argument.AssertNotNull(fileUri, nameof(fileUri)); - options ??= new ShareClientOptions(); - _uri = fileUri; - _clientConfiguration = new ShareClientConfiguration( - pipeline: options.Build(), - sharedKeyCredential: default, - clientDiagnostics: diagnostics, - clientOptions: options); - _fileRestClient = BuildFileRestClient(fileUri); - } - /// /// Initializes a new instance of the class. /// @@ -6309,8 +6255,7 @@ private async Task> RenameInternal( // Create the destination path with the destination SAS destFileClient = new ShareFileClient( destUriBuilder.ToUri(), - ClientConfiguration.ClientDiagnostics, - ClientConfiguration.ClientOptions); + ClientConfiguration); } } else diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs index 858d20e847ca0..0a2d18d28ac3a 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs @@ -152,7 +152,13 @@ public ShareServiceClient( public ShareServiceClient( Uri serviceUri, ShareClientOptions options = default) - : this(serviceUri, (HttpPipelinePolicy)null, options, storageSharedKeyCredential:null) + : this( + serviceUri, + (HttpPipelinePolicy)null, + options, + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -175,7 +181,13 @@ public ShareServiceClient( Uri serviceUri, StorageSharedKeyCredential credential, ShareClientOptions options = default) - : this(serviceUri, credential.AsPolicy(), options, credential) + : this( + serviceUri, + credential.AsPolicy(), + options, + sharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -202,7 +214,13 @@ public ShareServiceClient( Uri serviceUri, AzureSasCredential credential, ShareClientOptions options = default) - : this(serviceUri, credential.AsPolicy(serviceUri), options, sasCredential:credential) + : this( + serviceUri, + credential.AsPolicy(serviceUri), + options, + sharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -256,7 +274,10 @@ public ShareServiceClient( : this( serviceUri: serviceUri, authentication: credential.AsPolicy(options), - options: options ?? new ShareClientOptions()) + options: options ?? new ShareClientOptions(), + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(serviceUri); } @@ -276,58 +297,31 @@ public ShareServiceClient( /// policies for authentication, retries, etc., that are applied to /// every request. /// - /// + /// /// The shared key credential used to sign requests. /// - internal ShareServiceClient( - Uri serviceUri, - HttpPipelinePolicy authentication, - ShareClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential = default) - { - Argument.AssertNotNull(serviceUri, nameof(serviceUri)); - options ??= new ShareClientOptions(); - _uri = serviceUri; - _clientConfiguration = new ShareClientConfiguration( - pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, - sasCredential: null, - clientDiagnostics: new ClientDiagnostics(options), - clientOptions: options); - _serviceRestClient = BuildServiceRestClient(); - } - - /// - /// Initializes a new instance of the - /// class. - /// - /// - /// A referencing the file service. - /// - /// - /// An optional authentication policy used to sign requests. - /// - /// - /// Optional client options that define the transport pipeline - /// policies for authentication, retries, etc., that are applied to - /// every request. - /// /// - /// The shared access signature used to sign requests. + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. /// internal ShareServiceClient( Uri serviceUri, HttpPipelinePolicy authentication, ShareClientOptions options, - AzureSasCredential sasCredential) + StorageSharedKeyCredential sharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(serviceUri, nameof(serviceUri)); options ??= new ShareClientOptions(); _uri = serviceUri; _clientConfiguration = new ShareClientConfiguration( pipeline: options.Build(authentication), - sharedKeyCredential: null, + sharedKeyCredential: sharedKeyCredential, sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), clientOptions: options); _serviceRestClient = BuildServiceRestClient(); diff --git a/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs b/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs index 9f12a0f268f37..b7ffcf191da36 100644 --- a/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs +++ b/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs @@ -234,7 +234,13 @@ public QueueClient(string connectionString, string queueName, QueueClientOptions /// /// Storage SAS Token Overview public QueueClient(Uri queueUri, QueueClientOptions options = default) - : this(queueUri, (HttpPipelinePolicy)null, options, null) + : this( + queueUri, + (HttpPipelinePolicy)null, + options, + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -256,7 +262,13 @@ public QueueClient(Uri queueUri, QueueClientOptions options = default) /// every request. /// public QueueClient(Uri queueUri, StorageSharedKeyCredential credential, QueueClientOptions options = default) - : this(queueUri, credential.AsPolicy(), options, credential) + : this( + queueUri, + credential.AsPolicy(), + options, + sharedKeyCredential: credential, + sasCredential: null, + tokenCredential: null) { } @@ -282,7 +294,13 @@ public QueueClient(Uri queueUri, StorageSharedKeyCredential credential, QueueCli /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public QueueClient(Uri queueUri, AzureSasCredential credential, QueueClientOptions options = default) - : this(queueUri, credential.AsPolicy(queueUri), options, null) + : this( + queueUri, + credential.AsPolicy(queueUri), + options, + sharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -304,7 +322,13 @@ public QueueClient(Uri queueUri, AzureSasCredential credential, QueueClientOptio /// every request. /// public QueueClient(Uri queueUri, TokenCredential credential, QueueClientOptions options = default) - : this(queueUri, credential.AsPolicy(options), options, null) + : this( + queueUri, + credential.AsPolicy(options), + options, + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(queueUri); } @@ -326,14 +350,22 @@ public QueueClient(Uri queueUri, TokenCredential credential, QueueClientOptions /// policies for authentication, retries, etc., that are applied to /// every request. /// - /// + /// /// The shared key credential used to sign requests. /// + /// + /// The SAS credential used to sign requests. + /// + /// + /// The token credential used to sign requests. + /// internal QueueClient( Uri queueUri, HttpPipelinePolicy authentication, QueueClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) + StorageSharedKeyCredential sharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(queueUri, nameof(queueUri)); _uri = queueUri; @@ -341,7 +373,9 @@ internal QueueClient( options ??= new QueueClientOptions(); _clientConfiguration = new QueueClientConfiguration( pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, + sharedKeyCredential: sharedKeyCredential, + sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), version: options.Version, clientSideEncryption: QueueClientSideEncryptionOptions.CloneFrom(options._clientSideEncryptionOptions), diff --git a/sdk/storage/Azure.Storage.Queues/src/QueueClientConfiguration.cs b/sdk/storage/Azure.Storage.Queues/src/QueueClientConfiguration.cs index cacb5e99d12e8..8be13423203a5 100644 --- a/sdk/storage/Azure.Storage.Queues/src/QueueClientConfiguration.cs +++ b/sdk/storage/Azure.Storage.Queues/src/QueueClientConfiguration.cs @@ -18,6 +18,9 @@ internal class QueueClientConfiguration : StorageClientConfiguration public SyncAsyncEventHandler QueueMessageDecodingFailedHandlers { get; internal set; } + /// + /// Create a with shared key authentication. + /// public QueueClientConfiguration( HttpPipeline pipeline, StorageSharedKeyCredential sharedKeyCredential, @@ -26,7 +29,105 @@ public QueueClientConfiguration( QueueClientSideEncryptionOptions clientSideEncryption, QueueMessageEncoding messageEncoding, SyncAsyncEventHandler queueMessageDecodingFailedHandlers) - : base(pipeline, sharedKeyCredential, clientDiagnostics) + : this( + pipeline, + sharedKeyCredential, + default, + default, + clientDiagnostics, + version, + clientSideEncryption, + messageEncoding, + queueMessageDecodingFailedHandlers) + { + } + + /// + /// Create a with SAS authentication. + /// + public QueueClientConfiguration( + HttpPipeline pipeline, + AzureSasCredential sasCredential, + ClientDiagnostics clientDiagnostics, + QueueClientOptions.ServiceVersion version, + QueueClientSideEncryptionOptions clientSideEncryption, + QueueMessageEncoding messageEncoding, + SyncAsyncEventHandler queueMessageDecodingFailedHandlers) + : this( + pipeline, + default, + sasCredential, + default, + clientDiagnostics, + version, + clientSideEncryption, + messageEncoding, + queueMessageDecodingFailedHandlers) + { + } + + /// + /// Create a with SAS authentication. + /// + public QueueClientConfiguration( + HttpPipeline pipeline, + TokenCredential tokenCredential, + ClientDiagnostics clientDiagnostics, + QueueClientOptions.ServiceVersion version, + QueueClientSideEncryptionOptions clientSideEncryption, + QueueMessageEncoding messageEncoding, + SyncAsyncEventHandler queueMessageDecodingFailedHandlers) + : this( + pipeline, + default, + default, + tokenCredential, + clientDiagnostics, + version, + clientSideEncryption, + messageEncoding, + queueMessageDecodingFailedHandlers) + { + } + + /// + /// Create a without authentication, + /// or with SAS that was provided as part of the URL. + /// + public QueueClientConfiguration( + HttpPipeline pipeline, + ClientDiagnostics clientDiagnostics, + QueueClientOptions.ServiceVersion version, + QueueClientSideEncryptionOptions clientSideEncryption, + QueueMessageEncoding messageEncoding, + SyncAsyncEventHandler queueMessageDecodingFailedHandlers) + : this( + pipeline, + default, + default, + default, + clientDiagnostics, + version, + clientSideEncryption, + messageEncoding, + queueMessageDecodingFailedHandlers) + { + } + + /// + /// Used for internal Client Constructors that accept multiple types of authentication. + /// + internal QueueClientConfiguration( + HttpPipeline pipeline, + StorageSharedKeyCredential sharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential, + ClientDiagnostics clientDiagnostics, + QueueClientOptions.ServiceVersion version, + QueueClientSideEncryptionOptions clientSideEncryption, + QueueMessageEncoding messageEncoding, + SyncAsyncEventHandler queueMessageDecodingFailedHandlers) + : base(pipeline, sharedKeyCredential, sasCredential, tokenCredential, clientDiagnostics) { Version = version; ClientSideEncryption = clientSideEncryption; diff --git a/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs b/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs index 774988834289d..73a5ad529eef6 100644 --- a/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs +++ b/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs @@ -153,7 +153,13 @@ public QueueServiceClient(string connectionString, QueueClientOptions options) /// /// Storage SAS Token Overview public QueueServiceClient(Uri serviceUri, QueueClientOptions options = default) - : this(serviceUri, (HttpPipelinePolicy)null, options, null) + : this( + serviceUri, + (HttpPipelinePolicy)null, + options, + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: null) { } @@ -174,7 +180,13 @@ public QueueServiceClient(Uri serviceUri, QueueClientOptions options = default) /// every request. /// public QueueServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, QueueClientOptions options = default) - : this(serviceUri, credential.AsPolicy(), options, credential) + : this( + serviceUri, + credential.AsPolicy(), + options, + credential, + sasCredential: null, + tokenCredential: null) { } @@ -199,7 +211,13 @@ public QueueServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, /// This constructor should only be used when shared access signature needs to be updated during lifespan of this client. /// public QueueServiceClient(Uri serviceUri, AzureSasCredential credential, QueueClientOptions options = default) - : this(serviceUri, credential.AsPolicy(serviceUri), options, null) + : this( + serviceUri, + credential.AsPolicy(serviceUri), + options, + sharedKeyCredential: null, + sasCredential: credential, + tokenCredential: null) { } @@ -220,7 +238,13 @@ public QueueServiceClient(Uri serviceUri, AzureSasCredential credential, QueueCl /// every request. /// public QueueServiceClient(Uri serviceUri, TokenCredential credential, QueueClientOptions options = default) - : this(serviceUri, credential.AsPolicy(options), options, null) + : this( + serviceUri, + credential.AsPolicy(options), + options, + sharedKeyCredential: null, + sasCredential: null, + tokenCredential: credential) { Errors.VerifyHttpsTokenAuth(serviceUri); } @@ -241,14 +265,22 @@ public QueueServiceClient(Uri serviceUri, TokenCredential credential, QueueClien /// policies for authentication, retries, etc., that are applied to /// every request. /// - /// + /// /// The shared key credential used to sign requests. /// + /// + /// The token credential used to sign requests. + /// + /// + /// The SAS credential used to sign requests. + /// internal QueueServiceClient( Uri serviceUri, HttpPipelinePolicy authentication, QueueClientOptions options, - StorageSharedKeyCredential storageSharedKeyCredential) + StorageSharedKeyCredential sharedKeyCredential, + AzureSasCredential sasCredential, + TokenCredential tokenCredential) { Argument.AssertNotNull(serviceUri, nameof(serviceUri)); _uri = serviceUri; @@ -256,7 +288,9 @@ internal QueueServiceClient( _clientConfiguration = new QueueClientConfiguration( pipeline: options.Build(authentication), - sharedKeyCredential: storageSharedKeyCredential, + sharedKeyCredential: sharedKeyCredential, + sasCredential: sasCredential, + tokenCredential: tokenCredential, clientDiagnostics: new ClientDiagnostics(options), version: options.Version, clientSideEncryption: QueueClientSideEncryptionOptions.CloneFrom(options._clientSideEncryptionOptions),