Skip to content

refactor(guest,auth): name each key vendor backend in one place - #1561

Draft
freshtonic wants to merge 1 commit into
james/guest-vendor-optionfrom
james/kms-vendor-dispatch
Draft

freshtonic wants to merge 1 commit into
james/guest-vendor-optionfrom
james/kms-vendor-dispatch

Conversation

@freshtonic

Copy link
Copy Markdown
Contributor

Summary

The same five-way vendor switch was written in four places: three in the Go guest and one in the @cipherstash/auth binding. A new vendor meant an edit to each. This PR lists the vendors once on each side.

Changes

  • Go guest: one guest_vendors! macro call lists the vendor clients once. It generates the GuestVendor enum and forwards every KeyVendorBackend method. VendorSettings::vendor() is gone.
  • @cipherstash/auth: each BACKENDS row also holds the function that builds the client from the environment, so run_vendor has no switch.
  • Still per vendor, by design: each vendor's config keys and its constructor in the guest. These are different data for each vendor, not the same switch. A new vendor now touches three places in the guest (the macro list, its config keys, its constructor) and one row in auth.
  • Changeset: @cipherstash/auth patch. native.d.ts rebuilt, no change.

Behaviour change

  • The old dispatch did not forward same_key, so the guest used a plain text compare for Google Cloud KMS and Azure key names. Those should ignore the key version. It is forwarded now, and a new test covers it. The guest never rewraps a record, so no reachable path changes.

Verification

Run on the top branch of this stack (james/kms-vendor-dispatch), on macOS:

  • cargo fmt --all --check and cargo clippy --workspace --all-features --all-targets -- -D warnings: pass.
  • mise x --env test -- cargo nextest run --workspace --all-features: 1401 of 1402 pass. The one failure is stack-encrypt::ui derive_diagnostics (trybuild). It fails on every snapshot because of a local rustc wrapper that changes the paths in the compiler output. This stack does not touch stack-encrypt. CI is the check for it.
  • mise run wasm:guest:test: 80 of 80 pass.
  • All four Go guests rebuilt, then go vet ./... and go test -count=1 ./... in languages/golang: pass.
  • pnpm --filter @cipherstash/auth test: 92 pass. pnpm --filter stash test: 1667 pass.
  • Biome on the changed TypeScript and script files: no errors.
  • cargo check of the workspace and the guest (native and wasm32-wasip1) on each branch of the stack: pass.

Related

Refs #1541. Code-smell follow-up to the key vendor backend stack.

The five-way vendor switch was written again in each place that used
it: the guest's GuestVendor Debug, VendorSettings::vendor, a dispatch
macro with one arm per vendor and method, and run_vendor in the auth
binding. A new vendor meant an edit to each one.

In the guest, one macro call lists the vendor clients once. The macro
makes the GuestVendor enum and forwards every KeyVendorBackend method
to the configured client. Debug reads the name from vendor(), and
VendorSettings::vendor is gone. The config keys and the constructor
of each vendor stay where they are, because they are different data
for each vendor, not the same switch.

The dispatch did not forward same_key, so the guest used the default
text compare for Google Cloud KMS and Azure, which ignore the key
version. The guest does not rewrap a record, so no call path changes,
but the macro now forwards it and a test shows it.

In the auth binding, each row of BACKENDS now also holds how to build
the vendor client from the environment. run_vendor reads the row, so
the table is the one list of backends in the module.
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ea7f160

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@cipherstash/auth Patch
stash Patch
@cipherstash/stack Patch
@cipherstash/wizard Patch
@cipherstash/ffi-integration-tests Patch
@cipherstash/basic-example Patch
@cipherstash/e2e Patch
@cipherstash/bench Patch
@cipherstash/stack-drizzle Patch
@cipherstash/stack-prisma Patch
@cipherstash/stack-supabase Patch
@cipherstash/test-kit Patch
@cipherstash/prisma-example Patch
@cipherstash/auth-darwin-arm64 Patch
@cipherstash/auth-darwin-x64 Patch
@cipherstash/auth-linux-arm64-gnu Patch
@cipherstash/auth-linux-x64-gnu Patch
@cipherstash/auth-linux-x64-musl Patch
@cipherstash/auth-win32-x64-msvc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
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.

1 participant