pub trait CredentialStore: Send + Sync {
// Required methods
fn read(&self, provider_id: &str) -> Result<Option<Credential>>;
fn list(&self) -> Result<Vec<CredentialInfo>>;
fn modify(
&self,
provider_id: &str,
f: &mut dyn FnMut(Option<Credential>) -> Result<Option<Credential>>,
) -> Result<Option<Credential>>;
fn delete(&self, provider_id: &str) -> Result<()>;
}Expand description
App-owned credential storage, keyed by provider id, one credential per provider.
modify is the only write path, so every mutation is a serialized
read-modify-write. Callers that need to refresh a rotated token run the
refresh inside modify so concurrent requests cannot double-refresh.
Error semantics: read yields Ok(None) for a missing entry and Err
on storage failure. list is best-effort per slot: a single unreadable
entry is omitted so one corrupt slot cannot hide every other stored
credential from enumeration (status, /provider, logout). list fails
only when enumeration itself cannot run. list must not execute
configured API-key commands or open network flows.
Required Methods§
Sourcefn read(&self, provider_id: &str) -> Result<Option<Credential>>
fn read(&self, provider_id: &str) -> Result<Option<Credential>>
Read the stored credential, possibly expired. Display/status use.
Sourcefn list(&self) -> Result<Vec<CredentialInfo>>
fn list(&self) -> Result<Vec<CredentialInfo>>
List stored credential metadata without exposing secrets.
Per-slot read failures are omitted rather than propagated.
Sourcefn modify(
&self,
provider_id: &str,
f: &mut dyn FnMut(Option<Credential>) -> Result<Option<Credential>>,
) -> Result<Option<Credential>>
fn modify( &self, provider_id: &str, f: &mut dyn FnMut(Option<Credential>) -> Result<Option<Credential>>, ) -> Result<Option<Credential>>
Serialized write — the only write path. f sees the current
credential because correct writes (refresh, login-during-refresh)
depend on it; return the new credential, or None to leave the entry
unchanged. Mutual exclusion is per provider id. Yields the post-write
credential.
Not yet on any production write path: CodeWhale’s two credential writes
(save_api_key_for_identity, logout) already interleave a config-file
mutation and a compensating rollback between their snapshot and their
store write, so they take with_provider_write_lock around the whole
sequence instead. Collapsing them onto modify would change their
error messages and rollback shape, which is deliberately out of this
change’s scope.
Sourcefn delete(&self, provider_id: &str) -> Result<()>
fn delete(&self, provider_id: &str) -> Result<()>
Remove a credential (logout). Serialized against modify.
Exercised by the store tests but not yet on the production logout path:
the full-wipe logout in config.rs still deletes slots directly rather
than through this trait. Routing it here is the remaining half of the
port and is deliberately not folded into this change — logout is
security-sensitive and deserves its own commit and its own tests.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".