Skip to content

Commit

Permalink
added GOOGLE_OAUTH2_ACCESS_TOKEN to filestate loging for gcloud bucke…
Browse files Browse the repository at this point in the history
…t storage
  • Loading branch information
phillipedwards committed Feb 3, 2023
1 parent 486b364 commit 4917ca2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/authhelpers/gcpauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"cloud.google.com/go/storage"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"

"gocloud.dev/blob/gcsblob"
Expand All @@ -32,13 +33,23 @@ func ResolveGoogleCredentials(ctx context.Context, scope string) (*google.Creden
if creds := os.Getenv("GOOGLE_CREDENTIALS"); creds != "" {
// We try $GOOGLE_CREDENTIALS before gcp.DefaultCredentials
// so that users can override the default creds

credentials, err := google.CredentialsFromJSON(ctx, []byte(creds), scope)
if err != nil {
return nil, fmt.Errorf("unable to parse credentials from $GOOGLE_CREDENTIALS: %w", err)
}
return credentials, nil
}

if creds := os.Getenv("GOOGLE_OAUTH_ACCESS_TOKEN"); creds != "" {
// We try $GOOGLE_OAUTH_ACCESS_TOKEN before gcp.DefaultCredentials
// so that users can override the default creds

return &google.Credentials{
TokenSource: oauth2.StaticTokenSource(&oauth2.Token{AccessToken: creds}),
}, nil
}

// DefaultCredentials will attempt to load creds in the following order:
// 1. a file located at $GOOGLE_APPLICATION_CREDENTIALS
// 2. application_default_credentials.json file in ~/.config/gcloud or $APPDATA\gcloud
Expand Down

0 comments on commit 4917ca2

Please sign in to comment.