Skip to content
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

Updated client constructors to ensure authentication is property being added to ClientConfiguration #37710

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCr
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Blobs.BlobContainerClient> CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.BlobContainerClient>> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> 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<Azure.Response> DeleteBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Storage.Blobs.Models.TaggedBlobItem> FindBlobsByTags(string tagFilterSqlExpression, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCr
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Blobs.BlobContainerClient> CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.BlobContainerClient>> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> 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<Azure.Response> DeleteBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Storage.Blobs.Models.TaggedBlobItem> FindBlobsByTags(string tagFilterSqlExpression, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public BlobServiceClient(System.Uri serviceUri, Azure.Storage.StorageSharedKeyCr
public virtual System.Uri Uri { get { throw null; } }
public virtual Azure.Response<Azure.Storage.Blobs.BlobContainerClient> CreateBlobContainer(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.BlobContainerClient>> CreateBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.PublicAccessType publicAccessType = Azure.Storage.Blobs.Models.PublicAccessType.None, System.Collections.Generic.IDictionary<string, string> 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<Azure.Response> DeleteBlobContainerAsync(string blobContainerName, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Storage.Blobs.Models.TaggedBlobItem> FindBlobsByTags(string tagFilterSqlExpression, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
106 changes: 40 additions & 66 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,13 @@ public BlobBaseClient(string connectionString, string blobContainerName, string
/// every request.
/// </param>
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)
{
}

Expand All @@ -261,7 +267,13 @@ public BlobBaseClient(Uri blobUri, BlobClientOptions options = default)
/// every request.
/// </param>
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)
{
}

Expand All @@ -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.
/// </remarks>
public BlobBaseClient(Uri blobUri, AzureSasCredential credential, BlobClientOptions options = default)
: this(blobUri, credential.AsPolicy<BlobUriBuilder>(blobUri), options, storageSharedKeyCredential: null)
: this(
blobUri,
credential.AsPolicy<BlobUriBuilder>(blobUri),
options,
storageSharedKeyCredential: null,
sasCredential: credential,
tokenCredential: null)
{
}

Expand All @@ -311,7 +329,13 @@ public BlobBaseClient(Uri blobUri, AzureSasCredential credential, BlobClientOpti
/// every request.
/// </param>
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);
}
Expand All @@ -334,13 +358,21 @@ public BlobBaseClient(Uri blobUri, TokenCredential credential, BlobClientOptions
/// policies for authentication, retries, etc., that are applied to
/// every request.
/// </param>
/// <param name="storageSharedKeyCredential">
/// The shared key credential used to sign requests.
/// </param>
/// <param name="sasCredential">
/// The SAS credential used to sign requests.
/// </param>
/// <param name="tokenCredential">
/// The token credential used to sign requests.
/// </param>
internal BlobBaseClient(
Uri blobUri,
HttpPipelinePolicy authentication,
BlobClientOptions options,
StorageSharedKeyCredential storageSharedKeyCredential,
AzureSasCredential sasCredential,
TokenCredential tokenCredential)
{
Argument.AssertNotNull(blobUri, nameof(blobUri));
Expand All @@ -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);
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobBaseClient"/>
/// class.
/// </summary>
/// <param name="blobUri">
/// A <see cref="Uri"/> 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}".
/// </param>
/// <param name="authentication">
/// An optional authentication policy used to sign requests.
/// </param>
/// <param name="options">
/// Optional client options that define the transport pipeline
/// policies for authentication, retries, etc., that are applied to
/// every request.
/// </param>
/// <param name="storageSharedKeyCredential">
/// The shared key credential used to sign requests.
/// </param>
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,
Expand Down Expand Up @@ -651,9 +625,9 @@ protected static async Task<HttpAuthorization> 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;
}
Expand Down
Loading