use self::authentication::Authentication;
pub mod authentication;
pub mod backends;
pub mod storage;
#[derive(thiserror::Error, Debug)]
pub enum AuthenticationStorageError {
#[error(transparent)]
FileStorageError(#[from] crate::authentication_storage::backends::file::FileStorageError),
#[cfg(feature = "keyring")]
#[error(transparent)]
KeyringStorageError(
#[from] crate::authentication_storage::backends::keyring::KeyringAuthenticationStorageError,
),
#[cfg(feature = "netrc-rs")]
#[error(transparent)]
NetRcStorageError(#[from] crate::authentication_storage::backends::netrc::NetRcStorageError),
#[error(transparent)]
MemoryStorageError(#[from] crate::authentication_storage::backends::memory::MemoryStorageError),
#[error("none of the configured backends could store the credentials for '{host}': {backends}")]
StoreFailed {
host: String,
backends: String,
},
#[error("none of the configured backends could delete the credentials for '{host}'")]
DeleteFailed {
host: String,
},
#[error("no configured backend is named '{backend}'")]
UnknownBackend {
backend: String,
},
}
pub trait StorageBackend: std::fmt::Debug {
fn name(&self) -> String;
fn store(
&self,
host: &str,
authentication: &Authentication,
) -> Result<(), AuthenticationStorageError>;
fn get(&self, host: &str) -> Result<Option<Authentication>, AuthenticationStorageError>;
fn list(&self) -> Result<Vec<(String, Authentication)>, AuthenticationStorageError> {
Ok(Vec::new())
}
fn list_keys(&self) -> Result<Vec<String>, AuthenticationStorageError> {
Ok(self.list()?.into_iter().map(|(host, _)| host).collect())
}
fn delete(&self, host: &str) -> Result<(), AuthenticationStorageError>;
}