Skip to content

Commit f4b8a85

Browse files
committed
osxkeychain: improve error message for non-interactive sessions
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent f78081d commit f4b8a85

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

osxkeychain/osxkeychain_darwin.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ import (
2121
// when the credentials are not in the keychain.
2222
const errCredentialsNotFound = "The specified item could not be found in the keychain."
2323

24+
// errCredentialsNotFound is the specific error message returned by OS X
25+
// when environment does not allow showing dialog to unlock keychain.
26+
const errInteractionNotAllowed = "User interaction is not allowed."
27+
28+
// ErrInteractionNotAllowed is returned if keychain password prompt can not be shown.
29+
var ErrInteractionNotAllowed = errors.New(`keychain cannot be accessed because the current session does not allow user interaction. The keychain may be locked; unlock it by running "security -v unlock-keychain ~/Library/Keychains/login.keychain-db" and try again`)
30+
2431
// Osxkeychain handles secrets using the OS X Keychain as store.
2532
type Osxkeychain struct{}
2633

@@ -89,6 +96,9 @@ func (h Osxkeychain) Get(serverURL string) (string, string, error) {
8996
if goMsg == errCredentialsNotFound {
9097
return "", "", credentials.NewErrCredentialsNotFound()
9198
}
99+
if goMsg == errInteractionNotAllowed {
100+
return "", "", ErrInteractionNotAllowed
101+
}
92102

93103
return "", "", errors.New(goMsg)
94104
}
@@ -117,6 +127,9 @@ func (h Osxkeychain) List() (map[string]string, error) {
117127
if goMsg == errCredentialsNotFound {
118128
return make(map[string]string), nil
119129
}
130+
if goMsg == errInteractionNotAllowed {
131+
return nil, ErrInteractionNotAllowed
132+
}
120133

121134
return nil, errors.New(goMsg)
122135
}

0 commit comments

Comments
 (0)