Skip to content

Commit 58def4d

Browse files
Revert "Revert "fix: Update config.go and framework_config.go to use transport.Creds for all cases"" (#7955) (#5645)
Signed-off-by: Modular Magician <[email protected]>
1 parent d12a100 commit 58def4d

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

.changelog/7955.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 mtls transports were not used consistently
3+
```

google-beta/framework_config.go

Lines changed: 3 additions & 5 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 := googleoauth.CredentialsFromJSON(ctx, []byte(contents), clientScopes...)
1497+
creds, err := transport.Creds(ctx, option.WithCredentialsJSON([]byte(contents)), option.WithScopes(clientScopes...))
14981498
if err != nil {
14991499
diags.AddError("unable to parse credentials", err.Error())
15001500
return googleoauth.Credentials{}
@@ -1518,14 +1518,12 @@ 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-
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
1521+
creds, err := transport.Creds(context.Background(), option.WithScopes(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 googleoauth.Credentials{
1529-
TokenSource: defaultTS,
1530-
}
1528+
return *creds
15311529
}

google-beta/transport/config.go

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

19451945
log.Printf("[INFO] Authenticating using DefaultClient...")
19461946
log.Printf("[INFO] -- Scopes: %s", clientScopes)
1947-
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
1947+
creds, err := transport.Creds(context.Background(), option.WithScopes(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 googleoauth.Credentials{
1953-
TokenSource: defaultTS,
1954-
}, err
1952+
return *creds, nil
19551953
}
19561954

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

0 commit comments

Comments
 (0)