use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ConfigStoreError {
#[error("failed to read config from {path}")]
Read {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to write config to {path}")]
Write {
path: PathBuf,
#[source]
source: std::io::Error,
},
}
impl auths_crypto::AuthsErrorInfo for ConfigStoreError {
fn error_code(&self) -> &'static str {
match self {
Self::Read { .. } => "AUTHS-E3951",
Self::Write { .. } => "AUTHS-E3952",
}
}
fn suggestion(&self) -> Option<&'static str> {
match self {
Self::Read { .. } => Some("Check that ~/.auths/config.toml exists and is readable"),
Self::Write { .. } => Some("Check file permissions for ~/.auths/config.toml"),
}
}
}
pub trait ConfigStore: Send + Sync {
fn read(&self, path: &std::path::Path) -> Result<Option<String>, ConfigStoreError>;
fn write(&self, path: &std::path::Path, content: &str) -> Result<(), ConfigStoreError>;
}