From 5380edeeb95b793aa433ead86f0d9898c0ae453d Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Tue, 5 Jan 2021 09:51:13 +0100 Subject: [PATCH] feat: only delete if the secret is present in the keychain --- pkg/keychain/keychain.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/keychain/keychain.go b/pkg/keychain/keychain.go index 6729977a..d07ccc9e 100644 --- a/pkg/keychain/keychain.go +++ b/pkg/keychain/keychain.go @@ -102,10 +102,19 @@ func (kc *Keychain) List() ([]string, error) { return userIDs, nil } -func (kc *Keychain) Delete(userID string) (err error) { +func (kc *Keychain) Delete(userID string) error { kc.locker.Lock() defer kc.locker.Unlock() + userIDsByURL, err := kc.helper.List() + if err != nil { + return err + } + + if _, ok := userIDsByURL[kc.secretURL(userID)]; !ok { + return nil + } + return kc.helper.Delete(kc.secretURL(userID)) }