Skip to content

Commit

Permalink
Revert "fix: Update config.go and framework_config.go to use transpor…
Browse files Browse the repository at this point in the history
…t.Creds for all cases" (#7948)
  • Loading branch information
shuyama1 authored May 16, 2023
1 parent 21a919d commit b2d535b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func GetCredentials(ctx context.Context, data ProviderModel, initialCredentialsO
return *creds
}

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

tflog.Info(ctx, "Authenticating using DefaultClient...")
tflog.Info(ctx, fmt.Sprintf(" -- Scopes: %s", clientScopes))
creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...))
defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...)
if err != nil {
diags.AddError(fmt.Sprintf("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'"), err.Error())
return googleoauth.Credentials{}
}

return *creds
return googleoauth.Credentials{
TokenSource: defaultTS,
}
}
8 changes: 5 additions & 3 deletions mmv1/third_party/terraform/transport/config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ func (c *Config) GetCredentials(clientScopes []string, initialCredentialsOnly bo
return *creds, nil
}

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

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

return *creds, nil
return googleoauth.Credentials{
TokenSource: defaultTS,
}, err
}

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

0 comments on commit b2d535b

Please sign in to comment.