@@ -40,12 +40,11 @@ content: |
40
40
:tabid: python
41
41
42
42
.. code-block:: python
43
- :emphasize-lines: 4
44
-
45
- from bson import binary
43
+ :emphasize-lines: 3
46
44
47
45
path = "./master-key.txt"
48
- local_master_key = binary.Binary(open(path, "rb").read(96))
46
+ with open(path, "rb") as f:
47
+ local_master_key = f.read()
49
48
50
49
---
51
50
title : Specify KMS Provider Settings
@@ -94,9 +93,9 @@ content: |
94
93
:emphasize-lines: 2,3
95
94
96
95
kms_providers = {
97
- "local": {
98
- "key": local_master_key # local_master_key variable from the previous step
99
- },
96
+ "local": {
97
+ "key": local_master_key # local_master_key variable from the previous step
98
+ },
100
99
}
101
100
102
101
---
@@ -183,7 +182,7 @@ content: |
183
182
:tabid: python
184
183
185
184
.. code-block:: python
186
- :emphasize-lines: 13,14,20,30
185
+ :emphasize-lines: 13,21
187
186
188
187
from pymongo import MongoClient
189
188
from pymongo.encryption_options import AutoEncryptionOpts
@@ -195,14 +194,7 @@ content: |
195
194
connection_string = "mongodb://localhost:27017"
196
195
key_vault_namespace = "encryption.__keyVault"
197
196
198
- fle_opts = AutoEncryptionOpts(
199
- kms_providers, # pass in the kms_providers variable from the previous step
200
- key_vault_namespace
201
- )
202
- client = MongoClient(
203
- connection_string,
204
- auto_encryption_opts=fle_opts
205
- )
197
+ client = MongoClient(connection_string)
206
198
client_encryption = ClientEncryption(
207
199
kms_providers, # pass in the kms_providers variable from the previous step
208
200
key_vault_namespace,
@@ -212,16 +204,15 @@ content: |
212
204
213
205
214
206
def create_data_encryption_key():
215
-
216
- data_key = client_encryption.create_data_key("local")
217
- uuid_data_key_id = UUID(bytes=data_key)
218
- base_64_data_key_id = base64.b64encode(data_key)
207
+ data_key_id = client_encryption.create_data_key("local")
208
+ uuid_data_key_id = UUID(bytes=data_key_id)
209
+ base_64_data_key_id = base64.b64encode(data_key_id)
219
210
print("DataKeyId [UUID]: ", str(uuid_data_key_id))
220
211
print("DataKeyId [base64]: ", base_64_data_key_id)
221
- return data_key
212
+ return data_key_id
222
213
223
214
224
- data_key = create_data_encryption_key()
215
+ data_key_id = create_data_encryption_key()
225
216
226
217
227
218
The ``_id`` field of the data encryption key is represented as a **UUID**
@@ -361,19 +352,19 @@ content: |
361
352
:tabid: python
362
353
363
354
.. code-block:: python
355
+ :emphasize-lines: 9,10
364
356
365
357
from pprint import pprint
366
358
connection_string = "mongodb://localhost:27017"
367
- key_vault_namespace = "encryption.__keyVault"
368
-
369
- def verify_data_key_created(data_key, client, client_encryption, fle_opts):
370
- db = client["encryption"]
371
- collection = db["__keyVault"]
372
- key = collection.find_one({"_id": data_key})
373
- pprint(key)
374
-
375
- # pass in fle_opts, client, client_encryption, data_key variables created in previous section
376
- verify_data_key_created(data_key, client, client_encryption, fle_opts)
359
+ key_vault_db = "encryption"
360
+ key_vault_coll = "__keyVault"
361
+
362
+ client = MongoClient(connection_string)
363
+ key_vault = client[key_vault_db][key_vault_coll]
364
+
365
+ # Pass in the data_key_id created in previous section
366
+ key = key_vault.find_one({"_id": data_key_id})
367
+ pprint(key)
377
368
378
369
379
370
This code example should print a retrieved document that resembles the
0 commit comments