8
8
from pymongo .encryption import AutoEncryptionOpts , ClientEncryption
9
9
10
10
11
- def get_client_encryption (auto_encryption_opts , encrypted_connection ):
11
+ def get_kms_providers ():
12
+ """
13
+ Return supported KMS providers for MongoDB Client-Side Field Level Encryption (CSFLE).
14
+ """
15
+ return {
16
+ "local" : {
17
+ "key" : get_customer_master_key (),
18
+ },
19
+ }
20
+
21
+
22
+ def get_client_encryption (encrypted_connection ):
12
23
"""
13
24
Returns a `ClientEncryption` instance for MongoDB Client-Side Field Level
14
25
Encryption (CSFLE) that can be used to create an encrypted collection.
15
26
"""
16
27
17
- key_vault_namespace = auto_encryption_opts . _key_vault_namespace
18
- kms_providers = auto_encryption_opts . _kms_providers
28
+ key_vault_namespace = get_key_vault_namespace ()
29
+ kms_providers = get_kms_providers ()
19
30
codec_options = CodecOptions (uuid_representation = STANDARD )
20
31
return ClientEncryption (kms_providers , key_vault_namespace , encrypted_connection , codec_options )
21
32
22
33
34
+ def get_key_vault_namespace ():
35
+ key_vault_database_name = "encryption"
36
+ key_vault_collection_name = "__keyVault"
37
+ return f"{ key_vault_database_name } .{ key_vault_collection_name } "
38
+
39
+
23
40
def get_auto_encryption_opts (crypt_shared_lib_path = None , kms_providers = None ):
24
41
"""
25
42
Returns an `AutoEncryptionOpts` instance for MongoDB Client-Side Field
26
43
Level Encryption (CSFLE) that can be used to create an encrypted connection.
27
44
"""
28
- key_vault_database_name = "encryption"
29
- key_vault_collection_name = "__keyVault"
30
- key_vault_namespace = f"{ key_vault_database_name } .{ key_vault_collection_name } "
45
+ key_vault_namespace = get_key_vault_namespace ()
31
46
return AutoEncryptionOpts (
32
47
key_vault_namespace = key_vault_namespace ,
33
48
kms_providers = kms_providers ,
@@ -53,14 +68,3 @@ def get_customer_master_key():
53
68
"404142434445464748494a4b4c4d4e4f"
54
69
"505152535455565758595a5b5c5d5e5f"
55
70
)
56
-
57
-
58
- def get_kms_providers ():
59
- """
60
- Return supported KMS providers for MongoDB Client-Side Field Level Encryption (CSFLE).
61
- """
62
- return {
63
- "local" : {
64
- "key" : get_customer_master_key (),
65
- },
66
- }
0 commit comments