Ash FrameworkAF
Ash Framework3y ago
60 replies
moxley

Porting `cloak`-managed fields from Ecto schema to Ash

One of the Ecto schemas in my project uses Cloak to encrypt a value to a column on write, then decrypt the column on read and expose that on a virtual field on the schema.

For example, the schema has these two fields:

field :encrypted_meetup, GF.Encrypted.Map
field :meetup, :map, virtual: true


GF.Encrypted.Map is a very small module tells cloak about the details of encrypting and decrypting the data. cloak will then perform its magic in the background. On database write, encrypted_meetup is expected to be an unencrypted value, and cloak will encrypt that value to the underlying column as a Postgres bytea type. On database read, cloak will decrypt the value, and put it in encrypted_meetup, and it will also cast that value to a struct, and put it in meetup.

How should I approach porting this to an Ash resource? Should I also set up two attributes in the Ash resource, just like in the Ecto schema? Should I define a custom Ash type for transparently encrypting and decrypting the value?
GitHub
Elixir encryption library designed for Ecto. Contribute to danielberkompas/cloak development by creating an account on GitHub.
GitHub - danielberkompas/cloak: Elixir encryption library designed ...
Was this page helpful?