-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client Encryption : Adds integration with Cosmos SDK 3.15.0-preview (#…
…1956) * Integrate with latest Cosmos SDK 3.15.0-preview * Use customer serializer
- Loading branch information
1 parent
4fcdd95
commit 7610323
Showing
17 changed files
with
1,072 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Encryption.Tests" + Microsoft.Azure.Cosmos.Encryption.AssemblyKeys.TestPublicKey)] | ||
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Encryption.EmulatorTests" + Microsoft.Azure.Cosmos.Encryption.AssemblyKeys.TestPublicKey)] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Microsoft.Azure.Cosmos.Encryption/src/EncryptionTransactionalBatchOperationResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Encryption | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
|
||
internal sealed class EncryptionTransactionalBatchOperationResult : TransactionalBatchOperationResult | ||
{ | ||
private readonly Stream encryptionResourceStream; | ||
private readonly TransactionalBatchOperationResult response; | ||
|
||
public EncryptionTransactionalBatchOperationResult(TransactionalBatchOperationResult response, Stream encryptionResourceStream) | ||
{ | ||
this.response = response; | ||
this.encryptionResourceStream = encryptionResourceStream; | ||
} | ||
|
||
public override Stream ResourceStream => this.encryptionResourceStream; | ||
|
||
public override HttpStatusCode StatusCode => this.response.StatusCode; | ||
|
||
public override bool IsSuccessStatusCode => this.response.IsSuccessStatusCode; | ||
|
||
public override string ETag => this.response.ETag; | ||
|
||
public override TimeSpan RetryAfter => this.response.RetryAfter; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Microsoft.Azure.Cosmos.Encryption/src/EncryptionTransactionalBatchOperationResult{T}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Encryption | ||
{ | ||
internal sealed class EncryptionTransactionalBatchOperationResult<T> : TransactionalBatchOperationResult<T> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TransactionalBatchOperationResult{T}"/> class. | ||
/// </summary> | ||
/// <param name="result">BatchOperationResult with stream resource.</param> | ||
/// <param name="resource">Deserialized resource.</param> | ||
internal EncryptionTransactionalBatchOperationResult(T resource) | ||
{ | ||
this.Resource = resource; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the content of the resource. | ||
/// </summary> | ||
public override T Resource { get; set; } | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
Microsoft.Azure.Cosmos.Encryption/src/EncryptionTransactionalBatchResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Encryption | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
internal sealed class EncryptionTransactionalBatchResponse : TransactionalBatchResponse | ||
{ | ||
private readonly IReadOnlyList<TransactionalBatchOperationResult> results; | ||
private readonly TransactionalBatchResponse response; | ||
private readonly CosmosSerializer cosmosSerializer; | ||
private bool isDisposed = false; | ||
|
||
public EncryptionTransactionalBatchResponse( | ||
IReadOnlyList<TransactionalBatchOperationResult> results, | ||
TransactionalBatchResponse response, | ||
CosmosSerializer cosmosSerializer) | ||
{ | ||
this.results = results; | ||
this.response = response; | ||
this.cosmosSerializer = cosmosSerializer; | ||
} | ||
|
||
public override TransactionalBatchOperationResult this[int index] => this.results[index]; | ||
|
||
public override TransactionalBatchOperationResult<T> GetOperationResultAtIndex<T>(int index) | ||
{ | ||
TransactionalBatchOperationResult result = this.results[index]; | ||
|
||
T resource = default; | ||
if (result.ResourceStream != null) | ||
{ | ||
resource = this.cosmosSerializer.FromStream<T>(result.ResourceStream); | ||
} | ||
|
||
return new EncryptionTransactionalBatchOperationResult<T>(resource); | ||
} | ||
|
||
public override IEnumerator<TransactionalBatchOperationResult> GetEnumerator() | ||
{ | ||
return this.results.GetEnumerator(); | ||
} | ||
|
||
public override Headers Headers => this.response.Headers; | ||
|
||
public override string ActivityId => this.response.ActivityId; | ||
|
||
public override double RequestCharge => this.response.RequestCharge; | ||
|
||
public override TimeSpan? RetryAfter => this.response.RetryAfter; | ||
|
||
public override HttpStatusCode StatusCode => this.response.StatusCode; | ||
|
||
public override string ErrorMessage => this.response.ErrorMessage; | ||
|
||
public override bool IsSuccessStatusCode => this.response.IsSuccessStatusCode; | ||
|
||
public override int Count => this.results?.Count ?? 0; | ||
|
||
public override CosmosDiagnostics Diagnostics => this.response.Diagnostics; | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing && !this.isDisposed) | ||
{ | ||
this.isDisposed = true; | ||
|
||
if (this.response != null) | ||
{ | ||
this.response.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
Microsoft.Azure.Cosmos.Encryption/src/Mirrored/AssemblyKeys.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Encryption | ||
{ | ||
internal static class AssemblyKeys | ||
{ | ||
/// <summary>TestPublicKey is an unsupported strong key for testing and internal use only</summary> | ||
internal const string TestPublicKey = ", PublicKey=0024000004800000940000000602000000240000525341310004000001000100197c25d0a04f73cb271e8181dba1c0c713df8deebb25864541a66670500f34896d280484b45fe1ff6c29f2ee7aa175d8bcbd0c83cc23901a894a86996030f6292ce6eda6e6f3e6c74b3c5a3ded4903c951e6747e6102969503360f7781bf8bf015058eb89b7621798ccc85aaca036ff1bc1556bb7f62de15908484886aa8bbae"; | ||
} | ||
} |
Oops, something went wrong.