use keyring::{Entry, Error}; use strum::{Display, EnumString}; pub mod commands; #[derive(Debug, PartialEq, Display, EnumString)] pub enum SecretName { #[strum(to_string = "cartesia_api_key")] CartesiaApiKey, #[strum(to_string = "letta_api_key")] LettaApiKey, } const SERVICE_NAME: &'static str = "miwiwi"; pub struct SecretsManager {} impl SecretsManager { pub fn new() -> Self { Self {} } pub fn get_secret(&self, name: SecretName) -> Result { let entry = Entry::new(SERVICE_NAME, &name.to_string())?; let cred = entry.get_password()?; Ok(cred) } pub fn set_secret(&self, name: SecretName, value: String) -> Result<(), Error> { let entry = Entry::new(SERVICE_NAME, &name.to_string())?; entry.set_password(&value) } pub fn delete_secret(&self, name: SecretName) -> Result<(), Error> { let entry = Entry::new(SERVICE_NAME, &name.to_string())?; entry.delete_credential() } pub fn has_secret(&self, name: SecretName) -> Result { match self.get_secret(name) { Ok(_) => Ok(true), Err(Error::NoEntry) => Ok(false), Err(err) => Err(err), } } }