diff --git a/.gitignore b/.gitignore index df70893..075ae0b 100644 --- a/.gitignore +++ b/.gitignore @@ -31,5 +31,4 @@ search/ uv.lock docs/_build/ config/wagtail/wagtail_settings.py -HELP-72348.json customer-master-key.txt diff --git a/qe.py b/qe.py index 45103d3..6933c15 100644 --- a/qe.py +++ b/qe.py @@ -1,17 +1,30 @@ import code +import os from bson.binary import STANDARD from bson.codec_options import CodecOptions from pymongo import MongoClient from pymongo.encryption import ClientEncryption -from django_mongodb_backend.utils import get_auto_encryption_options +from django_mongodb_backend.utils import ( + get_auto_encryption_opts, + get_customer_master_key, +) + +HOME = os.environ.get("HOME") + +kms_providers = { + "local": { + "key": get_customer_master_key(), + }, +} encrypted_client = MongoClient( - auto_encryption_opts=get_auto_encryption_options( - crypt_shared_lib_path="/Users/alexclark/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib" + auto_encryption_opts=get_auto_encryption_opts( + crypt_shared_lib_path=f"{HOME}/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib", + kms_providers=kms_providers, ) ) -kms_providers = encrypted_client.options.auto_encryption_opts._kms_providers + key_vault_namespace = encrypted_client.options.auto_encryption_opts._key_vault_namespace codec_options = CodecOptions(uuid_representation=STANDARD) client_encryption = ClientEncryption( @@ -32,6 +45,6 @@ ] } encrypted_collection = client_encryption.create_encrypted_collection( - encrypted_database, "encrypted_collection", encrypted_fields + encrypted_database, "encrypted_collection", encrypted_fields, "local" ) code.interact(local=locals())