Skip to content

Commit

Permalink
fix: don't error if we can't access the keyring
Browse files Browse the repository at this point in the history
Use of the keyring to cache credentials is just for convenience.
  • Loading branch information
alecthomas committed Sep 23, 2023
1 parent 7499d47 commit 2f978fe
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions authn/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetAuthenticationHeaders(ctx context.Context, endpoint *url.URL, authentica
if errors.Is(err, keyring.ErrNotFound) {
logger.Tracef("No credentials found in keyring")
} else if err != nil {
return nil, errors.WithStack(err)
logger.Debugf("Failed to get credentials from keyring: %s", err)
} else {
logger.Tracef("Credentials found in keyring: %s", creds)
if headers, err := checkAuth(ctx, logger, endpoint, creds); err != nil {
Expand All @@ -75,24 +75,25 @@ func GetAuthenticationHeaders(ctx context.Context, endpoint *url.URL, authentica
}

creds = out.String()
if headers, err := checkAuth(ctx, logger, endpoint, creds); err != nil {
headers, err := checkAuth(ctx, logger, endpoint, creds)
if err != nil {
return nil, errors.WithStack(err)
} else if headers != nil {
logger.Debugf("Authenticator %s succeeded", authenticator)
w := &strings.Builder{}
for name, values := range headers {
for _, value := range values {
fmt.Fprintf(w, "%s: %s\r\n", name, value)
}
}
err = keyring.Set(keyringKey, usr.Name, w.String())
if err != nil {
logger.Warnf("Failed to save credentials to keyring: %s", err)
}
return headers, nil
} else if headers == nil {
return nil, nil
}

return nil, nil
logger.Debugf("Authenticator %s succeeded", authenticator)
w := &strings.Builder{}
for name, values := range headers {
for _, value := range values {
fmt.Fprintf(w, "%s: %s\r\n", name, value)
}
}
err = keyring.Set(keyringKey, usr.Name, w.String())
if err != nil {
logger.Debugf("Failed to save credentials to keyring: %s", err)
}
return headers, nil
}

// Check credentials and return authenticating headers if we're able to successfully authenticate.
Expand Down

0 comments on commit 2f978fe

Please sign in to comment.