From 2dc77a71f6fd3c7fc6bb66ad0d4f531698f1fde2 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:45:05 -0500 Subject: [PATCH] Remove secure store entry when removing identity --- cmd/soroban-cli/src/config/locator.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/soroban-cli/src/config/locator.rs b/cmd/soroban-cli/src/config/locator.rs index b6f5c75c1..c33646938 100644 --- a/cmd/soroban-cli/src/config/locator.rs +++ b/cmd/soroban-cli/src/config/locator.rs @@ -12,7 +12,12 @@ use std::{ }; use stellar_strkey::{Contract, DecodeError}; -use crate::{commands::HEADING_GLOBAL, utils::find_config_dir, Pwd}; +use crate::{ + commands::HEADING_GLOBAL, + signer::{self, keyring::StellarEntry}, + utils::find_config_dir, + Pwd, +}; use super::{ alias, @@ -83,6 +88,8 @@ pub enum Error { UpgradeCheckReadFailed { path: PathBuf, error: io::Error }, #[error("Failed to write upgrade check file: {path}: {error}")] UpgradeCheckWriteFailed { path: PathBuf, error: io::Error }, + #[error(transparent)] + Keyring(#[from] signer::keyring::Error), } #[derive(Debug, clap::Args, Default, Clone)] @@ -254,6 +261,22 @@ impl Args { } pub fn remove_identity(&self, name: &str) -> Result<(), Error> { + let identity = self.read_identity(name)?; + match identity { + Secret::SecureStore { entry_name } => { + let entry = StellarEntry::new(&entry_name)?; + let _ = entry.delete_password().map_err(|e| { + if e.to_string() == keyring::Error::NoEntry.to_string() { + println!("This key was already removed from the secure store. Removing the config file"); + return Ok(()); + } else { + Err(Error::Keyring(e)) + } + }); + } + _ => {} + } + KeyType::Identity.remove(name, &self.config_dir()?) }