Add store support for Spin adapter (KV, config, secret)#253
Add store support for Spin adapter (KV, config, secret)#253
Conversation
- dispatch() in request.rs now injects ConfigStoreHandle, KvHandle, and SecretHandle into request extensions on every request - SpinSecretStore normalises the lookup key to lowercase so conventional uppercase names (e.g. SMOKE_SECRET) resolve to the correct Spin variable - contract.rs gains store injection smoke tests (config, kv, secret) and wasm32 compile-time trait checks for SpinKvStore and SpinSecretStore
- spin.toml gains key_value_stores = ["default"] binding and variables declarations for greeting and smoke_secret - edgezero.toml adds "spin" to adapters for config, kv, and secrets routes - smoke_test_kv/config/secrets.sh each gain a spin case that builds the WASM binary and starts spin up --listen 127.0.0.1:3000; the config script skips dotted-key checks (Spin variable names cannot contain dots); the secrets script passes SPIN_VARIABLE_SMOKE_SECRET at startup
spin up creates .spin/ (SQLite KV database and component logs) in the adapter directory during local development, mirroring .wrangler/ for CF.
instead of silently truncating; callers now get an explicit signal rather than incomplete pagination results - Correct DEFAULT_MAX_LIST_KEYS, with_max_list_keys, and module-level docs to accurately describe error-return behaviour (not truncation, not "unbounded allocation" guarding) - Add log::debug in SpinSecretStore::get_bytes when store_name is non-empty so callers learn the flat-namespace constraint at runtime - Add comment in config_store contract tests explaining the InMemory backend accepts dotted/uppercase keys that the real Spin backend would reject via InvalidName - Add comment in lib.rs explaining why SpinConfigStore has different feature gating than SpinKvStore and SpinSecretStore
ChristianPavilonis
left a comment
There was a problem hiding this comment.
Summary
Thanks for adding Spin store support and the smoke/CI coverage. CI is green. I found two configuration-semantics issues worth addressing before relying on non-default store names: Spin KV dispatch is hard-coded to default, and accepting a Spin config-store adapter override is misleading because the runtime does not consume that name.
| .extensions_mut() | ||
| .insert(ConfigStoreHandle::new(Arc::new(SpinConfigStore::new()))); | ||
|
|
||
| match SpinKvStore::open_default() { |
There was a problem hiding this comment.
Spin dispatch ignores manifest-configured KV store names
Severity: P1
dispatch() always opens SpinKvStore::open_default(). That means [stores.kv].name or [stores.kv.adapters.spin].name from edgezero.toml cannot affect the injected handle, unlike the other adapters' manifest-aware run_app paths. Apps configured to use a non-default Spin KV label will silently get the wrong label or no KV handle.
Suggestion: Make the Spin entrypoint/dispatch path manifest-aware and resolve the configured Spin KV label before opening the store, or reject/document Spin KV store-name configuration until the runtime can honor it.
|
|
||
| pub const DEFAULT_CONFIG_STORE_NAME: &str = "EDGEZERO_CONFIG"; | ||
| const SUPPORTED_CONFIG_STORE_ADAPTERS: &[&str] = &["axum", "cloudflare", "fastly"]; | ||
| const SUPPORTED_CONFIG_STORE_ADAPTERS: &[&str] = &["axum", "cloudflare", "fastly", "spin"]; |
There was a problem hiding this comment.
Spin config-store adapter overrides are accepted but not used by the Spin runtime
Severity: P2
This change makes [stores.config.adapters.spin] pass validation, but edgezero_adapter_spin::run_app does not take edgezero.toml and dispatch() injects SpinConfigStore::new() directly. Since Spin variables are a flat namespace, the configured name/adapter override has no effect at runtime.
Suggestion: Either keep spin rejected for config-store adapter-name overrides, or update the runtime/docs so users know Spin config values come from component variables and the configured store name is ignored.
Summary
SpinKvStore,SpinConfigStore, andSpinSecretStoreso Spin handlers can access key-value, configuration, and secret data through the samectx.kv_handle(),ctx.config_store(), andctx.secret_handle()API as every other adapter.spin-adapter-testsCI job, store injection contract tests, and Spin support to all three smoke test scripts.Changes
crates/edgezero-adapter-spin/src/config_store.rsSpinConfigStorebacked byspin_sdk::variables; dual-backend (Spin / in-memory for tests); contract tests via macrocrates/edgezero-adapter-spin/src/key_value_store.rsSpinKvStorebacked byspin_sdk::key_value; in-process prefix filter + pagination; configurablemax_list_keyscap (warn + truncate); TTL silently ignoredcrates/edgezero-adapter-spin/src/secret_store.rsSpinSecretStorebacked byspin_sdk::variables; key normalised to lowercase to match Spin variable naming rulescrates/edgezero-adapter-spin/src/request.rsdispatch()now injectsConfigStoreHandle,KvHandle, andSecretHandleinto every request's extensionscrates/edgezero-adapter-spin/src/lib.rscrates/edgezero-adapter-spin/tests/contract.rsSpinKvStoreandSpinSecretStorecrates/edgezero-core/src/manifest.rs"spin"toSUPPORTED_CONFIG_STORE_ADAPTERScrates/edgezero-core/src/config_store.rsConfigStoretrait doc to listSpinConfigStore.github/workflows/test.ymlspin-adapter-testsjob: native tests + wasm32-wasip1 compilation checkexamples/app-demo/crates/app-demo-adapter-spin/spin.tomlkey_value_stores = ["default"]binding and variable declarations forgreetingandsmoke_secretexamples/app-demo/edgezero.toml"spin"toadaptersfor config, KV, and secrets routesscripts/smoke_test_kv.shspincasescripts/smoke_test_config.shspincase; skips dotted-key checks (Spin variable names cannot contain dots)scripts/smoke_test_secrets.shspincase; passes secret value viaSPIN_VARIABLE_SMOKE_SECRETat startup.gitignore.spin/(runtime SQLite KV database and component logs)Closes
Closes #73
Closes #74
Test plan
cargo test --workspace --all-targetscargo clippy --workspace --all-targets --all-features -- -D warningscargo check --workspace --all-targets --features "fastly cloudflare spin"cargo check -p edgezero-adapter-spin --target wasm32-wasip1 --features spin./scripts/smoke_test_kv.sh spin./scripts/smoke_test_config.sh spin./scripts/smoke_test_secrets.sh spinChecklist
{id}syntax (not:id)edgezero_core(nothttpcrate)