Skip to content

Commit 70d9b70

Browse files
authored
Merge pull request #33 from aclark4life/main
Update django test settings + misc
2 parents c27087e + d209450 commit 70d9b70

File tree

3 files changed

+65
-18
lines changed

3 files changed

+65
-18
lines changed

django_mongodb_cli/repo.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,45 @@ def clone(repo, context, repo_names, all_repos, install):
118118
click.echo(context.get_help())
119119

120120

121+
@repo.command()
122+
@click.argument("repo_names", nargs=-1)
123+
@click.option("-a", "--all-repos", is_flag=True, help="Install all repositories")
124+
@click.pass_context
125+
@pass_repo
126+
def install(repo, context, repo_names, all_repos):
127+
"""Install repositories (like 'clone -i')."""
128+
repos, url_pattern, _ = get_repos("pyproject.toml")
129+
repo_name_map = get_repo_name_map(repos, url_pattern)
130+
131+
if all_repos and repo_names:
132+
click.echo("Cannot specify both repo names and --all-repos")
133+
return
134+
135+
# If -a/--all-repos is given
136+
if all_repos:
137+
click.echo(f"Updating {len(repo_name_map)} repositories...")
138+
for repo_name, repo_url in repo_name_map.items():
139+
clone_path = os.path.join(context.obj.home, repo_name)
140+
if os.path.exists(clone_path):
141+
install_package(clone_path)
142+
return
143+
144+
# If specific repo names are given
145+
if repo_names:
146+
not_found = []
147+
for repo_name in repo_names:
148+
clone_path = os.path.join(context.obj.home, repo_name)
149+
if os.path.exists(clone_path):
150+
install_package(clone_path)
151+
else:
152+
not_found.append(repo_name)
153+
for name in not_found:
154+
click.echo(f"Repository '{name}' not found.")
155+
return
156+
157+
click.echo(context.get_help())
158+
159+
121160
@repo.command(context_settings={"ignore_unknown_options": True})
122161
@click.argument("repo_name", required=False)
123162
@click.argument("args", nargs=-1)

qe.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import code
2-
import os
32

43
from bson.binary import STANDARD
54
from bson.codec_options import CodecOptions
@@ -8,25 +7,20 @@
87
from pymongo.errors import EncryptedCollectionError
98
from django_mongodb_backend.encryption import (
109
get_auto_encryption_opts,
11-
get_customer_master_key,
10+
get_kms_providers,
11+
get_key_vault_namespace,
1212
)
1313

14-
HOME = os.environ.get("HOME")
15-
16-
kms_providers = {
17-
"local": {
18-
"key": get_customer_master_key(),
19-
},
20-
}
14+
kms_providers = get_kms_providers()
15+
key_vault_namespace = get_key_vault_namespace()
2116

2217
client = MongoClient(
2318
auto_encryption_opts=get_auto_encryption_opts(
24-
crypt_shared_lib_path=f"{HOME}/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib",
19+
key_vault_namespace=key_vault_namespace,
2520
kms_providers=kms_providers,
2621
)
2722
)
2823

29-
key_vault_namespace = client.options.auto_encryption_opts._key_vault_namespace
3024
codec_options = CodecOptions(uuid_representation=STANDARD)
3125
client_encryption = ClientEncryption(
3226
kms_providers, key_vault_namespace, client, codec_options

test/settings/django.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,40 @@
22

33
from django_mongodb_backend import encryption, parse_uri
44

5-
kms_providers = encryption.get_kms_providers()
6-
7-
auto_encryption_opts = encryption.get_auto_encryption_opts(
8-
kms_providers=kms_providers,
5+
# Queryable Encryption settings
6+
KEY_VAULT_NAMESPACE = encryption.get_key_vault_namespace()
7+
KMS_PROVIDERS = encryption.get_kms_providers()
8+
KMS_PROVIDER = encryption.KMS_PROVIDER
9+
AUTO_ENCRYPTION_OPTS = encryption.get_auto_encryption_opts(
10+
key_vault_namespace=KEY_VAULT_NAMESPACE,
11+
kms_providers=KMS_PROVIDERS,
912
)
1013

1114
DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017")
1215
DATABASES = {
1316
"default": parse_uri(
1417
DATABASE_URL,
15-
db_name="djangotests",
18+
db_name="test",
1619
),
1720
"encrypted": parse_uri(
1821
DATABASE_URL,
19-
options={"auto_encryption_opts": auto_encryption_opts},
20-
db_name="encrypted_djangotests",
22+
options={"auto_encryption_opts": AUTO_ENCRYPTION_OPTS},
23+
db_name="encrypted",
2124
),
2225
}
2326

2427
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
2528
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
2629
SECRET_KEY = "django_tests_secret_key"
2730
USE_TZ = False
31+
32+
33+
class TestRouter:
34+
def allow_migrate(self, db, app_label, model_name=None, **hints):
35+
if db == "encrypted":
36+
if app_label != "encryption_":
37+
return False
38+
return None
39+
40+
41+
DATABASE_ROUTERS = [TestRouter()]

0 commit comments

Comments
 (0)