Added both a short profile flag '-p' and made the list and update functions optional since not all secret providers need to support them. Also means the default implementation for the list/update functions in the base SecretsProvider trait will error out by default if undefined

This commit is contained in:
2025-09-10 19:10:36 -06:00
parent bd81446bf8
commit 8ae9b19567
2 changed files with 19 additions and 8 deletions
+3 -2
View File
@@ -70,7 +70,7 @@ struct Cli {
provider: Option<ProviderKind>, provider: Option<ProviderKind>,
/// Specify a run profile to use when wrapping a command /// Specify a run profile to use when wrapping a command
#[arg(long)] #[arg(long, short)]
profile: Option<String>, profile: Option<String>,
/// Output the command that will be run instead of executing it /// Output the command that will be run instead of executing it
@@ -95,7 +95,8 @@ enum Commands {
name: String, name: String,
}, },
/// Update an existing secret in the configured secret provider /// Update an existing secret in the configured secret provider (if supported by the provider)
/// If a provider does not support updating secrets, this command will return an error.
Update { Update {
/// Name of the secret to update /// Name of the secret to update
name: String, name: String,
+16 -6
View File
@@ -1,21 +1,31 @@
pub mod local;
mod git_sync; mod git_sync;
pub mod local;
use crate::config::Config; use crate::config::Config;
use crate::providers::local::LocalProvider; use crate::providers::local::LocalProvider;
use anyhow::Result; use anyhow::{Result, anyhow};
use serde::{Deserialize}; use serde::Deserialize;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error; use thiserror::Error;
pub trait SecretProvider { pub trait SecretProvider {
fn name(&self) -> &'static str; fn name(&self) -> &'static str;
fn get_secret(&self, config: &Config, key: &str) -> Result<String>; fn get_secret(&self, config: &Config, key: &str) -> Result<String>;
fn set_secret(&self, config: &Config, key: &str, value: &str) -> Result<()>; fn set_secret(&self, config: &Config, key: &str, value: &str) -> Result<()>;
fn update_secret(&self, config: &Config, key: &str, value: &str) -> Result<()>; fn update_secret(&self, _config: &Config, _key: &str, _value: &str) -> Result<()> {
Err(anyhow!(
"update secret not supported for provider {}",
self.name()
))
}
fn delete_secret(&self, key: &str) -> Result<()>; fn delete_secret(&self, key: &str) -> Result<()>;
fn list_secrets(&self) -> Result<Vec<String>>; fn list_secrets(&self) -> Result<Vec<String>> {
Err(anyhow!(
"list secrets is not supported for the provider {}",
self.name()
))
}
fn sync(&self, config: &mut Config) -> Result<()>; fn sync(&self, config: &mut Config) -> Result<()>;
} }