mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
osxkeychain: use a switch for handling errors
Makes the error-handling slightly cleaner. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -93,16 +93,15 @@ func (h Osxkeychain) Get(serverURL string) (string, string, error) {
|
|||||||
errMsg := C.keychain_get(s, &usernameLen, &username, &secretLen, &secret)
|
errMsg := C.keychain_get(s, &usernameLen, &username, &secretLen, &secret)
|
||||||
if errMsg != nil {
|
if errMsg != nil {
|
||||||
defer C.free(unsafe.Pointer(errMsg))
|
defer C.free(unsafe.Pointer(errMsg))
|
||||||
goMsg := C.GoString(errMsg)
|
switch goMsg := C.GoString(errMsg); goMsg {
|
||||||
if goMsg == errCredentialsNotFound {
|
case errCredentialsNotFound:
|
||||||
return "", "", credentials.NewErrCredentialsNotFound()
|
return "", "", credentials.NewErrCredentialsNotFound()
|
||||||
}
|
case errInteractionNotAllowed:
|
||||||
if goMsg == errInteractionNotAllowed {
|
|
||||||
return "", "", ErrInteractionNotAllowed
|
return "", "", ErrInteractionNotAllowed
|
||||||
}
|
default:
|
||||||
|
|
||||||
return "", "", errors.New(goMsg)
|
return "", "", errors.New(goMsg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user := C.GoStringN(username, C.int(usernameLen))
|
user := C.GoStringN(username, C.int(usernameLen))
|
||||||
pass := C.GoStringN(secret, C.int(secretLen))
|
pass := C.GoStringN(secret, C.int(secretLen))
|
||||||
@@ -124,16 +123,15 @@ func (h Osxkeychain) List() (map[string]string, error) {
|
|||||||
defer C.freeListData(&acctsC, listLenC)
|
defer C.freeListData(&acctsC, listLenC)
|
||||||
if errMsg != nil {
|
if errMsg != nil {
|
||||||
defer C.free(unsafe.Pointer(errMsg))
|
defer C.free(unsafe.Pointer(errMsg))
|
||||||
goMsg := C.GoString(errMsg)
|
switch goMsg := C.GoString(errMsg); goMsg {
|
||||||
if goMsg == errCredentialsNotFound {
|
case errCredentialsNotFound:
|
||||||
return make(map[string]string), nil
|
return make(map[string]string), nil
|
||||||
}
|
case errInteractionNotAllowed:
|
||||||
if goMsg == errInteractionNotAllowed {
|
|
||||||
return nil, ErrInteractionNotAllowed
|
return nil, ErrInteractionNotAllowed
|
||||||
}
|
default:
|
||||||
|
|
||||||
return nil, errors.New(goMsg)
|
return nil, errors.New(goMsg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var listLen int
|
var listLen int
|
||||||
listLen = int(listLenC)
|
listLen = int(listLenC)
|
||||||
|
|||||||
Reference in New Issue
Block a user