diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e40408..106f1f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/mongoengine_plus/models/base.py b/mongoengine_plus/models/base.py index 3b96216..9980f72 100644 --- a/mongoengine_plus/models/base.py +++ b/mongoengine_plus/models/base.py @@ -4,8 +4,8 @@ class BaseModel: - _excluded: ClassVar = [] - _hidden: ClassVar = [] + _excluded: ClassVar[list[str]] = [] + _hidden: ClassVar[list[str]] = [] def __init__(self, *args, **values): return super().__init__(*args, **values) diff --git a/mongoengine_plus/types/encrypted_string/__init__.py b/mongoengine_plus/types/encrypted_string/__init__.py index d9db7a6..a15afe7 100644 --- a/mongoengine_plus/types/encrypted_string/__init__.py +++ b/mongoengine_plus/types/encrypted_string/__init__.py @@ -3,7 +3,7 @@ import codecs import boto3 -from pymongo.encryption import _EncryptionIO +from pymongo.synchronous.encryption import _EncryptionIO from .fields import EncryptedStringField diff --git a/mongoengine_plus/types/encrypted_string/base.py b/mongoengine_plus/types/encrypted_string/base.py index 8733f03..fe9b2ba 100644 --- a/mongoengine_plus/types/encrypted_string/base.py +++ b/mongoengine_plus/types/encrypted_string/base.py @@ -2,7 +2,7 @@ from typing import Dict from bson import CodecOptions -from bson.binary import STANDARD, UUID_SUBTYPE, Binary +from bson.binary import STANDARD, Binary from mongoengine import get_connection from pymongo.encryption import ClientEncryption @@ -32,7 +32,7 @@ def get_data_key_binary(key_namespace: str, key_name: str) -> Binary: # Buscamos el data key data_key = get_data_key(key_namespace, key_name) uuid_data_key = data_key['_id'] - return Binary(uuid_data_key.bytes, UUID_SUBTYPE) + return uuid_data_key def create_data_key( @@ -52,6 +52,7 @@ def create_data_key( partialFilterExpression={"keyAltNames": {"$exists": True}}, ) + client_encryption: ClientEncryption with ClientEncryption( kms_provider, key_namespace, diff --git a/mongoengine_plus/types/encrypted_string/fields.py b/mongoengine_plus/types/encrypted_string/fields.py index 45e201e..882a596 100644 --- a/mongoengine_plus/types/encrypted_string/fields.py +++ b/mongoengine_plus/types/encrypted_string/fields.py @@ -8,7 +8,7 @@ from .base import get_data_key_binary -CODEC_OPTION = CodecOptions(uuid_representation=STANDARD) +CODEC_OPTION: CodecOptions = CodecOptions(uuid_representation=STANDARD) class EncryptedStringField(BaseField): @@ -57,6 +57,7 @@ def to_python(self, value: Any) -> Any: connection = get_connection() + client_encryption: ClientEncryption with ClientEncryption( self.kms_provider, self.key_namespace, connection, CODEC_OPTION ) as client_encryption: @@ -66,6 +67,7 @@ def to_mongo(self, value: Any) -> Any: connection = get_connection() data_key = get_data_key_binary(self.key_namespace, self.key_name) + client_encryption: ClientEncryption with ClientEncryption( self.kms_provider, self.key_namespace, connection, CODEC_OPTION ) as client_encryption: diff --git a/mongoengine_plus/version.py b/mongoengine_plus/version.py index 3f262a6..19b4f1d 100644 --- a/mongoengine_plus/version.py +++ b/mongoengine_plus/version.py @@ -1 +1 @@ -__version__ = '1.2.1' +__version__ = '1.3.0' diff --git a/requirements-test.txt b/requirements-test.txt index fcebc5c..1653f0c 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,10 +1,10 @@ -black==24.10.0 -flake8==7.1.1 -isort==5.13.2 -mypy==1.14.1 -moto[server,kms]==5.0.26 -pytest==8.3.4 -pytest-asyncio==0.25.2 -pytest-cov==6.0.0 -pytest-freezegun==0.4.2 -testcontainers==4.9.0 +black==25.11.* +flake8==7.3.* +isort==7.0.* +moto[server,kms]==5.1.* +mypy==1.18.* +pytest==9.0.* +pytest-asyncio==1.3.* +pytest-cov==7.0.* +pytest-freezegun==0.4.* +testcontainers==4.13.* diff --git a/requirements.txt b/requirements.txt index 32c07ba..4200bcf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ blinker==1.9.0 -dnspython==2.7.0 +boto3==1.40.71 +dnspython==2.8.0 mongoengine==0.29.1 -pymongo==3.13.0 -pymongocrypt==1.12.2 -boto3==1.35.95 +pymongo==4.15.4 +pymongocrypt==1.16.0 diff --git a/setup.py b/setup.py index a339550..26d6afe 100644 --- a/setup.py +++ b/setup.py @@ -23,17 +23,16 @@ packages=find_packages(), include_package_data=True, package_data=dict(mongoengine_plus=['py.typed']), - python_requires='>=3.9', + python_requires='>=3.10', install_requires=[ 'mongoengine>=0.29.1', 'dnspython>=2.7.0', - 'pymongo>=3.13.0,<4.0.0', + 'pymongo>=4.0.0,<5.0.0', 'pymongocrypt>=1.12.2,<2.0.0', 'boto3>=1.34.106,<2.0.0', 'blinker>=1.9.0,<2.0.0', ], classifiers=[ - 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', diff --git a/tests/types/test_encrypted_string.py b/tests/types/test_encrypted_string.py index 90d30c4..f0a1b00 100644 --- a/tests/types/test_encrypted_string.py +++ b/tests/types/test_encrypted_string.py @@ -6,7 +6,8 @@ from bson import Binary from mongoengine import Document, StringField from pymongo import MongoClient -from pymongo.encryption import Algorithm, ClientEncryption, _EncryptionIO +from pymongo.encryption import Algorithm, ClientEncryption +from pymongo.synchronous.encryption import _EncryptionIO from mongoengine_plus.models import uuid_field from mongoengine_plus.types import EncryptedStringField @@ -85,6 +86,7 @@ def test_create_data_key( ({"keyAltNames": key_name}) ) + assert data_key is not None assert data_key['keyAltNames'] == [key_name] assert type(data_key['keyMaterial']) is bytes assert data_key['masterKey'] == dict( @@ -113,6 +115,7 @@ def test_encrypted_string_on_saving_and_reading( assert user_dict['name'] == user.name assert isinstance(user_dict['ssn'], Binary) + client_encryption: ClientEncryption with ClientEncryption( EncryptedStringField.kms_provider, EncryptedStringField.key_namespace,