forked from Mirrors/oauth2
google: don't check for IsNotExist for well-known file
There are cases when reading this file that a ENOTDIR is returned. Because of this it is safer to just fall-back when any error happens from reading the gcloud file. Change-Id: Ie8e45ad508643e900adb5c9787907aaa50cceb5d Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/493695 Run-TryBot: Cody Oss <codyoss@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Cody Oss <codyoss@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
0690208dba
commit
839de2255f
|
@ -8,7 +8,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -142,10 +141,8 @@ func FindDefaultCredentialsWithParams(ctx context.Context, params CredentialsPar
|
||||||
|
|
||||||
// Second, try a well-known file.
|
// Second, try a well-known file.
|
||||||
filename := wellKnownFile()
|
filename := wellKnownFile()
|
||||||
if creds, err := readCredentialsFile(ctx, filename, params); err == nil {
|
if b, err := os.ReadFile(filename); err == nil {
|
||||||
return creds, nil
|
return CredentialsFromJSONWithParams(ctx, b, params)
|
||||||
} else if !os.IsNotExist(err) {
|
|
||||||
return nil, fmt.Errorf("google: error getting credentials using well-known file (%v): %v", filename, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third, if we're on a Google App Engine standard first generation runtime (<= Go 1.9)
|
// Third, if we're on a Google App Engine standard first generation runtime (<= Go 1.9)
|
||||||
|
@ -231,7 +228,7 @@ func wellKnownFile() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readCredentialsFile(ctx context.Context, filename string, params CredentialsParams) (*Credentials, error) {
|
func readCredentialsFile(ctx context.Context, filename string, params CredentialsParams) (*Credentials, error) {
|
||||||
b, err := ioutil.ReadFile(filename)
|
b, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue