cloak_ecto icon indicating copy to clipboard operation
cloak_ecto copied to clipboard

add `:default_vault` configuration

Open Gladear opened this issue 9 months ago • 1 comments

Hello :wave:

It has been brought to my attention through our tooling that the classic schema when using Cloak.Ecto creates compile-connected dependencies between the schema and the vault. Indeed, using field :field, CustomType creates a compile dependency to CustomType, which, in this library's use case, has in turn a runtime dependency to MyApp.Vault, creating a compile-connected dependency.

I tried to think of some ways to avoid this:

  • One of the solution was to use an API similar to :polymorphic_embed, and make Cloak.Ecto require to use its own field macro, but I couldn't really figure out how to make it work honestly :no_mouth:
  • The second, much simpler solution, is to allow providing a config :cloak_ecto, default_vault: MyApp.Vault in the configuration, so that the CustomType module does not have to reference the MyApp.Vault module. That obviously does not cover the use-case where projects have multiple vaults...

I did a small PoC of the second option. I did not update the documentation, nor the unit tests, as I'm just asking your opinion on this option.

Thanks in advance!

Gladear avatar Mar 24 '25 14:03 Gladear

In my opinion the vault should not be a genserver at all, but a module with it's own settings. See #62. Then automatically you won't have this issue

a3kov avatar Apr 25 '25 05:04 a3kov