Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! add support for mong…
Browse files Browse the repository at this point in the history
…odb Client Side Field Level Encryption (CSFLE)
  • Loading branch information
dill0wn committed Sep 12, 2024
1 parent c95286d commit acf88ac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/presentations/demo_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from ming.datastore import create_engine, create_datastore, DataStore
from ming.encryption import EncryptionConfig
import ming.schema as S
from ming.tests import EncryptionConfigHelper
from ming.tests import make_encryption_key

bind: DataStore = create_datastore(
'mongodb://localhost:27017/test_database',
encryption=EncryptionConfig({
'kms_providers': {
'local': {
# Don't use this for production! This is just for demo purposes
'key': EncryptionConfigHelper.make_encryption_key('demo_encryption'),
'key': make_encryption_key('demo_encryption'),
},
},
'key_vault_namespace': 'demo_encryption_db.__keyVault',
Expand Down
11 changes: 6 additions & 5 deletions ming/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ def push_seed(seed):
random.setstate(rstate)


class EncryptionConfigHelper:
@staticmethod
def make_encryption_key(seed=__name__):
with push_seed(seed):
return base64.b64encode(os.urandom(96)).decode('ascii')


@staticmethod
def make_encryption_key(seed=__name__):
with push_seed(seed):
return base64.b64encode(os.urandom(96)).decode('ascii')
class EncryptionConfigHelper:

LOCAL_KEY_VAULT_NAMESPACE = 'encryption_test.coll_key_vault_test'
LOCAL_KEY = make_encryption_key('test local key')
Expand Down
4 changes: 2 additions & 2 deletions ming/tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ming import create_datastore, create_engine
from ming.exc import MingConfigError
from ming.datastore import Engine
from ming.tests import EncryptionConfigHelper
from ming.tests import EncryptionConfigHelper, make_encryption_key


class DummyConnection:
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_configure_optional_params(self):
assert session.bind.db is not None

def test_configure_encryption(self):
encryption_key = EncryptionConfigHelper.make_encryption_key('foo')
encryption_key = make_encryption_key('foo')
ming.configure(**{
'ming.main.uri': 'mongodb://localhost:27017/test_db',
'ming.main.replicaSet': 'foobar',
Expand Down
4 changes: 2 additions & 2 deletions ming/tests/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ming.odm.odmsession import ODMSession, ThreadLocalODMSession
from ming.session import Session
from ming.exc import MingException
from ming.tests import EncryptionConfigHelper
from ming.tests import make_encryption_key


def mock_datastore():
Expand Down Expand Up @@ -183,7 +183,7 @@ def setUp(self):
encryption_config = EncryptionConfig({
'kms_providers': {
'local': {
'key': EncryptionConfigHelper.make_encryption_key(__name__),
'key': make_encryption_key(__name__),
},
},
'key_vault_namespace': 'encryption.__keyVault',
Expand Down

0 comments on commit acf88ac

Please sign in to comment.