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

[Storage ]Added WithCustomerProvidedKey() and WithEncryptionScope() to BlobClie… #20399

Merged
merged 1 commit into from
Apr 15, 2021
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
1 change: 1 addition & 0 deletions sdk/storage/Azure.Storage.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 12.9.0-beta.4 (Unreleased)
- Added support for service version 2020-08-04.
- Added support for Blob Query Parquet input format.
- Added WithCustomerProvidedKey() and WithEncryptionScope() to BlobClient, BlobBaseClient, AppendBlobClient, and PageBlobClient.
- Fixed bug where clients would sometimes throw a NullReferenceException when calling GenerateSas() with a BlobSasBuilder parameter.
- Fixed bug where BlobBaseClient.Exists() would not function correctly on blobs encrypted with CPK.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public BlobClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredential c
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(string path, bool overwrite = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(string path, System.Threading.CancellationToken cancellationToken) { throw null; }
protected internal virtual Azure.Storage.Blobs.BlobClient WithClientSideEncryptionOptionsCore(Azure.Storage.ClientSideEncryptionOptions clientSideEncryptionOptions) { throw null; }
public new Azure.Storage.Blobs.BlobClient WithCustomerProvidedKey(Azure.Storage.Blobs.Models.CustomerProvidedKey? customerProvidedKey) { throw null; }
public new Azure.Storage.Blobs.BlobClient WithEncryptionScope(string encryptionScope) { throw null; }
public new Azure.Storage.Blobs.BlobClient WithSnapshot(string snapshot) { throw null; }
public new Azure.Storage.Blobs.BlobClient WithVersion(string versionId) { throw null; }
Comment on lines +45 to 48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have With(string snapshot = default, encryptionScope = default, cpk = default, versionId = default ?:D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add every permutation just to be safe, 4 factorial overloads. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about WithOptions ? :-)

}
Expand Down Expand Up @@ -1299,6 +1301,8 @@ public AppendBlobClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCreden
public virtual System.Threading.Tasks.Task<System.IO.Stream> OpenWriteAsync(bool overwrite, Azure.Storage.Blobs.Models.AppendBlobOpenWriteOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Storage.Blobs.Models.BlobInfo> Seal(Azure.Storage.Blobs.Models.AppendBlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobInfo>> SealAsync(Azure.Storage.Blobs.Models.AppendBlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public new Azure.Storage.Blobs.Specialized.AppendBlobClient WithCustomerProvidedKey(Azure.Storage.Blobs.Models.CustomerProvidedKey? customerProvidedKey) { throw null; }
public new Azure.Storage.Blobs.Specialized.AppendBlobClient WithEncryptionScope(string encryptionScope) { throw null; }
public new Azure.Storage.Blobs.Specialized.AppendBlobClient WithSnapshot(string snapshot) { throw null; }
public new Azure.Storage.Blobs.Specialized.AppendBlobClient WithVersion(string versionId) { throw null; }
}
Expand Down Expand Up @@ -1394,6 +1398,8 @@ public BlobBaseClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredenti
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobCopyInfo>> SyncCopyFromUriAsync(System.Uri source, Azure.Storage.Blobs.Models.BlobCopyFromUriOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response Undelete(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> UndeleteAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Storage.Blobs.Specialized.BlobBaseClient WithCustomerProvidedKey(Azure.Storage.Blobs.Models.CustomerProvidedKey? customerProvidedKey) { throw null; }
public virtual Azure.Storage.Blobs.Specialized.BlobBaseClient WithEncryptionScope(string encryptionScope) { throw null; }
public virtual Azure.Storage.Blobs.Specialized.BlobBaseClient WithSnapshot(string snapshot) { throw null; }
protected virtual Azure.Storage.Blobs.Specialized.BlobBaseClient WithSnapshotCore(string snapshot) { throw null; }
public virtual Azure.Storage.Blobs.Specialized.BlobBaseClient WithVersion(string versionId) { throw null; }
Expand Down Expand Up @@ -1464,6 +1470,8 @@ public BlockBlobClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredent
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(System.IO.Stream content, Azure.Storage.Blobs.Models.BlobHttpHeaders httpHeaders = null, System.Collections.Generic.IDictionary<string, string> metadata = null, Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, Azure.Storage.Blobs.Models.AccessTier? accessTier = default(Azure.Storage.Blobs.Models.AccessTier?), System.IProgress<long> progressHandler = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(System.IO.Stream content, Azure.Storage.Blobs.Models.BlobUploadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public new Azure.Storage.Blobs.Specialized.BlockBlobClient WithCustomerProvidedKey(Azure.Storage.Blobs.Models.CustomerProvidedKey? customerProvidedKey) { throw null; }
public new Azure.Storage.Blobs.Specialized.BlockBlobClient WithEncryptionScope(string encryptionScope) { throw null; }
public new Azure.Storage.Blobs.Specialized.BlockBlobClient WithSnapshot(string snapshot) { throw null; }
protected sealed override Azure.Storage.Blobs.Specialized.BlobBaseClient WithSnapshotCore(string snapshot) { throw null; }
public new Azure.Storage.Blobs.Specialized.BlockBlobClient WithVersion(string versionId) { throw null; }
Expand Down Expand Up @@ -1511,6 +1519,8 @@ public PageBlobClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredenti
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.PageInfo>> UploadPagesAsync(System.IO.Stream content, long offset, byte[] transactionalContentHash = null, Azure.Storage.Blobs.Models.PageBlobRequestConditions conditions = null, System.IProgress<long> progressHandler = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Storage.Blobs.Models.PageInfo> UploadPagesFromUri(System.Uri sourceUri, Azure.HttpRange sourceRange, Azure.HttpRange range, byte[] sourceContentHash = null, Azure.Storage.Blobs.Models.PageBlobRequestConditions conditions = null, Azure.Storage.Blobs.Models.PageBlobRequestConditions sourceConditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.PageInfo>> UploadPagesFromUriAsync(System.Uri sourceUri, Azure.HttpRange sourceRange, Azure.HttpRange range, byte[] sourceContentHash = null, Azure.Storage.Blobs.Models.PageBlobRequestConditions conditions = null, Azure.Storage.Blobs.Models.PageBlobRequestConditions sourceConditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public new Azure.Storage.Blobs.Specialized.PageBlobClient WithCustomerProvidedKey(Azure.Storage.Blobs.Models.CustomerProvidedKey? customerProvidedKey) { throw null; }
public new Azure.Storage.Blobs.Specialized.PageBlobClient WithEncryptionScope(string encryptionScope) { throw null; }
public new Azure.Storage.Blobs.Specialized.PageBlobClient WithSnapshot(string snapshot) { throw null; }
protected sealed override Azure.Storage.Blobs.Specialized.BlobBaseClient WithSnapshotCore(string snapshot) { throw null; }
public new Azure.Storage.Blobs.Specialized.PageBlobClient WithVersion(string versionId) { throw null; }
Expand Down
40 changes: 40 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,46 @@ private AppendBlobRestClient BuildAppendBlobRestClient(BlobUriBuilder uriBuilder
ClientConfiguration);
}

/// <summary>
/// Initializes a new instance of the <see cref="AppendBlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/>.
///
/// </summary>
/// <param name="customerProvidedKey">The customer provided key.</param>
/// <returns>A new <see cref="AppendBlobClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the customer provide key in the returned <see cref="AppendBlobClient"/>.
/// </remarks>
public new AppendBlobClient WithCustomerProvidedKey(CustomerProvidedKey? customerProvidedKey)
kasobol-msft marked this conversation as resolved.
Show resolved Hide resolved
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.CustomerProvidedKey = customerProvidedKey;
return new AppendBlobClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration);
}

/// <summary>
/// Initializes a new instance of the <see cref="AppendBlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="encryptionScope"/>.
///
/// </summary>
/// <param name="encryptionScope">The encryption scope.</param>
/// <returns>A new <see cref="AppendBlobClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the encryption scope in the returned <see cref="AppendBlobClient"/>.
/// </remarks>
public new AppendBlobClient WithEncryptionScope(string encryptionScope)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.EncryptionScope = encryptionScope;
return new AppendBlobClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration);
}

#region Create
/// <summary>
/// The <see cref="Create(AppendBlobCreateOptions, CancellationToken)"/>
Expand Down
46 changes: 46 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,52 @@ private protected virtual BlobBaseClient WithVersionCore(string versionId)
ClientSideEncryption);
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobBaseClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/>.
///
/// </summary>
/// <param name="customerProvidedKey">The customer provided key.</param>
/// <returns>A new <see cref="BlobBaseClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the customer provide key in the returned <see cref="BlobBaseClient"/>.
/// </remarks>
public virtual BlobBaseClient WithCustomerProvidedKey(CustomerProvidedKey? customerProvidedKey) => WithCustomerProvidedKeyCore(customerProvidedKey);

private protected virtual BlobBaseClient WithCustomerProvidedKeyCore(CustomerProvidedKey? customerProvidedKey)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.CustomerProvidedKey = customerProvidedKey;
return new BlobBaseClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration,
clientSideEncryption: ClientSideEncryption?.Clone());
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobBaseClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="encryptionScope"/>.
///
/// </summary>
/// <param name="encryptionScope">The encryption scope.</param>
/// <returns>A new <see cref="BlobBaseClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the encryption scope in the returned <see cref="BlobBaseClient"/>.
/// </remarks>
public virtual BlobBaseClient WithEncryptionScope(string encryptionScope) => WithEncryptionScopeCore(encryptionScope);

private protected virtual BlobBaseClient WithEncryptionScopeCore(string encryptionScope)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.EncryptionScope = encryptionScope;
return new BlobBaseClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration,
clientSideEncryption: ClientSideEncryption?.Clone());
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobLeaseClient"/> class.
/// </summary>
Expand Down
42 changes: 42 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,48 @@ internal BlobClient(
ClientSideEncryption);
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/>.
///
/// </summary>
/// <param name="customerProvidedKey">The customer provided key.</param>
/// <returns>A new <see cref="BlobClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the customer provide key in the returned <see cref="BlobClient"/>.
/// </remarks>
public new BlobClient WithCustomerProvidedKey(CustomerProvidedKey? customerProvidedKey)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.CustomerProvidedKey = customerProvidedKey;
return new BlobClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration,
clientSideEncryption: ClientSideEncryption?.Clone());
}

/// <summary>
/// Initializes a new instance of the <see cref="BlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="encryptionScope"/>.
///
/// </summary>
/// <param name="encryptionScope">The encryption scope.</param>
/// <returns>A new <see cref="BlobClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the encryption scope in the returned <see cref="BlobClient"/>.
/// </remarks>
public new BlobClient WithEncryptionScope(string encryptionScope)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.EncryptionScope = encryptionScope;
return new BlobClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration,
clientSideEncryption: ClientSideEncryption?.Clone());
}

/// <summary>
/// Creates a new instance of the <see cref="BlobClient"/> class, maintaining all the same
/// internals but specifying new <see cref="ClientSideEncryptionOptions"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ public BlobClientConfiguration(
CustomerProvidedKey = customerProvidedKey;
EncryptionScope = encryptionScope;
}

internal static BlobClientConfiguration DeepCopy(BlobClientConfiguration originalClientConfiguration)
=> new BlobClientConfiguration(
pipeline: originalClientConfiguration.Pipeline,
sharedKeyCredential: originalClientConfiguration.SharedKeyCredential,
clientDiagnostics: originalClientConfiguration.ClientDiagnostics,
version: originalClientConfiguration.Version,
customerProvidedKey: originalClientConfiguration.CustomerProvidedKey,
encryptionScope: originalClientConfiguration.EncryptionScope);
}
}
41 changes: 41 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Cryptography;
using Azure.Storage.Shared;
using Metadata = System.Collections.Generic.IDictionary<string, string>;
using Tags = System.Collections.Generic.IDictionary<string, string>;
Expand Down Expand Up @@ -453,6 +454,46 @@ protected sealed override BlobBaseClient WithSnapshotCore(string snapshot)
return new BlockBlobClient(builder.ToUri(), ClientConfiguration);
}

/// <summary>
/// Initializes a new instance of the <see cref="BlockBlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="customerProvidedKey"/>.
///
/// </summary>
/// <param name="customerProvidedKey">The customer provided key.</param>
/// <returns>A new <see cref="BlockBlobClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the customer provide key in the returned <see cref="BlockBlobClient"/>.
/// </remarks>
public new BlockBlobClient WithCustomerProvidedKey(CustomerProvidedKey? customerProvidedKey)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.CustomerProvidedKey = customerProvidedKey;
return new BlockBlobClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration);
}

/// <summary>
/// Initializes a new instance of the <see cref="BlockBlobClient"/>
/// class with an identical <see cref="Uri"/> source but the specified
/// <paramref name="encryptionScope"/>.
///
/// </summary>
/// <param name="encryptionScope">The encryption scope.</param>
/// <returns>A new <see cref="BlockBlobClient"/> instance.</returns>
/// <remarks>
/// Pass null to remove the encryption scope in the returned <see cref="BlockBlobClient"/>.
/// </remarks>
public new BlockBlobClient WithEncryptionScope(string encryptionScope)
{
BlobClientConfiguration newClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration);
newClientConfiguration.EncryptionScope = encryptionScope;
return new BlockBlobClient(
blobUri: Uri,
clientConfiguration: newClientConfiguration);
}

///// <summary>
///// Creates a new BlockBlobURL object identical to the source but with the specified version ID.
///// </summary>
Expand Down
Loading