Skip to content

Commit 46158c5

Browse files
fix: Update config.go and framework_config.go to use transport.Creds for all cases (#7875) (#14550)
Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Riley Karson <[email protected]>
1 parent 751811a commit 46158c5

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

.changelog/7875.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
Update config.go and framework_config.go to use transport.Creds for all cases
3+
```

google/framework_config.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ func GetCredentials(ctx context.Context, data ProviderModel, initialCredentialsO
13591359
return *creds
13601360
}
13611361

1362-
creds, err := googleoauth.CredentialsFromJSON(ctx, []byte(contents), clientScopes...)
1362+
creds, err := transport.Creds(ctx, option.WithCredentialsJSON([]byte(contents)), option.WithScopes(clientScopes...))
13631363
if err != nil {
13641364
diags.AddError("unable to parse credentials", err.Error())
13651365
return googleoauth.Credentials{}
@@ -1383,14 +1383,12 @@ func GetCredentials(ctx context.Context, data ProviderModel, initialCredentialsO
13831383

13841384
tflog.Info(ctx, "Authenticating using DefaultClient...")
13851385
tflog.Info(ctx, fmt.Sprintf(" -- Scopes: %s", clientScopes))
1386-
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
1386+
creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...))
13871387
if err != nil {
13881388
diags.AddError(fmt.Sprintf("Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. "+
13891389
"No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'"), err.Error())
13901390
return googleoauth.Credentials{}
13911391
}
13921392

1393-
return googleoauth.Credentials{
1394-
TokenSource: defaultTS,
1395-
}
1393+
return *creds
13961394
}

google/transport/config.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ func (c *Config) GetCredentials(clientScopes []string, initialCredentialsOnly bo
17891789
return *creds, nil
17901790
}
17911791

1792-
creds, err := googleoauth.CredentialsFromJSON(c.Context, []byte(contents), clientScopes...)
1792+
creds, err := transport.Creds(c.Context, option.WithCredentialsJSON([]byte(contents)), option.WithScopes(clientScopes...))
17931793
if err != nil {
17941794
return googleoauth.Credentials{}, fmt.Errorf("unable to parse credentials from '%s': %s", contents, err)
17951795
}
@@ -1811,14 +1811,12 @@ func (c *Config) GetCredentials(clientScopes []string, initialCredentialsOnly bo
18111811

18121812
log.Printf("[INFO] Authenticating using DefaultClient...")
18131813
log.Printf("[INFO] -- Scopes: %s", clientScopes)
1814-
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
1814+
creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...))
18151815
if err != nil {
18161816
return googleoauth.Credentials{}, fmt.Errorf("Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'. Original error: %w", err)
18171817
}
18181818

1819-
return googleoauth.Credentials{
1820-
TokenSource: defaultTS,
1821-
}, err
1819+
return *creds, nil
18221820
}
18231821

18241822
// Remove the `/{{version}}/` from a base path if present.

0 commit comments

Comments
 (0)