88from pymongo .encryption import AutoEncryptionOpts , ClientEncryption
99
1010
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 ):
1223 """
1324 Returns a `ClientEncryption` instance for MongoDB Client-Side Field Level
1425 Encryption (CSFLE) that can be used to create an encrypted collection.
1526 """
1627
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 ()
1930 codec_options = CodecOptions (uuid_representation = STANDARD )
2031 return ClientEncryption (kms_providers , key_vault_namespace , encrypted_connection , codec_options )
2132
2233
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+
2340def get_auto_encryption_opts (crypt_shared_lib_path = None , kms_providers = None ):
2441 """
2542 Returns an `AutoEncryptionOpts` instance for MongoDB Client-Side Field
2643 Level Encryption (CSFLE) that can be used to create an encrypted connection.
2744 """
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 ()
3146 return AutoEncryptionOpts (
3247 key_vault_namespace = key_vault_namespace ,
3348 kms_providers = kms_providers ,
@@ -53,14 +68,3 @@ def get_customer_master_key():
5368 "404142434445464748494a4b4c4d4e4f"
5469 "505152535455565758595a5b5c5d5e5f"
5570 )
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