Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Storage.Blobs.Models;

#pragma warning disable SA1402 // File may only contain a single type

Expand Down Expand Up @@ -148,8 +149,10 @@ public EncryptedBlockBlobClient(Uri blobUri, TokenCredential credential, BlobCli
/// <param name="pipeline">
/// The transport pipeline used to send every request.
/// </param>
internal EncryptedBlockBlobClient(Uri blobUri, HttpPipeline pipeline)
: base(blobUri, pipeline)
/// <param name="clientDiagnostics">Client diagnostics.</param>
/// <param name="customerProvidedKey">Customer provided key.</param>
internal EncryptedBlockBlobClient(Uri blobUri, HttpPipeline pipeline, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey)
: base(blobUri, pipeline, clientDiagnostics, customerProvidedKey)
{
}
#endregion ctors
Expand All @@ -175,7 +178,11 @@ public static partial class SpecializedBlobExtensions
/// <returns>A new <see cref="EncryptedBlockBlobClient"/> instance.</returns>
public static EncryptedBlockBlobClient GetEncryptedBlockBlobClient(
this BlobContainerClient client,
string blobName)
=> new EncryptedBlockBlobClient(client.Uri.AppendToPath(blobName), client.Pipeline);
string blobName) =>
new EncryptedBlockBlobClient(
client.Uri.AppendToPath(blobName),
client.Pipeline,
client.ClientDiagnostics,
client.CustomerProvidedKey);
}
}
54 changes: 11 additions & 43 deletions sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,10 @@ public AppendBlobClient(Uri blobUri, TokenCredential credential, BlobClientOptio
/// <param name="pipeline">
/// The transport pipeline used to send every request.
/// </param>
/// <param name="options">
/// Optional client options that define the transport pipeline
/// policies for authentication, retries, etc., that are applied to
/// every request.
/// </param>
internal AppendBlobClient(Uri blobUri, HttpPipeline pipeline, BlobClientOptions options = default)
: base(blobUri, pipeline, options)
/// <param name="clientDiagnostics">Client diagnostics.</param>
/// <param name="customerProvidedKey">Customer provided key.</param>
internal AppendBlobClient(Uri blobUri, HttpPipeline pipeline, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey)
: base(blobUri, pipeline, clientDiagnostics, customerProvidedKey)
{
}
#endregion ctors
Expand All @@ -202,40 +199,7 @@ internal AppendBlobClient(Uri blobUri, HttpPipeline pipeline, BlobClientOptions
public new AppendBlobClient WithSnapshot(string snapshot)
{
var builder = new BlobUriBuilder(Uri) { Snapshot = snapshot };
return new AppendBlobClient(builder.ToUri(), Pipeline);
}

/// <summary>
/// Initializes a new instance of the <see cref="AppendBlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/> customer provided key.
/// </summary>
/// <param name="customerProvidedKey">
/// The customer provided key to be used by the service to encrypt data.
/// </param>
/// <returns>A new <see cref="AppendBlobClient"/> instance.</returns>
public new AppendBlobClient WithCustomerProvidedKey(CustomerProvidedKey customerProvidedKey) => (AppendBlobClient)WithCustomerProvidedKeyCore(customerProvidedKey);

/// <summary>
/// Creates a new instance of the <see cref="AppendBlobClient"/> class
/// with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/> customer provided key.
/// </summary>
/// <param name="customerProvidedKey">
/// The customer provided key to be used by the service to encrypt data.
/// </param>
/// <returns>A new <see cref="AppendBlobClient"/> instance.</returns>
protected sealed override BlobBaseClient WithCustomerProvidedKeyCore(CustomerProvidedKey customerProvidedKey)
{
var uriBuilder = new UriBuilder(Uri)
{
Scheme = Constants.Blob.Https,
Port = Constants.Blob.HttpsPort
};
return new AppendBlobClient(
uriBuilder.Uri,
Pipeline,
new BlobClientOptions(customerProvidedKey: customerProvidedKey));
return new AppendBlobClient(builder.ToUri(), Pipeline, ClientDiagnostics, CustomerProvidedKey);
}

#region Create
Expand Down Expand Up @@ -1059,7 +1023,11 @@ public static partial class SpecializedBlobExtensions
/// <returns>A new <see cref="AppendBlobClient"/> instance.</returns>
public static AppendBlobClient GetAppendBlobClient(
this BlobContainerClient client,
string blobName)
=> new AppendBlobClient(client.Uri.AppendToPath(blobName), client.Pipeline);
string blobName) =>
new AppendBlobClient(
client.Uri.AppendToPath(blobName),
client.Pipeline,
client.ClientDiagnostics,
client.CustomerProvidedKey);
}
}
69 changes: 18 additions & 51 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public class BlobBaseClient
/// <summary>
/// The <see cref="CustomerProvidedKey"/> to be used when sending requests.
/// </summary>
private readonly CustomerProvidedKey? _customerProvidedKey;
internal readonly CustomerProvidedKey? _customerProvidedKey;

/// <summary>
/// The <see cref="CustomerProvidedKey"/> to be used when sending requests.
/// </summary>
public virtual CustomerProvidedKey? CustomerProvidedKey => _customerProvidedKey;
internal virtual CustomerProvidedKey? CustomerProvidedKey => _customerProvidedKey;

/// <summary>
/// The Storage account name corresponding to the blob client.
Expand Down Expand Up @@ -183,6 +183,7 @@ public BlobBaseClient(string connectionString, string blobContainerName, string
_pipeline = options.Build(conn.Credentials);
_clientDiagnostics = new ClientDiagnostics(options);
_customerProvidedKey = options?.CustomerProvidedKey;
BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _customerProvidedKey);
}

/// <summary>
Expand Down Expand Up @@ -272,6 +273,7 @@ internal BlobBaseClient(Uri blobUri, HttpPipelinePolicy authentication, BlobClie
_pipeline = options.Build(authentication);
_clientDiagnostics = new ClientDiagnostics(options);
_customerProvidedKey = options?.CustomerProvidedKey;
BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _customerProvidedKey);
}

/// <summary>
Expand All @@ -286,18 +288,14 @@ internal BlobBaseClient(Uri blobUri, HttpPipelinePolicy authentication, BlobClie
/// <param name="pipeline">
/// The transport pipeline used to send every request.
/// </param>
/// <param name="options">
/// Optional client options that define the transport pipeline
/// policies for authentication, retries, etc., that are applied to
/// </param>
internal BlobBaseClient(Uri blobUri, HttpPipeline pipeline, BlobClientOptions options = default)
/// <param name="clientDiagnostics">Client diagnostics.</param>
/// <param name="customerProvidedKey">Customer provided key.</param>
internal BlobBaseClient(Uri blobUri, HttpPipeline pipeline, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey)
{
options ??= new BlobClientOptions();

_uri = blobUri;
_pipeline = pipeline;
_clientDiagnostics = new ClientDiagnostics(options);
_customerProvidedKey = options?.CustomerProvidedKey;
_clientDiagnostics = clientDiagnostics;
_customerProvidedKey = customerProvidedKey;
}
#endregion ctors

Expand Down Expand Up @@ -326,42 +324,7 @@ internal BlobBaseClient(Uri blobUri, HttpPipeline pipeline, BlobClientOptions op
protected virtual BlobBaseClient WithSnapshotCore(string snapshot)
{
var builder = new BlobUriBuilder(Uri) { Snapshot = snapshot };
return new BlobBaseClient(builder.ToUri(), Pipeline);
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobClient"/> class
/// with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/> customer provided key.
/// </summary>
/// <param name="customerProvidedKey">
/// The customer provided key to be used by the service to encrypt data.
/// </param>
/// <returns>A new <see cref="BlobClient"/></returns>
public virtual BlobBaseClient WithCustomerProvidedKey(CustomerProvidedKey customerProvidedKey) =>
WithCustomerProvidedKeyCore(customerProvidedKey);

/// <summary>
/// Creates a new instance of the <see cref="BlobClient"/> class
/// with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/> customer provided key.
/// </summary>
/// <param name="customerProvidedKey">
/// The customer provided key to be used by the service to encrypt data.
/// </param>
/// <returns>A new <see cref="BlobClient"/></returns>
protected virtual BlobBaseClient WithCustomerProvidedKeyCore(CustomerProvidedKey customerProvidedKey)
{
var uriBuilder = new UriBuilder(Uri)
{
Scheme = Constants.Blob.Https,
Port = Constants.Blob.HttpsPort
};
return new BlobBaseClient(
uriBuilder.Uri,
Pipeline,
new BlobClientOptions(customerProvidedKey: customerProvidedKey));

return new BlobBaseClient(builder.ToUri(), Pipeline, ClientDiagnostics, CustomerProvidedKey);
}

/// <summary>
Expand Down Expand Up @@ -1213,7 +1176,7 @@ internal Task<Response<BlobProperties>> StagedDownloadAsync(
{
Debug.Assert(singleBlockThreshold <= Constants.Blob.Block.MaxDownloadBytes);

var client = new BlobBaseClient(Uri, Pipeline);
var client = new BlobBaseClient(Uri, Pipeline, ClientDiagnostics, CustomerProvidedKey);
Task<Response<BlobProperties>> downloadTask =
PartitionedDownloader.DownloadAsync(
destination,
Expand Down Expand Up @@ -2977,9 +2940,13 @@ public static partial class SpecializedBlobExtensions
/// <param name="client">The <see cref="BlobContainerClient"/>.</param>
/// <param name="blobName">The name of the blob.</param>
/// <returns>A new <see cref="BlobClient"/> instance.</returns>
public static BlobBaseClient GetBlobClient(
public static BlobBaseClient GetBlobBaseClient(
this BlobContainerClient client,
string blobName)
=> new BlobBaseClient(client.Uri.AppendToPath(blobName), client.Pipeline);
string blobName) =>
new BlobBaseClient(
client.Uri.AppendToPath(blobName),
client.Pipeline,
client.ClientDiagnostics,
client.CustomerProvidedKey);
}
}
8 changes: 5 additions & 3 deletions sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ public BlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions opt
/// <param name="pipeline">
/// The transport pipeline used to send every request.
/// </param>
internal BlobClient(Uri blobUri, HttpPipeline pipeline)
: base(blobUri, pipeline)
/// <param name="clientDiagnostics">Client diagnostics.</param>
/// <param name="customerProvidedKey">Customer provided key.</param>
internal BlobClient(Uri blobUri, HttpPipeline pipeline, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey)
: base(blobUri, pipeline, clientDiagnostics, customerProvidedKey)
{
}
#endregion ctors
Expand Down Expand Up @@ -826,7 +828,7 @@ internal async Task<Response<BlobContentInfo>> StagedUploadAsync(
CancellationToken cancellationToken = default)
{

var client = new BlockBlobClient(Uri, Pipeline);
var client = new BlockBlobClient(Uri, Pipeline, ClientDiagnostics, CustomerProvidedKey);
singleBlockThreshold ??= client.BlockBlobMaxUploadBlobBytes;
Debug.Assert(singleBlockThreshold <= client.BlockBlobMaxUploadBlobBytes);

Expand Down
34 changes: 14 additions & 20 deletions sdk/storage/Azure.Storage.Blobs/src/BlobClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,6 @@ public enum ServiceVersion
/// </summary>
public CustomerProvidedKey? CustomerProvidedKey { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="BlobClientOptions"/>
/// class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests
/// </param>
/// <param name="customerProvidedKey">
/// The customer provided key to be used by the service to encrypt data.
/// </param>
public BlobClientOptions(
ServiceVersion version = LatestVersion,
CustomerProvidedKey? customerProvidedKey = default)
{
Version = version == ServiceVersion.V2019_02_02 ? version: throw Errors.VersionNotSupported(nameof(version));
CustomerProvidedKey = customerProvidedKey;
this.Initialize();
}

/// <summary>
/// Gets or sets the secondary storage <see cref="Uri"/> that can be read from for the storage account if the
/// account is enabled for RA-GRS.
Expand All @@ -79,6 +59,20 @@ public BlobClientOptions(
/// </summary>
public Uri GeoRedundantSecondaryUri { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="BlobClientOptions"/>
/// class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </param>
public BlobClientOptions(ServiceVersion version = LatestVersion)
{
Version = version == ServiceVersion.V2019_02_02 ? version: throw Errors.VersionNotSupported(nameof(version));
this.Initialize();
}

/// <summary>
/// Create an HttpPipeline from BlobClientOptions.
/// </summary>
Expand Down
19 changes: 17 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public class BlobContainerClient
/// </summary>
internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics;

/// <summary>
/// The <see cref="CustomerProvidedKey"/> to be used when sending requests.
/// </summary>
internal readonly CustomerProvidedKey? _customerProvidedKey;

/// <summary>
/// The <see cref="CustomerProvidedKey"/> to be used when sending requests.
/// </summary>
internal virtual CustomerProvidedKey? CustomerProvidedKey => _customerProvidedKey;

/// <summary>
/// The Storage account name corresponding to the container client.
/// </summary>
Expand Down Expand Up @@ -161,6 +171,7 @@ public BlobContainerClient(string connectionString, string blobContainerName, Bl
options ??= new BlobClientOptions();
_pipeline = options.Build(conn.Credentials);
_clientDiagnostics = new ClientDiagnostics(options);
_customerProvidedKey = options.CustomerProvidedKey;
}

/// <summary>
Expand Down Expand Up @@ -245,6 +256,7 @@ internal BlobContainerClient(Uri blobContainerUri, HttpPipelinePolicy authentica
options ??= new BlobClientOptions();
_pipeline = options.Build(authentication);
_clientDiagnostics = new ClientDiagnostics(options);
_customerProvidedKey = options.CustomerProvidedKey;
}

/// <summary>
Expand All @@ -259,11 +271,13 @@ internal BlobContainerClient(Uri blobContainerUri, HttpPipelinePolicy authentica
/// The transport pipeline used to send every request.
/// </param>
/// <param name="clientDiagnostics"></param>
internal BlobContainerClient(Uri containerUri, HttpPipeline pipeline, ClientDiagnostics clientDiagnostics)
/// /// <param name="customerProvidedKey">Customer provided key.</param>
internal BlobContainerClient(Uri containerUri, HttpPipeline pipeline, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey)
{
_uri = containerUri;
_pipeline = pipeline;
_clientDiagnostics = clientDiagnostics;
_customerProvidedKey = customerProvidedKey;
}
#endregion ctor

Expand All @@ -275,7 +289,8 @@ internal BlobContainerClient(Uri containerUri, HttpPipeline pipeline, ClientDiag
/// </summary>
/// <param name="blobName">The name of the blob.</param>
/// <returns>A new <see cref="BlobClient"/> instance.</returns>
public virtual BlobClient GetBlobClient(string blobName) => new BlobClient(Uri.AppendToPath(blobName), _pipeline);
public virtual BlobClient GetBlobClient(string blobName) =>
new BlobClient(Uri.AppendToPath(blobName), _pipeline, ClientDiagnostics, CustomerProvidedKey);

/// <summary>
/// Sets the various name fields if they are currently null.
Expand Down
Loading