pub struct Secrets {
pub store: Arc<dyn KeyringStore>,
/* private fields */
}Expand description
High-level facade combining a KeyringStore with environment variable fallbacks.
Lookup precedence: secret store -> env -> none. Callers that also have a TOML config layer must wire that themselves at the very end of the chain (the config crate handles this).
§Examples
use codewhale_secrets::Secrets;
let secrets = Secrets::auto_detect();
if let Some(key) = secrets.resolve("deepseek") {
// use the API key
}Fields§
§store: Arc<dyn KeyringStore>Underlying secret store backend.
Implementations§
Source§impl Secrets
impl Secrets
Sourcepub fn new(store: Arc<dyn KeyringStore>) -> Secrets
pub fn new(store: Arc<dyn KeyringStore>) -> Secrets
Build a new facade around the given store, using the
DEFAULT_SERVICE service name.
Sourcepub fn auto_detect() -> Secrets
pub fn auto_detect() -> Secrets
Auto-detect the best available backend based on the environment.
Selection logic:
- If
SECRET_BACKEND_ENVis set tosystem/keyring/os/os-keyring, probe the OS keyring. If the probe succeeds, use it; otherwise fall back to the file-based store with a warning. - If the env var is unset, empty, or
file/local/json, use the file-based store directly. - If the env var is set to an unrecognised value, log a warning and use the file-based store.
Sourcepub fn file_backed() -> Secrets
pub fn file_backed() -> Secrets
Construct the file-backed default backend directly.
Sourcepub fn system_keyring() -> Secrets
pub fn system_keyring() -> Secrets
Construct the opt-in OS credential backend, falling back to the file-backed store when the platform backend is unavailable.
Sourcepub fn backend_name(&self) -> &'static str
pub fn backend_name(&self) -> &'static str
Backend label, suitable for doctor output.
Sourcepub fn resolve(&self, name: &str) -> Option<String>
pub fn resolve(&self, name: &str) -> Option<String>
Resolve a secret with secret store → env → none precedence.
name is the canonical provider name or a supported provider alias.
Empty strings on either layer are treated as “not set”.
Sourcepub fn resolve_with_source(&self, name: &str) -> Option<(String, SecretSource)>
pub fn resolve_with_source(&self, name: &str) -> Option<(String, SecretSource)>
Resolve a secret and report which layer supplied it.
Sourcepub fn set(&self, name: &str, value: &str) -> Result<(), SecretsError>
pub fn set(&self, name: &str, value: &str) -> Result<(), SecretsError>
Convenience: write a secret through the underlying store.
Sourcepub fn delete(&self, name: &str) -> Result<(), SecretsError>
pub fn delete(&self, name: &str) -> Result<(), SecretsError>
Convenience: delete a secret through the underlying store.
Sourcepub fn get(&self, name: &str) -> Result<Option<String>, SecretsError>
pub fn get(&self, name: &str) -> Result<Option<String>, SecretsError>
Convenience: read a secret directly (no env fallback).
Sourcepub fn resolve_direct(
&self,
key: &str,
source_hint: Option<&str>,
) -> Option<String>
pub fn resolve_direct( &self, key: &str, source_hint: Option<&str>, ) -> Option<String>
Resolve a secret by key name with an optional source constraint.
This is the fleet-worker secret resolution path. Unlike
resolve, this does NOT map provider names
to their canonical env vars — the caller controls the exact key
and resolution order.
source_hint controls the resolution order:
Some("env")— only check environment variablesSome("keyring")— only check the keyring/file storeNone— try the store first, then fall back to environment