Skip to content

Add qe.py to test Queryable Encryption #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ uv.lock
docs/_build/
config/wagtail/wagtail_settings.py
HELP-72348.json
customer-master-key.txt
10 changes: 9 additions & 1 deletion django_mongodb_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
import os
import sys

from .repo import repo
from .startproject import startproject
Expand All @@ -11,7 +12,14 @@
from .startapp import startapp


@click.group()
def get_help_text():
help_text = """
Django MongoDB CLI
"""
return f"\n\n{help_text.strip()}\n\nSystem executable:\n\n{sys.executable}\n"


@click.group(help=get_help_text())
def cli():
"""Django MongoDB CLI"""

Expand Down
22 changes: 13 additions & 9 deletions django_mongodb_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,25 @@ def repo_clone(repo_entry, url_pattern, branch_pattern, repo):


def repo_install(clone_path):
if clone_path.endswith("mongo-arrow"):
clone_path = os.path.join(clone_path, "bindings", "python")
if os.path.exists(os.path.join(clone_path, "pyproject.toml")):
subprocess.run([sys.executable, "-m", "pip", "install", "-e", clone_path])
elif os.path.exists(os.path.join(clone_path, "setup.py")):
subprocess.run([sys.executable, "setup.py", "develop"], cwd=clone_path)
elif os.path.exists(os.path.join(clone_path, "requirements.txt")):
install_path = clone_path

if clone_path.endswith("mongo-arrow") or clone_path.endswith("libmongocrypt"):
install_path = os.path.join(clone_path, "bindings", "python")
install_path = os.path.join(clone_path, "bindings", "python")

if os.path.exists(os.path.join(install_path, "pyproject.toml")):
subprocess.run([sys.executable, "-m", "pip", "install", "-e", install_path])
elif os.path.exists(os.path.join(install_path, "setup.py")):
subprocess.run([sys.executable, "setup.py", "develop"], cwd=install_path)
elif os.path.exists(os.path.join(install_path, "requirements.txt")):
subprocess.run(
[sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
cwd=clone_path,
cwd=install_path,
)
else:
click.echo(
click.style(
f"No valid installation method found for {clone_path}", fg="red"
f"No valid installation method found for {install_path}", fg="red"
)
)

Expand Down
10 changes: 6 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dev-install:
dm repo install django-mongodb-extensions
dm repo install mongo-python-driver
dm repo install python-xmlsec
dm repo install libmongocrypt


demo:
Expand All @@ -31,6 +32,7 @@ git-clone:
dm repo clone django-mongodb-project
dm repo clone django-mongodb-templates
dm repo clone django-rest-framework
dm repo clone libmongocrypt
dm repo clone mongo-python-driver
dm repo clone python-xmlsec

Expand Down Expand Up @@ -108,7 +110,7 @@ sphinx-clean:
rm -rvf docs/_build
alias sc := sphinx-clean

# ---------------------------------------- test ----------------------------------------
[group('test')]
HELP-72348:
python test/HELP-72348.py
# ---------------------------------------- qe ----------------------------------------
qe:
python qe.py
alias q := qe
37 changes: 37 additions & 0 deletions qe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import code

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

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"
)
)
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(
kms_providers, key_vault_namespace, encrypted_client, codec_options
)
encrypted_database = encrypted_client["test"]
encrypted_fields = {
"fields": [
{
"path": "patientRecord.ssn",
"bsonType": "string",
"queries": [{"queryType": "equality"}],
},
{
"path": "patientRecord.billing",
"bsonType": "object",
},
]
}
encrypted_collection = client_encryption.create_encrypted_collection(
encrypted_database, "encrypted_collection", encrypted_fields
)
code.interact(local=locals())
20 changes: 0 additions & 20 deletions test/HELP-72348/HELP-72348.py

This file was deleted.

Loading