Skip to content

Commit 3646c9f

Browse files
authored
Merge pull request #28 from aclark4life/main
Add qe.py to test Queryable Encryption
2 parents 132f5ad + 9eea133 commit 3646c9f

File tree

8 files changed

+66
-784
lines changed

8 files changed

+66
-784
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ uv.lock
3232
docs/_build/
3333
config/wagtail/wagtail_settings.py
3434
HELP-72348.json
35+
customer-master-key.txt

django_mongodb_cli/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import click
22
import os
3+
import sys
34

45
from .repo import repo
56
from .startproject import startproject
@@ -11,7 +12,14 @@
1112
from .startapp import startapp
1213

1314

14-
@click.group()
15+
def get_help_text():
16+
help_text = """
17+
Django MongoDB CLI
18+
"""
19+
return f"\n\n{help_text.strip()}\n\nSystem executable:\n\n{sys.executable}\n"
20+
21+
22+
@click.group(help=get_help_text())
1523
def cli():
1624
"""Django MongoDB CLI"""
1725

django_mongodb_cli/utils.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,25 @@ def repo_clone(repo_entry, url_pattern, branch_pattern, repo):
137137

138138

139139
def repo_install(clone_path):
140-
if clone_path.endswith("mongo-arrow"):
141-
clone_path = os.path.join(clone_path, "bindings", "python")
142-
if os.path.exists(os.path.join(clone_path, "pyproject.toml")):
143-
subprocess.run([sys.executable, "-m", "pip", "install", "-e", clone_path])
144-
elif os.path.exists(os.path.join(clone_path, "setup.py")):
145-
subprocess.run([sys.executable, "setup.py", "develop"], cwd=clone_path)
146-
elif os.path.exists(os.path.join(clone_path, "requirements.txt")):
140+
install_path = clone_path
141+
142+
if clone_path.endswith("mongo-arrow") or clone_path.endswith("libmongocrypt"):
143+
install_path = os.path.join(clone_path, "bindings", "python")
144+
install_path = os.path.join(clone_path, "bindings", "python")
145+
146+
if os.path.exists(os.path.join(install_path, "pyproject.toml")):
147+
subprocess.run([sys.executable, "-m", "pip", "install", "-e", install_path])
148+
elif os.path.exists(os.path.join(install_path, "setup.py")):
149+
subprocess.run([sys.executable, "setup.py", "develop"], cwd=install_path)
150+
elif os.path.exists(os.path.join(install_path, "requirements.txt")):
147151
subprocess.run(
148152
[sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
149-
cwd=clone_path,
153+
cwd=install_path,
150154
)
151155
else:
152156
click.echo(
153157
click.style(
154-
f"No valid installation method found for {clone_path}", fg="red"
158+
f"No valid installation method found for {install_path}", fg="red"
155159
)
156160
)
157161

justfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dev-install:
1010
dm repo install django-mongodb-extensions
1111
dm repo install mongo-python-driver
1212
dm repo install python-xmlsec
13+
dm repo install libmongocrypt
1314

1415

1516
demo:
@@ -31,6 +32,7 @@ git-clone:
3132
dm repo clone django-mongodb-project
3233
dm repo clone django-mongodb-templates
3334
dm repo clone django-rest-framework
35+
dm repo clone libmongocrypt
3436
dm repo clone mongo-python-driver
3537
dm repo clone python-xmlsec
3638

@@ -108,7 +110,7 @@ sphinx-clean:
108110
rm -rvf docs/_build
109111
alias sc := sphinx-clean
110112

111-
# ---------------------------------------- test ----------------------------------------
112-
[group('test')]
113-
HELP-72348:
114-
python test/HELP-72348.py
113+
# ---------------------------------------- qe ----------------------------------------
114+
qe:
115+
python qe.py
116+
alias q := qe

qe.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import code
2+
3+
from bson.binary import STANDARD
4+
from bson.codec_options import CodecOptions
5+
from pymongo import MongoClient
6+
from pymongo.encryption import ClientEncryption
7+
from django_mongodb_backend.utils import get_auto_encryption_options
8+
9+
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"
12+
)
13+
)
14+
kms_providers = encrypted_client.options.auto_encryption_opts._kms_providers
15+
key_vault_namespace = encrypted_client.options.auto_encryption_opts._key_vault_namespace
16+
codec_options = CodecOptions(uuid_representation=STANDARD)
17+
client_encryption = ClientEncryption(
18+
kms_providers, key_vault_namespace, encrypted_client, codec_options
19+
)
20+
encrypted_database = encrypted_client["test"]
21+
encrypted_fields = {
22+
"fields": [
23+
{
24+
"path": "patientRecord.ssn",
25+
"bsonType": "string",
26+
"queries": [{"queryType": "equality"}],
27+
},
28+
{
29+
"path": "patientRecord.billing",
30+
"bsonType": "object",
31+
},
32+
]
33+
}
34+
encrypted_collection = client_encryption.create_encrypted_collection(
35+
encrypted_database, "encrypted_collection", encrypted_fields
36+
)
37+
code.interact(local=locals())

test/HELP-72348/HELP-72348.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)