Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions mongoengine_plus/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mongoengine_plus/types/encrypted_string/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import codecs

import boto3
from pymongo.encryption import _EncryptionIO
from pymongo.synchronous.encryption import _EncryptionIO

from .fields import EncryptedStringField

Expand Down
5 changes: 3 additions & 2 deletions mongoengine_plus/types/encrypted_string/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -52,6 +52,7 @@ def create_data_key(
partialFilterExpression={"keyAltNames": {"$exists": True}},
)

client_encryption: ClientEncryption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es necesario esto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si, el lint ahora es más estricto, marca este error:
error: Need type annotation for "client_encryption" [var-annotated]

with ClientEncryption(
kms_provider,
key_namespace,
Expand Down
4 changes: 3 additions & 1 deletion mongoengine_plus/types/encrypted_string/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion mongoengine_plus/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.1'
__version__ = '1.3.0'
20 changes: 10 additions & 10 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -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.*
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion tests/types/test_encrypted_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Loading