refactor: changed removing secret from store returns error

This commit is contained in:
David Allen 2025-03-20 09:28:24 -06:00
parent 17350ab99b
commit e38402edc3
Signed by: towk
GPG key ID: 793B2924A49B3A3F
3 changed files with 11 additions and 4 deletions

View file

@ -102,10 +102,16 @@ func (l *LocalSecretStore) ListSecrets() (map[string]string, error) {
} }
// RemoveSecretByID removes the specified secretID stored locally // RemoveSecretByID removes the specified secretID stored locally
func (l *LocalSecretStore) RemoveSecretByID(secretID string) { func (l *LocalSecretStore) RemoveSecretByID(secretID string) error {
l.mu.RLock() l.mu.RLock()
// Let user know if there was nothing to delete
_, err := l.GetSecretByID(secretID)
if err != nil {
return err
}
delete(l.Secrets, secretID) delete(l.Secrets, secretID)
l.mu.RUnlock() l.mu.RUnlock()
return nil
} }
// openStore tries to create or open the LocalSecretStore based on the environment // openStore tries to create or open the LocalSecretStore based on the environment

View file

@ -4,5 +4,5 @@ type SecretStore interface {
GetSecretByID(secretID string) (string, error) GetSecretByID(secretID string) (string, error)
StoreSecretByID(secretID, secret string) error StoreSecretByID(secretID, secret string) error
ListSecrets() (map[string]string, error) ListSecrets() (map[string]string, error)
RemoveSecretByID(secretID string) RemoveSecretByID(secretID string) error
} }

View file

@ -29,6 +29,7 @@ func (s *StaticStore) ListSecrets() (map[string]string, error) {
}, nil }, nil
} }
func (s *StaticStore) RemoveSecretByID(secretID string) { func (s *StaticStore) RemoveSecretByID(secretID string) error {
// Nothing to do here, since nothing is being stored // Nothing to do here, since nothing is being stored. With different implementations, we could return an error when no secret is found for a specific ID.
return nil
} }