refactor: changed removing secret from store returns error

This commit is contained in:
David Allen 2025-03-20 09:28:24 -06:00 committed by David Allen
parent c3e1b40e3b
commit 0333caa403
Signed by: towk
GPG key ID: 0430CDBE22619155
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
func (l *LocalSecretStore) RemoveSecretByID(secretID string) {
func (l *LocalSecretStore) RemoveSecretByID(secretID string) error {
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)
l.mu.RUnlock()
return nil
}
// 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)
StoreSecretByID(secretID, secret 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
}
func (s *StaticStore) RemoveSecretByID(secretID string) {
// Nothing to do here, since nothing is being stored
func (s *StaticStore) RemoveSecretByID(secretID string) error {
// 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
}