Skip to content

Commit 9120a8c

Browse files
modular-magicianshuyama1
authored andcommitted
Revert "fix: Update config.go and framework_config.go to use transport.Creds for all cases" (#7948) (#5640)
Signed-off-by: Modular Magician <[email protected]>
1 parent 2d27c83 commit 9120a8c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.changelog/7948.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
provider: fixed an issue where `google_client_config` datasource return `null` for `access_token`
3+
```

google-beta/framework_config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ func GetCredentials(ctx context.Context, data ProviderModel, initialCredentialsO
14941494
return *creds
14951495
}
14961496

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

15191519
tflog.Info(ctx, "Authenticating using DefaultClient...")
15201520
tflog.Info(ctx, fmt.Sprintf(" -- Scopes: %s", clientScopes))
1521-
creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...))
1521+
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
15221522
if err != nil {
15231523
diags.AddError(fmt.Sprintf("Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. "+
15241524
"No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'"), err.Error())
15251525
return googleoauth.Credentials{}
15261526
}
15271527

1528-
return *creds
1528+
return googleoauth.Credentials{
1529+
TokenSource: defaultTS,
1530+
}
15291531
}

google-beta/transport/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ func (c *Config) GetCredentials(clientScopes []string, initialCredentialsOnly bo
19221922
return *creds, nil
19231923
}
19241924

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

19451945
log.Printf("[INFO] Authenticating using DefaultClient...")
19461946
log.Printf("[INFO] -- Scopes: %s", clientScopes)
1947-
creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...))
1947+
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
19481948
if err != nil {
19491949
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)
19501950
}
19511951

1952-
return *creds, nil
1952+
return googleoauth.Credentials{
1953+
TokenSource: defaultTS,
1954+
}, err
19531955
}
19541956

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

0 commit comments

Comments
 (0)