From 839de2255f57ac5af1321327f280f79471825bc9 Mon Sep 17 00:00:00 2001 From: Cody Oss Date: Mon, 8 May 2023 16:10:46 -0500 Subject: [PATCH] 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 Reviewed-by: Russ Cox Auto-Submit: Cody Oss TryBot-Result: Gopher Robot --- google/default.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/google/default.go b/google/default.go index b3e8783..2cf71f0 100644 --- a/google/default.go +++ b/google/default.go @@ -8,7 +8,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -142,10 +141,8 @@ func FindDefaultCredentialsWithParams(ctx context.Context, params CredentialsPar // Second, try a well-known file. filename := wellKnownFile() - if creds, err := readCredentialsFile(ctx, filename, params); err == nil { - return creds, nil - } else if !os.IsNotExist(err) { - return nil, fmt.Errorf("google: error getting credentials using well-known file (%v): %v", filename, err) + if b, err := os.ReadFile(filename); err == nil { + return CredentialsFromJSONWithParams(ctx, b, params) } // 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) { - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) if err != nil { return nil, err }