8000 Pluggable storage backend by neilberkman · Pull Request #6 · dominicletz/certmagex · GitHub
[go: up one dir, main page]

Skip to content

Pluggable storage backend - #6

Merged
dominicletz merged 6 commits into
dominicletz:masterfrom
neilberkman:pluggable-storage-backend
Jul 6, 2026
Merged

dominicletz merged 6 commits into
dominicletz:masterfrom
neilberkman:pluggable-storage-backend

Conversation

@neilberkman
Copy link
Copy Markdown
Contributor

Makes CertMagex.Storage delegate 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 new CertMagex.Storage.Backend behaviour (child/0, insert/2, delete/1, lookup/1); select one with config :certmagex, :storage_backend, MyBackend.

Dogfooding this in a Phoenix SaaS that stores certs encrypted in Postgres with an ETS read-through cache.

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).
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/certmagex/storage.ex Resolved
Comment thread lib/certmagex/storage.ex Resolved
- 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).
@dominicletz
Copy link
Copy Markdown
Owner

@cursor review the gemini comments and apply fixes as appropriate

dominicletz and others added 3 commits July 6, 2026 15:31
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>
@dominicletz
dominicletz merged commit 990f002 into dominicletz:master Jul 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0