Repository navigation
Pluggable storage backend - #6
Conversation
Make CertMagex.Storage delegate to a configurable backend module so cert/key storage can be backed by something other than the on-disk DetsPlus file (e.g. a database-backed, encrypted store for durability, encryption-at-rest, and clustering). Default is unchanged (CertMagex.Storage.Dets), so existing setups are unaffected. Set via `config :certmagex, :storage_backend, MyBackend`; backends implement the new CertMagex.Storage.Backend behaviour (child/0, insert/2, delete/1, lookup/1).
There was a problem hiding this comment.
Code Review
This pull request introduces a pluggable storage backend system for CertMagex.Storage by defining a new Backend behaviour and refactoring the default on-disk DetsPlus store into a nested Dets module. Feedback highlights two critical issues: first, using __MODULE__ inside the nested Dets module changes the DETS table name, which will break backward compatibility and crash existing setups; second, returning :ignore from a custom backend's child/0 will cause an ArgumentError on startup, requiring a dummy worker to handle it gracefully.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
- Dets backend keeps the historical table name CertMagex.Storage (not
__MODULE__/CertMagex.Storage.Dets). DETS stores the name in the file header,
so renaming would fail with {:error, {:name_mismatch}} and crash existing
setups on upgrade.
- CertMagex.Storage.child/0 maps a backend's :ignore to an EmptyWorker child
(start_link -> :ignore), since :ignore is not a valid supervisor child spec.
Lets backends that need no process of their own return :ignore as documented.
The worker pattern-matches `:ok = Storage.insert(...)` after issuing a cert, so a backend returning anything else would MatchError on success. Tighten the behaviour callback from `any()` to `:ok` and document it (the default Dets backend already returns :ok via DetsPlus.start_sync/1).
|
@cursor review the gemini comments and apply fixes as appropriate |
Document storage_backend config, assert insert failures explicitly, and add tests for backend delegation, EmptyWorker child spec, and DETS table name compat. Co-authored-by: Cursor <cursoragent@cursor.com>
Remove duplicate module comments and EmptyWorker child_spec, make backend/0 private, and dedupe storage_backend env restore in tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Makes
CertMagex.Storagedelegate to a configurable backend so certs/keys can be stored somewhere other than the on-disk DetsPlus file — e.g. a database-backed, encrypted store for durability, encryption-at-rest, and clustering.Default is unchanged (
CertMagex.Storage.Dets), so existing setups are unaffected. Backends implement the newCertMagex.Storage.Backendbehaviour (child/0,insert/2,delete/1,lookup/1); select one withconfig :certmagex, :storage_backend, MyBackend.Dogfooding this in a Phoenix SaaS that stores certs encrypted in Postgres with an ETS read-through cache.