|
1 | 1 | import code |
| 2 | +import os |
2 | 3 |
|
3 | 4 | from bson.binary import STANDARD |
4 | 5 | from bson.codec_options import CodecOptions |
5 | 6 | from pymongo import MongoClient |
6 | 7 | from pymongo.encryption import ClientEncryption |
7 | | -from django_mongodb_backend.utils import get_auto_encryption_options |
| 8 | +from django_mongodb_backend.utils import ( |
| 9 | + get_auto_encryption_opts, |
| 10 | + get_customer_master_key, |
| 11 | +) |
| 12 | + |
| 13 | +HOME = os.environ.get("HOME") |
| 14 | + |
| 15 | +kms_providers = { |
| 16 | + "local": { |
| 17 | + "key": get_customer_master_key(), |
| 18 | + }, |
| 19 | +} |
8 | 20 |
|
9 | 21 | encrypted_client = MongoClient( |
10 | | - auto_encryption_opts=get_auto_encryption_options( |
11 | | - crypt_shared_lib_path="/Users/alexclark/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib" |
| 22 | + auto_encryption_opts=get_auto_encryption_opts( |
| 23 | + crypt_shared_lib_path=f"{HOME}/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib", |
| 24 | + kms_providers=kms_providers, |
12 | 25 | ) |
13 | 26 | ) |
14 | | -kms_providers = encrypted_client.options.auto_encryption_opts._kms_providers |
| 27 | + |
15 | 28 | key_vault_namespace = encrypted_client.options.auto_encryption_opts._key_vault_namespace |
16 | 29 | codec_options = CodecOptions(uuid_representation=STANDARD) |
17 | 30 | client_encryption = ClientEncryption( |
|
32 | 45 | ] |
33 | 46 | } |
34 | 47 | encrypted_collection = client_encryption.create_encrypted_collection( |
35 | | - encrypted_database, "encrypted_collection", encrypted_fields |
| 48 | + encrypted_database, "encrypted_collection", encrypted_fields, "local" |
36 | 49 | ) |
37 | 50 | code.interact(local=locals()) |
0 commit comments