fix: secrets remove not updating local store and return error when not found

This commit is contained in:
David Allen 2025-03-20 10:17:33 -06:00 committed by David Allen
parent 0333caa403
commit 6ae0121af7
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -203,13 +203,22 @@ var secretsRemoveCmd = &cobra.Command{
Short: "Remove secrets by IDs from secret store.", Short: "Remove secrets by IDs from secret store.",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
for _, secretID := range args { for _, secretID := range args {
// open secret store from file
store, err := secrets.OpenStore(secretsFile) store, err := secrets.OpenStore(secretsFile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
store.RemoveSecretByID(secretID) // remove secret from store by it's ID
err = store.RemoveSecretByID(secretID)
if err != nil {
fmt.Println("failed to remove secret: ", err)
os.Exit(1)
}
// update store by saving to original file
secrets.SaveSecrets(secretsFile, store.(*secrets.LocalSecretStore).Secrets)
} }
}, },
} }