mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
pvsecret: Warn during add if a secret-id is already in the store
Warn a user that the secret-id to be added is already in the secret store, but add it anyways. This helps users to notice issues before they happen, as retrieve may not retrieve the expected secret due to duplicated IDs. Reviewed-by: Finn Callies <fcallies@linux.ibm.com> Tested-by: Finn Callies <fcallies@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
0eac97542d
commit
fa00d1eac1
@@ -2,18 +2,29 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use crate::cli::AddSecretOpt;
|
||||
use crate::{cli::AddSecretOpt, cmd::list::list_uvc};
|
||||
use anyhow::{Context, Result};
|
||||
use log::warn;
|
||||
use pv::uv::{AddCmd, UvDevice};
|
||||
use pv::{
|
||||
secret::AddSecretRequest,
|
||||
uv::{AddCmd, UvCmd, UvDevice},
|
||||
};
|
||||
use utils::get_reader_from_cli_file_arg;
|
||||
|
||||
/// Do an Add Secret UVC
|
||||
pub fn add(opt: &AddSecretOpt) -> Result<()> {
|
||||
let uv = UvDevice::open()?;
|
||||
let mut rd_in = get_reader_from_cli_file_arg(&opt.input)?;
|
||||
let mut cmd =
|
||||
AddCmd::new(&mut rd_in).context(format!("Processing input file {}", opt.input))?;
|
||||
UvDevice::open()?.send_cmd(&mut cmd)?;
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
uv.send_cmd(&mut cmd)?;
|
||||
warn!("Successfully added the secret");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user