Add support for DecryptedField in nested dict fields#2
Add support for DecryptedField in nested dict fields#2
Conversation
Co-authored-by: jcarlosdev <8920902+jcarlosdev@users.noreply.github.com>
…ility Co-authored-by: jcarlosdev <8920902+jcarlosdev@users.noreply.github.com>
|
@copilot In the tests, I see that you create a new encrypted object document and encrypt the fields manually in doc = TestDocNested.make(dict( it would be better if the document could be created using make_encr(), like this doc = TestDocNested.make_encr(dict( under the hood it will encrypt the values and set them to the corresponding encrypted fields. Also, only save the encrypted fields to the db, the unencrypted fields will stay as a virtual field to get and set encrypted values |
…fields Co-authored-by: jcarlosdev <8920902+jcarlosdev@users.noreply.github.com>
Updated in commit b880cb8. The test now uses doc = TestDocNested.make_encr(dict(
_id=1,
profile=dict(
first_name='Jerome',
last_name='Smith',
age=30
)
))The |
DecryptedFielduses Python descriptors (__get__/__set__) which only work at class level. When placed inside a nested dict field schema, the descriptor protocol isn't invoked and encryption/decryption fails.Changes
ming/encryption.py:EncryptedObjectclass extendingObjectthat intercepts attribute/item access to handleDecryptedFieldpairs within nested dictsencrypt_some_fields()to recursively handle nested dicts withEncryptedObjectSchema, enablingmake_encr()to automatically encrypt nested fieldsming/schema.py:EncryptedObjectSchemato detectDecryptedFieldinstances in dict schemas and produceEncryptedObjectresultsSchemaItem.make()to route dicts containingDecryptedFieldtoEncryptedObjectSchemaDocument._validate()to inject encryption functions into nestedEncryptedObjectinstances post-validationExample
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.