diff --git a/rust/pvsecret/src/cli.rs b/rust/pvsecret/src/cli.rs index 6271b8fa..a0910201 100644 --- a/rust/pvsecret/src/cli.rs +++ b/rust/pvsecret/src/cli.rs @@ -262,6 +262,13 @@ pub struct AddSecretOpt { #[arg(value_name = "FILE", value_hint = ValueHint::FilePath,)] #[cfg(target_arch = "s390x")] pub input: String, + + /// Force the addition of add-secret requests. + /// + /// Add an add-secret request even if there is already a secret with the same ID in the secret + /// store. + #[arg(short, long)] + pub force: bool, } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug, Default)] diff --git a/rust/pvsecret/src/cmd/add.rs b/rust/pvsecret/src/cmd/add.rs index 81fd2730..50ea6d64 100644 --- a/rust/pvsecret/src/cmd/add.rs +++ b/rust/pvsecret/src/cmd/add.rs @@ -3,7 +3,7 @@ // Copyright IBM Corp. 2023 use crate::{cli::AddSecretOpt, cmd::list::list_uvc}; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use log::warn; use pv::{ secret::AddSecretRequest, @@ -20,7 +20,11 @@ pub fn add(opt: &AddSecretOpt) -> Result<()> { if let Some(id) = AddSecretRequest::bin_id(cmd.data().unwrap())? { if list_uvc(&uv)?.iter().any(|e| e.id() == id.as_ref()) { - warn!("There is already a secret in the secret store with that id. Adding the secret anyways."); + warn!("There is already a secret in the secret store with that id."); + match opt.force { + true => warn!("'--force' specified: Adding the secret anyways."), + false => bail!("Unable to add the secret due to duplicated IDs"), + } } }