#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum AuthCredentialsStoreMode {
Keyring,
File,
Auto,
}
impl Default for AuthCredentialsStoreMode {
fn default() -> Self {
#[cfg(target_os = "macos")]
{
Self::File
}
#[cfg(not(target_os = "macos"))]
{
Self::Auto
}
}
}
impl AuthCredentialsStoreMode {
pub(crate) fn effective_mode(self) -> ResolvedStoreMode {
match self {
Self::Auto => {
if super::keyring::is_functional() {
ResolvedStoreMode::Keyring
} else {
tracing::debug!("Keyring not available, falling back to file storage");
ResolvedStoreMode::File
}
}
Self::Keyring => ResolvedStoreMode::Keyring,
Self::File => ResolvedStoreMode::File,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum ResolvedStoreMode {
Keyring,
File,
}
#[cfg(test)]
mod tests {
use super::{AuthCredentialsStoreMode, ResolvedStoreMode};
#[test]
fn explicit_modes_pass_through_unchanged() {
assert_eq!(AuthCredentialsStoreMode::Keyring.effective_mode(), ResolvedStoreMode::Keyring);
assert_eq!(AuthCredentialsStoreMode::File.effective_mode(), ResolvedStoreMode::File);
}
#[test]
fn auto_resolves_to_a_concrete_backend() {
match AuthCredentialsStoreMode::Auto.effective_mode() {
ResolvedStoreMode::Keyring | ResolvedStoreMode::File => {}
}
}
}