I am planning to use python eve & cerberus to save some documents into a mongodb database. Some of this documents will have some sensible data (pseudo-passwords) which I do want to store encrypted.
I have thought that cerberus custom coercers is the perfect approach for this. However, I am not sure how to make cerberus persist data encrypted, and bring it back decrypted.
I have been looking for documentation, but I do not know if it is possible to specify when I do want to "encrypt" or "decrypt"
I would like something like:
def _normalize_coerce_encrypt_decrypt(self, encrypt=True, value):
if encrypt:
return encrypted(value)
else:
return decrypted(value)
Additional data
It is important that calling this coercer does not add extra normalizations such as add default values. I do only want to encrypt the fields, but let the rest of the document as it is
Is it possible to do something like this? How could I call this kind of coercer with this parameter?