Skip to content

Commit 53a6ae0

Browse files
authored
fix: credentials: check for not found errors properly (#899)
Signed-off-by: Grant Linville <[email protected]>
1 parent 2e26a10 commit 53a6ae0

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

pkg/credentials/error.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package credentials
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func IsCredentialsNotFoundError(err error) bool {
8+
if err == nil {
9+
return false
10+
}
11+
return strings.Contains(err.Error(), "credentials not found in native keychain")
12+
}

pkg/credentials/store.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/docker/cli/cli/config/credentials"
1010
"github.com/docker/cli/cli/config/types"
1111
"github.com/docker/docker-credential-helpers/client"
12-
credentials2 "github.com/docker/docker-credential-helpers/credentials"
1312
"github.com/gptscript-ai/gptscript/pkg/config"
1413
"golang.org/x/exp/maps"
1514
)
@@ -50,7 +49,7 @@ func (s Store) Get(_ context.Context, toolName string) (*Credential, bool, error
5049
for _, c := range s.credCtxs {
5150
auth, err := store.Get(toolNameWithCtx(toolName, c))
5251
if err != nil {
53-
if credentials2.IsErrCredentialsNotFound(err) {
52+
if IsCredentialsNotFoundError(err) {
5453
continue
5554
}
5655
return nil, false, err

pkg/credentials/toolstore.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (h *toolCredentialStore) Erase(serverAddress string) error {
3030

3131
func (h *toolCredentialStore) Get(serverAddress string) (types.AuthConfig, error) {
3232
creds, err := client.Get(h.program, serverAddress)
33-
if credentials2.IsErrCredentialsNotFound(err) {
33+
if IsCredentialsNotFoundError(err) {
3434
return h.file.Get(serverAddress)
3535
} else if err != nil {
3636
return types.AuthConfig{}, err

pkg/runner/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
872872
} else if credentialAlias != "" {
873873
c, exists, err = r.credStore.Get(callCtx.Ctx, credentialAlias)
874874
if err != nil {
875-
return nil, fmt.Errorf("failed to get credentials for tool %s: %w", credentialAlias, err)
875+
return nil, fmt.Errorf("failed to get credential %s: %w", credentialAlias, err)
876876
}
877877
}
878878

0 commit comments

Comments
 (0)