WIP push-to-talk Letta chat frontend
1use keyring::{Entry, Error};
2use strum::{Display, EnumString};
3
4pub mod commands;
5
6#[derive(Debug, PartialEq, Display, EnumString)]
7pub enum SecretName {
8 #[strum(to_string = "cartesia_api_key")]
9 CartesiaApiKey,
10 #[strum(to_string = "letta_api_key")]
11 LettaApiKey,
12}
13
14const SERVICE_NAME: &'static str = "miwiwi";
15
16pub struct SecretsManager {}
17impl SecretsManager {
18 pub fn new() -> Self {
19 Self {}
20 }
21
22 pub fn get_secret(&self, name: SecretName) -> Result<String, Error> {
23 let entry = Entry::new(SERVICE_NAME, &name.to_string())?;
24 let cred = entry.get_password()?;
25
26 Ok(cred)
27 }
28
29 pub fn set_secret(&self, name: SecretName, value: String) -> Result<(), Error> {
30 let entry = Entry::new(SERVICE_NAME, &name.to_string())?;
31
32 entry.set_password(&value)
33 }
34
35 pub fn delete_secret(&self, name: SecretName) -> Result<(), Error> {
36 let entry = Entry::new(SERVICE_NAME, &name.to_string())?;
37
38 entry.delete_credential()
39 }
40
41 pub fn has_secret(&self, name: SecretName) -> Result<bool, Error> {
42 match self.get_secret(name) {
43 Ok(_) => Ok(true),
44 Err(Error::NoEntry) => Ok(false),
45 Err(err) => Err(err),
46 }
47 }
48}