Skip to content

Commit 2c33732

Browse files
authored
fix(option): remove option.WithAuthCredentials from validation (#3420)
Do not raise multiple credential options provided error when option.WithAuthCredentials is provided with other auth configuration options, as it is a special case used internally for oauth2 type converversions. refs: googleapis/google-cloud-go#13503
1 parent 75e055a commit 2c33732

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

internal/settings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func (ds *DialSettings) Validate() error {
165165
return errors.New("options.WithoutAuthentication is incompatible with any option that provides credentials")
166166
}
167167
// Credentials should not appear with other options.
168+
// AuthCredentials is a special case that may be present with
169+
// with other options in order to facilitate automatic conversion of
170+
// oauth2 types (old auth) to cloud.google.com/go/auth types (new auth).
168171
// We currently allow TokenSource and CredentialsFile to coexist.
169172
// TODO(jba): make TokenSource & CredentialsFile an error (breaking change).
170173
nCreds := 0
@@ -174,9 +177,6 @@ func (ds *DialSettings) Validate() error {
174177
if len(ds.CredentialsJSON) > 0 {
175178
nCreds++
176179
}
177-
if ds.AuthCredentials != nil {
178-
nCreds++
179-
}
180180
if len(ds.AuthCredentialsJSON) > 0 {
181181
nCreds++
182182
}

internal/settings_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func TestSettingsValidate(t *testing.T) {
2929
{Scopes: []string{"s"}},
3030
{CredentialsFile: "f"},
3131
{TokenSource: dummyTS{}},
32-
{CredentialsFile: "f", TokenSource: dummyTS{}}, // keep for backwards compatibility
32+
{Credentials: &google.DefaultCredentials{}, AuthCredentials: &auth.Credentials{}}, // Support old auth to new auth automatic conversions
33+
{CredentialsFile: "f", AuthCredentials: &auth.Credentials{}}, // Support old auth to new auth automatic conversions
34+
{CredentialsFile: "f", TokenSource: dummyTS{}}, // keep for backwards compatibility
3335
{CredentialsJSON: []byte("json")},
3436
{AuthCredentialsFile: "f"},
3537
{AuthCredentialsJSON: []byte("json")},
@@ -56,6 +58,7 @@ func TestSettingsValidate(t *testing.T) {
5658
{NoAuth: true, AuthCredentialsFile: "f"},
5759
{NoAuth: true, TokenSource: dummyTS{}},
5860
{NoAuth: true, Credentials: &google.DefaultCredentials{}},
61+
{NoAuth: true, AuthCredentials: &auth.Credentials{}},
5962
{NoAuth: true, AuthCredentialsJSON: []byte("json")},
6063
{Credentials: &google.DefaultCredentials{}, CredentialsFile: "f"},
6164
{Credentials: &google.DefaultCredentials{}, AuthCredentialsFile: "f"},

0 commit comments

Comments
 (0)