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 Oct 7, 2024
1 parent b66487e commit 8e1491f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ming/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from typing import TYPE_CHECKING, TypeVar, Generic

from ming.utils import classproperty
import ming.schema

if TYPE_CHECKING:
import ming.datastore
from ming.metadata import Field

Check warning on line 10 in ming/encryption.py

View check run for this annotation

Codecov / codecov/patch

ming/encryption.py#L9-L10

Added lines #L9 - L10 were not covered by tests


class MingEncryptionError(Exception):
Expand Down Expand Up @@ -140,7 +142,13 @@ def _field_names(cls) -> list[str]:
from ming.declarative import Document
from ming.odm.declarative import MappedClass
if issubclass(cls, Document):
return list(cls.m.field_index.keys())
fields: list[tuple[str, Field]] = list(cls.m.field_index.items())
field_names = []
for (k, v) in fields:
if v.type in (ming.schema.Deprecated,):
continue

Check warning on line 149 in ming/encryption.py

View check run for this annotation

Codecov / codecov/patch

ming/encryption.py#L149

Added line #L149 was not covered by tests
field_names.append(k)
return field_names
if issubclass(cls, MappedClass):
return list(cls.query.mapper.property_index.keys())
raise NotImplementedError("Unexpected class type. You must implement `field_names` as a @classproperty in your mixin implementation.")

Check warning on line 154 in ming/encryption.py

View check run for this annotation

Codecov / codecov/patch

ming/encryption.py#L154

Added line #L154 was not covered by tests
Expand Down
3 changes: 2 additions & 1 deletion ming/odm/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def __init__(self, field_type, *args, **kwargs):

@property
def include_in_repr(self):
if isinstance(self.field.schema, (S.Binary, S.Deprecated)): return False
if isinstance(self.field.schema, (S.Binary, S.Deprecated)):
return False

Check warning on line 62 in ming/odm/property.py

View check run for this annotation

Codecov / codecov/patch

ming/odm/property.py#L62

Added line #L62 was not covered by tests
return True

def repr(self, doc):
Expand Down

0 comments on commit 8e1491f

Please sign in to comment.