Skip to content

Commit b2a7f32

Browse files
committed
Code review fixes (3/x)
Don't break the build!
1 parent 9a388bd commit b2a7f32

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
3+
from mongodb_settings import * # noqa: F403
4+
from pymongo.encryption import AutoEncryptionOpts
5+
6+
DATABASES["encrypted"] = { # noqa: F405
7+
"ENGINE": "django_mongodb_backend",
8+
"NAME": "djangotests-encrypted",
9+
"OPTIONS": {
10+
"auto_encryption_opts": AutoEncryptionOpts(
11+
key_vault_namespace="my_encrypted_database.keyvault",
12+
kms_providers={"local": {"key": os.urandom(96)}},
13+
),
14+
"directConnection": True,
15+
},
16+
"KMS_CREDENTIALS": {},
17+
}
18+
19+
20+
class EncryptedRouter:
21+
def allow_migrate(self, db, app_label, model_name=None, **hints):
22+
# The encryption_ app's models are only created in the encrypted database.
23+
if app_label == "encryption_":
24+
return db == "encrypted"
25+
# Don't create other app's models in the encrypted database.
26+
if db == "encrypted":
27+
return False
28+
return None
29+
30+
def kms_provider(self, model, **hints):
31+
return "local"
32+
33+
34+
DATABASE_ROUTERS = [EncryptedRouter()]

.github/workflows/mongodb_settings.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
22

3-
from pymongo.encryption_options import AutoEncryptionOpts
4-
53
from django_mongodb_backend import parse_uri
64

75
if mongodb_uri := os.getenv("MONGODB_URI"):
@@ -29,35 +27,7 @@
2927
},
3028
}
3129

32-
DATABASES["encrypted"] = {
33-
"ENGINE": "django_mongodb_backend",
34-
"NAME": "djangotests-encrypted",
35-
"OPTIONS": {
36-
"auto_encryption_opts": AutoEncryptionOpts(
37-
key_vault_namespace="my_encrypted_database.keyvault",
38-
kms_providers={"local": {"key": os.urandom(96)}},
39-
),
40-
"directConnection": True,
41-
},
42-
"KMS_CREDENTIALS": {},
43-
}
44-
45-
46-
class EncryptedRouter:
47-
def allow_migrate(self, db, app_label, model_name=None, **hints):
48-
# The encryption_ app's models are only created in the encrypted database.
49-
if app_label == "encryption_":
50-
return db == "encrypted"
51-
# Don't create other app's models in the encrypted database.
52-
if db == "encrypted":
53-
return False
54-
return None
55-
56-
def kms_provider(self, model, **hints):
57-
return "local"
58-
5930

60-
DATABASE_ROUTERS = [EncryptedRouter()]
6131
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
6232
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
6333
SECRET_KEY = "django_tests_secret_key"

0 commit comments

Comments
 (0)