Skip to content

Commit eea4b10

Browse files
committed
Remove helpers
1 parent 293656a commit eea4b10

File tree

2 files changed

+2
-110
lines changed

2 files changed

+2
-110
lines changed

django_mongodb_backend/encryption.py

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,4 @@
1-
# Queryable Encryption helper classes and settings
2-
3-
import os
4-
5-
from .fields import has_encrypted_fields
6-
7-
KMS_CREDENTIALS = {
8-
"aws": {
9-
"key": os.getenv("AWS_KEY_ARN", ""),
10-
"region": os.getenv("AWS_KEY_REGION", ""),
11-
},
12-
"azure": {
13-
"keyName": os.getenv("AZURE_KEY_NAME", ""),
14-
"keyVaultEndpoint": os.getenv("AZURE_KEY_VAULT_ENDPOINT", ""),
15-
},
16-
"gcp": {
17-
"projectId": os.getenv("GCP_PROJECT_ID", ""),
18-
"location": os.getenv("GCP_LOCATION", ""),
19-
"keyRing": os.getenv("GCP_KEY_RING", ""),
20-
"keyName": os.getenv("GCP_KEY_NAME", ""),
21-
},
22-
"kmip": {},
23-
"local": {},
24-
}
25-
26-
KMS_PROVIDERS = {
27-
"aws": {},
28-
"azure": {},
29-
"gcp": {},
30-
"kmip": {
31-
"endpoint": os.getenv("KMIP_KMS_ENDPOINT", "not a valid endpoint"),
32-
},
33-
"local": {
34-
"key": bytes.fromhex(
35-
"000102030405060708090a0b0c0d0e0f"
36-
"101112131415161718191a1b1c1d1e1f"
37-
"202122232425262728292a2b2c2d2e2f"
38-
"303132333435363738393a3b3c3d3e3f"
39-
"404142434445464748494a4b4c4d4e4f"
40-
"505152535455565758595a5b5c5d5e5f"
41-
)
42-
},
43-
}
44-
45-
46-
class EncryptedRouter:
47-
def allow_migrate(self, db, app_label, model_name=None, model=None, **hints):
48-
if model:
49-
return db == ("other" if has_encrypted_fields(model) else "default")
50-
return db == "default"
51-
52-
def db_for_read(self, model, **hints):
53-
if has_encrypted_fields(model):
54-
return "other"
55-
return "default"
56-
57-
db_for_write = db_for_read
58-
59-
def kms_provider(self, model):
60-
return "local"
1+
# Queryable Encryption helper classes
612

623

634
class EqualityQuery(dict):

tests/encryption_/tests.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib
2-
import os
32
from datetime import datetime, time, timedelta
43
from io import StringIO
54
from unittest.mock import patch
@@ -9,7 +8,7 @@
98
from bson.binary import Binary
109
from django.core.management import call_command
1110
from django.db import connections, models
12-
from django.test import TestCase, TransactionTestCase, modify_settings, override_settings
11+
from django.test import TransactionTestCase, modify_settings, override_settings
1312

1413
from django_mongodb_backend.encryption import EqualityQuery
1514
from django_mongodb_backend.fields import EncryptedFieldMixin
@@ -351,51 +350,3 @@ def test_patient(self):
351350
self.assertEqual(len(list(patients)), 1)
352351
records = connections["other"].database.encryption__patientrecord.find()
353352
self.assertTrue("__safeContent__" in records[0])
354-
355-
356-
class KMSCredentialsTests(TestCase):
357-
def test_env(self):
358-
with patch.dict(os.environ, {}, clear=True):
359-
encryption = reload_module("django_mongodb_backend.encryption")
360-
self.assertEqual(encryption.KMS_CREDENTIALS["aws"]["key"], "")
361-
self.assertEqual(encryption.KMS_CREDENTIALS["aws"]["region"], "")
362-
self.assertEqual(encryption.KMS_CREDENTIALS["azure"]["keyName"], "")
363-
self.assertEqual(encryption.KMS_CREDENTIALS["azure"]["keyVaultEndpoint"], "")
364-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["projectId"], "")
365-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["location"], "")
366-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["keyRing"], "")
367-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["keyName"], "")
368-
env = {
369-
"AWS_KEY_ARN": "TestArn",
370-
"AWS_KEY_REGION": "us-x-test",
371-
"AZURE_KEY_NAME": "azure-key",
372-
"AZURE_KEY_VAULT_ENDPOINT": "https://example.vault.azure.net/",
373-
"GCP_PROJECT_ID": "gcp-test-prj",
374-
"GCP_LOCATION": "test-loc",
375-
"GCP_KEY_RING": "ring1",
376-
"GCP_KEY_NAME": "gcp-key",
377-
}
378-
with patch.dict(os.environ, env, clear=True):
379-
encryption = reload_module("django_mongodb_backend.encryption")
380-
self.assertEqual(encryption.KMS_CREDENTIALS["azure"]["keyName"], "azure-key")
381-
self.assertEqual(
382-
encryption.KMS_CREDENTIALS["azure"]["keyVaultEndpoint"],
383-
"https://example.vault.azure.net/",
384-
)
385-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["projectId"], "gcp-test-prj")
386-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["location"], "test-loc")
387-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["keyRing"], "ring1")
388-
self.assertEqual(encryption.KMS_CREDENTIALS["gcp"]["keyName"], "gcp-key")
389-
390-
391-
class KMSProvidersTests(TestCase):
392-
def test_env(self):
393-
with patch.dict(os.environ, {}, clear=True):
394-
encryption = reload_module("django_mongodb_backend.encryption")
395-
self.assertEqual(encryption.KMS_PROVIDERS["kmip"]["endpoint"], "not a valid endpoint")
396-
env = {
397-
"KMIP_KMS_ENDPOINT": "kmip://loc",
398-
}
399-
with patch.dict(os.environ, env, clear=True):
400-
encryption = reload_module("django_mongodb_backend.encryption")
401-
self.assertEqual(encryption.KMS_PROVIDERS["kmip"]["endpoint"], "kmip://loc")

0 commit comments

Comments
 (0)