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

Client Encryption: Adds Client Encryption APIs to GA SDK #3035

Merged
merged 6 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 1 addition & 6 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,7 @@ internal CosmosClient(
/// a custom container that modifies the response. For example the client encryption
/// uses this to decrypt responses before returning to the caller.
/// </remarks>
#if PREVIEW
public
#else
internal
#endif
virtual CosmosResponseFactory ResponseFactory => this.ClientContext.ResponseFactory;
public virtual CosmosResponseFactory ResponseFactory => this.ClientContext.ResponseFactory;

/// <summary>
/// Gets the endpoint Uri for the Azure Cosmos DB service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
namespace Microsoft.Azure.Cosmos.Fluent
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

/// <summary>
/// <see cref="ClientEncryptionPolicy"/> fluent definition.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
sealed class ClientEncryptionPolicyDefinition
public sealed class ClientEncryptionPolicyDefinition
{
private readonly Collection<ClientEncryptionIncludedPath> clientEncryptionIncludedPaths = new Collection<ClientEncryptionIncludedPath>();
private readonly ContainerBuilder parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ ChangeFeedPolicyDefinition WithChangeFeedPolicy(TimeSpan retention)
/// Defines the ClientEncryptionPolicy for Azure Cosmos container
/// </summary>
/// <returns>An instance of <see cref="ClientEncryptionPolicyDefinition"/>.</returns>
#if PREVIEW
public
#else
internal
#endif
ClientEncryptionPolicyDefinition WithClientEncryptionPolicy()
public ClientEncryptionPolicyDefinition WithClientEncryptionPolicy()
{
return new ClientEncryptionPolicyDefinition(
this,
Expand Down
11 changes: 1 addition & 10 deletions Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
public class ResponseMessage : IDisposable
{
#if PREVIEW
private CosmosDiagnostics diagnostics = null;
#endif

/// <summary>
/// Create a <see cref="ResponseMessage"/>
Expand Down Expand Up @@ -149,21 +147,14 @@ public virtual Stream Content
/// </summary>
public virtual RequestMessage RequestMessage { get; internal set; }

#if PREVIEW
/// <summary>
/// Gets the cosmos diagnostic information for the current request to Azure Cosmos DB service
/// Gets or sets the cosmos diagnostic information for the current request to Azure Cosmos DB service
/// </summary>
public virtual CosmosDiagnostics Diagnostics
{
get => this.diagnostics ?? new CosmosTraceDiagnostics(this.Trace ?? NoOpTrace.Singleton);
set => this.diagnostics = value ?? throw new ArgumentNullException(nameof(this.Diagnostics));
}
#else
/// <summary>
/// Gets the cosmos diagnostic information for the current request to Azure Cosmos DB service
/// </summary>
public virtual CosmosDiagnostics Diagnostics => new CosmosTraceDiagnostics(this.Trace ?? NoOpTrace.Singleton);
#endif

internal ITrace Trace { get; set; }

Expand Down
14 changes: 2 additions & 12 deletions Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,10 @@ public class RequestOptions
/// </summary>
public IReadOnlyDictionary<string, object> Properties { get; set; }

#if PREVIEW
/// <summary>
/// Gets or sets a delegate which injects/appends a custom header in the request.
/// </summary>
public
#else
internal
#endif
Action<Headers> AddRequestHeaders { get; set; }
public Action<Headers> AddRequestHeaders { get; set; }

/// <summary>
/// Gets or sets the boolean to use effective partition key routing in the cosmos db request.
Expand Down Expand Up @@ -93,16 +88,11 @@ internal virtual void PopulateRequestOptions(RequestMessage request)
this.AddRequestHeaders?.Invoke(request.Headers);
}

#if PREVIEW
/// <summary>
/// Clone RequestOptions.
/// </summary>
/// <returns> cloned RequestOptions. </returns>
public
#else
internal
#endif
RequestOptions ShallowCopy()
public RequestOptions ShallowCopy()
{
return this.MemberwiseClone() as RequestOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ namespace Microsoft.Azure.Cosmos
/// See <see cref="Database"/> for operations to create and enumerate client encryption keys.
/// See https://aka.ms/CosmosClientEncryption for more information on client-side encryption support in Azure Cosmos DB.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
abstract class ClientEncryptionKey
public abstract class ClientEncryptionKey
{
/// <summary>
/// The unique identifier of the client encryption key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Details of an encryption key for use with the Azure Cosmos DB service.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
class ClientEncryptionKeyProperties : IEquatable<ClientEncryptionKeyProperties>
public class ClientEncryptionKeyProperties : IEquatable<ClientEncryptionKeyProperties>
{
/// <summary>
/// Initializes a new instance of <see cref="ClientEncryptionKeyProperties"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Response from the Cosmos DB service for a <see cref="Cosmos.ClientEncryptionKey"/> related request.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
class ClientEncryptionKeyResponse : Response<ClientEncryptionKeyProperties>
public class ClientEncryptionKeyResponse : Response<ClientEncryptionKeyProperties>
{
/// <summary>
/// Creates a client encryption key response as a no-op for mock testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ namespace Microsoft.Azure.Cosmos
/// Metadata that can be used to wrap/unwrap a Data Encryption Key using a Customer Managed Key.
/// See https://aka.ms/CosmosClientEncryption for more information on client-side encryption support in Azure Cosmos DB.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
class EncryptionKeyWrapMetadata : IEquatable<EncryptionKeyWrapMetadata>
public class EncryptionKeyWrapMetadata : IEquatable<EncryptionKeyWrapMetadata>
{
// For JSON deserialize
private EncryptionKeyWrapMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ namespace Microsoft.Azure.Cosmos
/// to the corresponding type response using the
/// CosmosClient serializer
/// </summary>
#if PREVIEW
public
#else
internal
#endif
abstract class CosmosResponseFactory
public abstract class CosmosResponseFactory
{
/// <summary>
/// Creates a FeedResponse from a response message
Expand Down
2 changes: 0 additions & 2 deletions Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,6 @@ public abstract ContainerBuilder DefineContainer(
string name,
string partitionKeyPath);

#if PREVIEW
/// <summary>
/// Returns a reference to a client encryption key object.
/// This method is not meant to be invoked directly. Please see https://aka.ms/CosmosClientEncryption in order to use client-side encryption.
Expand Down Expand Up @@ -1022,6 +1021,5 @@ public abstract Task<ClientEncryptionKeyResponse> CreateClientEncryptionKeyAsync
ClientEncryptionKeyProperties clientEncryptionKeyProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default);
#endif
}
}
27 changes: 6 additions & 21 deletions Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,7 @@ public override ContainerBuilder DefineContainer(
return new ContainerBuilder(this, name, partitionKeyPath);
}

#if PREVIEW
public override
#else
internal virtual
#endif
ClientEncryptionKey GetClientEncryptionKey(string id)
public override ClientEncryptionKey GetClientEncryptionKey(string id)
{
if (string.IsNullOrEmpty(id))
{
Expand All @@ -702,15 +697,10 @@ ClientEncryptionKey GetClientEncryptionKey(string id)
id);
}

#if PREVIEW
public override
#else
internal virtual
#endif
FeedIterator<ClientEncryptionKeyProperties> GetClientEncryptionKeyQueryIterator(
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
public override FeedIterator<ClientEncryptionKeyProperties> GetClientEncryptionKeyQueryIterator(
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
{
if (!(this.GetClientEncryptionKeyQueryStreamIterator(
queryDefinition: queryDefinition,
Expand Down Expand Up @@ -743,12 +733,7 @@ private FeedIterator GetClientEncryptionKeyQueryStreamIterator(
options: requestOptions);
}

#if PREVIEW
public
#else
internal virtual
#endif
async Task<ClientEncryptionKeyResponse> CreateClientEncryptionKeyAsync(
public async Task<ClientEncryptionKeyResponse> CreateClientEncryptionKeyAsync(
ITrace trace,
ClientEncryptionKeyProperties clientEncryptionKeyProperties,
RequestOptions requestOptions = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,38 +305,23 @@ public override Task<UserResponse> UpsertUserAsync(
(trace) => base.UpsertUserAsync(id, requestOptions, trace, cancellationToken));
}

#if PREVIEW
public
#else
internal
#endif
override ClientEncryptionKey GetClientEncryptionKey(string id)
public override ClientEncryptionKey GetClientEncryptionKey(string id)
{
return base.GetClientEncryptionKey(id);
}

#if PREVIEW
public
#else
internal
#endif
override FeedIterator<ClientEncryptionKeyProperties> GetClientEncryptionKeyQueryIterator(
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
public override FeedIterator<ClientEncryptionKeyProperties> GetClientEncryptionKeyQueryIterator(
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
{
return base.GetClientEncryptionKeyQueryIterator(queryDefinition, continuationToken, requestOptions);
}

#if PREVIEW
public override
#else
internal
#endif
Task<ClientEncryptionKeyResponse> CreateClientEncryptionKeyAsync(
ClientEncryptionKeyProperties clientEncryptionKeyProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
public override Task<ClientEncryptionKeyResponse> CreateClientEncryptionKeyAsync(
ClientEncryptionKeyProperties clientEncryptionKeyProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
{
return this.ClientContext.OperationHelperAsync(
nameof(CreateClientEncryptionKeyAsync),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Path that needs encryption and the associated settings within <see cref="ClientEncryptionPolicy"/>.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
sealed class ClientEncryptionIncludedPath
public sealed class ClientEncryptionIncludedPath
{
/// <summary>
/// Gets or sets the path to be encrypted. Must be a top level path, eg. /salary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Client encryption policy.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
sealed class ClientEncryptionPolicy
public sealed class ClientEncryptionPolicy
{
/// <summary>
/// Initializes a new instance of the <see cref="ClientEncryptionPolicy"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public UniqueKeyPolicy UniqueKeyPolicy
public DateTime? LastModified { get; private set; }

/// <summary>
/// Gets the client encryption policy information for storing items in a container from the Azure Cosmos service.
/// Gets or sets the client encryption policy information for storing items in a container from the Azure Cosmos service.
/// </summary>
/// <value>
/// It is an optional property.
Expand All @@ -258,12 +258,7 @@ public UniqueKeyPolicy UniqueKeyPolicy
/// </para>
/// </remarks>
[JsonIgnore]
#if PREVIEW
public
#else
internal
#endif
ClientEncryptionPolicy ClientEncryptionPolicy
public ClientEncryptionPolicy ClientEncryptionPolicy
{
get => this.clientEncryptionPolicyInternal;

Expand Down
Loading