Skip to content

Commit 11c0f31

Browse files
authored
Merge pull request #695 from terakilobyte/DOCSP-13041
GCP dotnet info
2 parents 0c62a42 + 336656f commit 11c0f31

File tree

2 files changed

+70
-30
lines changed

2 files changed

+70
-30
lines changed

source/includes/steps-fle-convert-to-a-remote-master-key-azure.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ content: |
110110
111111
.. note::
112112
113-
The Node.js driver does not currently support for Azure KMS.
113+
The Node.js driver does not currently support Azure KMS.
114114
115115
.. tab::
116116
:tabid: python
@@ -225,8 +225,7 @@ content: |
225225
226226
.. note::
227227
228-
Node does not currently support Azure as a remote KMS.
229-
228+
The Node.js driver does not currently support Azure KMS.
230229
231230
.. tab::
232231
:tabid: python

source/includes/steps-fle-convert-to-a-remote-master-key-gcp.yaml

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,9 @@ content: |
109109
.. tab::
110110
:tabid: nodejs
111111
112-
.. code-block:: javascript
113-
114-
// TODO: check correctness
115-
kmsProviders = {
116-
gcp: {
117-
email: '<GCP service account email>',
118-
privateKey: '<GCP service account private key>',
119-
endpoint: '<GCP authentication endpoint>',
120-
}
121-
}
112+
.. note::
113+
114+
The Node.js driver does not currently support GCP KMS.
122115
123116
.. tab::
124117
:tabid: python
@@ -132,6 +125,28 @@ content: |
132125
"endpoint": "<GCP authentication endpoint>",
133126
}
134127
}
128+
129+
.. tab::
130+
:tabid: csharp
131+
132+
.. code-block:: csharp
133+
134+
var kmsProviders = new Dictionary<string, IReadOnlyDictionary<string, object>>();
135+
136+
var gcpPrivateKey = Environment.GetEnvironmentVariable("FLE_GCP_PRIVATE_KEY");
137+
var gcpEmail = Environment.GetEnvironmentVariable("FLE_GCP_EMAIL");
138+
var gcpEndpoint = Environment.GetEnvironmentVariable("FLE_GCP_IDENTITY_ENDPOINT"); // Optional, defaults to "oauth2.googleapis.com".
139+
var gcpKmsOptions = new Dictionary<string, object>
140+
{
141+
{ "privateKey", gcpPrivateKey },
142+
{ "email", gcpEmail },
143+
};
144+
if (gcpEndpoint != null)
145+
{
146+
gcpKmsOptions.Add("endpoint", gcpEndpoint);
147+
}
148+
kmsProviders.Add("gcp", gcpKmsOptions);
149+
135150
---
136151
title: Create a New Data Encryption Key
137152
ref: create-a-new-data-key-gcp
@@ -205,23 +220,10 @@ content: |
205220
.. tab::
206221
:tabid: nodejs
207222
208-
.. code-block:: javascript
209-
210-
// TODO: check correctness
211-
const key = await encryption.createDataKey('gcp', {
212-
masterKey: {
213-
provider: 'gcp',
214-
projectId: '<GCP project identifier>',
215-
location: '<GCP region>',
216-
keyRing: '<GCP key ring name>',
217-
keyName: '<GCP key name>',
218-
keyVersion: '<GCP key version>',
219-
endpoint: '<GCP KMS API endpoint>',
220-
}
221-
});
222-
223-
const base64DataKeyId = key.toString('base64');
224-
console.log('DataKeyId [base64]: ', base64DataKeyId);
223+
.. note::
224+
225+
The Node.js driver does not currently support GCP KMS.
226+
225227
.. tab::
226228
:tabid: python
227229
@@ -245,6 +247,45 @@ content: |
245247
To use Google Cloud KMS, you must use `pymongocrypt <https://pypi.org/project/pymongocrypt/>`__
246248
version 1.1 or later in your application's environment.
247249
250+
.. tab::
251+
:tabid: csharp
252+
253+
.. code-block:: csharp
254+
255+
// _connectionString is defined elsewhere as "mongodb://localhost:27017"
256+
257+
var keyVaultClient = new MongoClient(_connectionString);
258+
var clientEncryptionOptions = new ClientEncryptionOptions(
259+
keyVaultClient: keyVaultClient,
260+
keyVaultNamespace: _keyVaultNamespace,
261+
kmsProviders: kmsProviders);
262+
263+
var clientEncryption = new ClientEncryption(clientEncryptionOptions);
264+
265+
266+
var gcpDataKeyProjectId = Environment.GetEnvironmentVariable("FLE_GCP_PROJ_ID");
267+
var gcpDataKeyLocation = Environment.GetEnvironmentVariable("FLE_GCP_KEY_LOC"); // Optional. e.g. "global"
268+
var gcpDataKeyKeyRing = Environment.GetEnvironmentVariable("FLE_GCP_KEY_RING");
269+
var gcpDataKeyKeyName = Environment.GetEnvironmentVariable("FLE_GCP_KEY_NAME");
270+
var gcpDataKeyKeyVersion = Environment.GetEnvironmentVariable("FLE_GCP_KEY_VERSION"); // Optional
271+
var gcpDataKeyEndpoint = Environment.GetEnvironmentVariable("FLE_GCP_KMS_ENDPOINT"); // Optional, KMS URL, defaults to https://www.googleapis.com/auth/cloudkms
272+
273+
var dataKeyOptions = new DataKeyOptions(
274+
masterKey: new BsonDocument
275+
{
276+
{ "projectId", gcpDataKeyProjectId },
277+
{ "location", gcpDataKeyLocation } ,
278+
{ "keyRing", gcpDataKeyKeyRing },
279+
{ "keyName", gcpDataKeyKeyName },
280+
{ "keyVersion", () => gcpDataKeyKeyVersion, gcpDataKeyKeyVersion != null },
281+
{ "endpoint", () => gcpDataKeyEndpoint, gcpDataKeyEndpoint != null }
282+
});
283+
284+
var dataKeyId = clientEncryption.CreateDataKey("gcp", dataKeyOptions, CancellationToken.None);
285+
Console.WriteLine($"DataKeyId [UUID]: {dataKeyId}");
286+
var dataKeyIdBase64 = Convert.ToBase64String(GuidConverter.ToBytes(dataKeyId, GuidRepresentation.Standard));
287+
Console.WriteLine($"DataKeyId [base64]: {dataKeyIdBase64}");
288+
248289
---
249290
title: Update the Automatic Encryption JSON Schema
250291
ref: update-the-json-schema-gcp

0 commit comments

Comments
 (0)