diff --git a/.gitignore b/.gitignore index 5e61a39..df70893 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ uv.lock docs/_build/ config/wagtail/wagtail_settings.py HELP-72348.json +customer-master-key.txt diff --git a/django_mongodb_cli/__init__.py b/django_mongodb_cli/__init__.py index 68198c2..c466a23 100644 --- a/django_mongodb_cli/__init__.py +++ b/django_mongodb_cli/__init__.py @@ -1,5 +1,6 @@ import click import os +import sys from .repo import repo from .startproject import startproject @@ -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""" diff --git a/django_mongodb_cli/utils.py b/django_mongodb_cli/utils.py index a2575b0..c53a7cf 100644 --- a/django_mongodb_cli/utils.py +++ b/django_mongodb_cli/utils.py @@ -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" ) ) diff --git a/justfile b/justfile index 562b722..3ef5944 100644 --- a/justfile +++ b/justfile @@ -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: @@ -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 @@ -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 diff --git a/qe.py b/qe.py new file mode 100644 index 0000000..45103d3 --- /dev/null +++ b/qe.py @@ -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()) diff --git a/test/HELP-72348/HELP-72348.py b/test/HELP-72348/HELP-72348.py deleted file mode 100644 index eb9d59f..0000000 --- a/test/HELP-72348/HELP-72348.py +++ /dev/null @@ -1,20 +0,0 @@ -import json -import time -from bson import encode, decode - -# Number of repetitions -x = 1 - -# Load JSON from a file -with open("HELP-72348.json") as f: - data = json.load(f) - -start = time.perf_counter() -for _ in range(x): - print(f"Running iteration {_ + 1} of {x}...") - bson_data = encode(data) - decoded_data = decode(bson_data) - -end = time.perf_counter() - -print(f"Time taken for {x} iterations: {end - start:.2f} seconds") diff --git a/test/HELP-72348/memray-flamegraph-HELP-72348.py.4949.html b/test/HELP-72348/memray-flamegraph-HELP-72348.py.4949.html deleted file mode 100644 index 3261ec6..0000000 --- a/test/HELP-72348/memray-flamegraph-HELP-72348.py.4949.html +++ /dev/null @@ -1,375 +0,0 @@ - - - - - - - memray - flamegraph report - - - - - - - - -
-
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - diff --git a/test/HELP-72348/memray-flamegraph-HELP-72348.py.5279.html b/test/HELP-72348/memray-flamegraph-HELP-72348.py.5279.html deleted file mode 100644 index 6908308..0000000 --- a/test/HELP-72348/memray-flamegraph-HELP-72348.py.5279.html +++ /dev/null @@ -1,375 +0,0 @@ - - - - - - - memray - flamegraph report - - - - - - - - -
-
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - -