feat(GODT-3172): detect missing keychain item

This commit is contained in:
Jakub
2024-01-04 08:28:17 +01:00
committed by Jakub Cuth
parent 89bb7b6389
commit 9b1daa0373
5 changed files with 41 additions and 5 deletions

View File

@ -41,8 +41,14 @@ var (
// ErrMacKeychainRebuild is returned on macOS with blocked or corrupted keychain.
ErrMacKeychainRebuild = errors.New("keychain error -25293")
ErrKeychainNoItem = errors.New("no such keychain item")
)
func IsErrKeychainNoItem(err error) bool {
return errors.Is(err, ErrKeychainNoItem) || credentials.IsErrCredentialsNotFound(err)
}
type Helpers map[string]helperConstructor
type List struct {
@ -173,7 +179,16 @@ func (kc *Keychain) Get(userID string) (string, string, error) {
kc.locker.Lock()
defer kc.locker.Unlock()
return kc.helper.Get(kc.secretURL(userID))
id, key, err := kc.helper.Get(kc.secretURL(userID))
if err != nil {
return id, key, err
}
if key == "" {
return id, key, ErrKeychainNoItem
}
return id, key, err
}
func (kc *Keychain) Put(userID, secret string) error {