Skip to content

Commit b47af27

Browse files
committed
fix: parse string and file credentials in uniform way
The Google backend key parsing implementation used JWTConfigFromJSON() when the key is specified as a JSON string, and this only works with service account credentials. In contrast, when setting the key to the path of a file containing the JSON credentials we use the environment GOOGLE_APPLICATION_CREDENTIALS, which also accepts authorized user credentials. Change the JSON string key parsing to use CredentialsFromJSON() to match the functionality of reading the JSON from a file, allowing the use of authorized user credentials with string keys. Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
1 parent 9377006 commit b47af27

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

spread/google.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"golang.org/x/net/context"
1717
"golang.org/x/oauth2"
1818
"golang.org/x/oauth2/google"
19-
"golang.org/x/oauth2/jwt"
2019

2120
"github.com/niemeyer/pretty"
2221
"regexp"
@@ -777,10 +776,9 @@ func (p *googleProvider) checkKey() error {
777776
if err == nil && p.client == nil {
778777
ctx := context.Background()
779778
if strings.HasPrefix(p.backend.Key, "{") {
780-
var cfg *jwt.Config
781-
cfg, err = google.JWTConfigFromJSON([]byte(p.backend.Key), googleScope)
779+
creds, err := google.CredentialsFromJSON(ctx, []byte(p.backend.Key), googleScope)
782780
if err == nil {
783-
p.client = oauth2.NewClient(ctx, cfg.TokenSource(ctx))
781+
p.client = oauth2.NewClient(ctx, creds.TokenSource)
784782
}
785783
} else {
786784
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", p.backend.Key)

0 commit comments

Comments
 (0)