use crate::record::{SecretInfo, SecretRecord};
#[derive(Debug, thiserror::Error)]
pub enum StoreError {
#[error("credential store io: {0}")]
Io(#[from] std::io::Error),
#[error("credential store encoding: {0}")]
Encoding(String),
#[error("credential store is read-only; {0}")]
ReadOnly(String),
#[error("credential store unavailable: {0}")]
Unavailable(String),
}
pub trait CredentialStore: Send + Sync {
fn get(&self, component: &str, key: &str) -> Result<Option<SecretRecord>, StoreError>;
fn put(&self, component: &str, key: &str, rec: &SecretRecord) -> Result<(), StoreError>;
fn erase(&self, component: &str, key: &str) -> Result<(), StoreError>;
fn list(&self, component: Option<&str>) -> Result<Vec<SecretInfo>, StoreError>;
fn components(&self) -> Result<Vec<String>, StoreError>;
fn update(
&self,
component: &str,
key: &str,
mutate: &mut dyn FnMut(&mut SecretRecord),
) -> Result<Option<SecretRecord>, StoreError>;
}