Skip to content

Commit f0cfd05

Browse files
authored
fix(all): Update hand-written clients to not use WithEndpoint override (#3111)
-logging clients delegate to the gapic generated client with the correct defaults, so no need to override. -bigtable and spanner clients needs to be manually updated to use DefaultEndpoint and DefaultMTLSEndpoint
1 parent 751afe6 commit f0cfd05

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

bigtable/admin.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
)
4545

4646
const adminAddr = "bigtableadmin.googleapis.com:443"
47+
const mtlsAdminAddr = "bigtableadmin.mtls.googleapis.com:443"
4748

4849
// ErrPartiallyUnavailable is returned when some locations (clusters) are
4950
// unavailable. Both partial results (retrieved from available locations)
@@ -70,7 +71,7 @@ type AdminClient struct {
7071

7172
// NewAdminClient creates a new AdminClient for a given project and instance.
7273
func NewAdminClient(ctx context.Context, project, instance string, opts ...option.ClientOption) (*AdminClient, error) {
73-
o, err := btopt.DefaultClientOptions(adminAddr, AdminScope, clientUserAgent)
74+
o, err := btopt.DefaultClientOptions(adminAddr, mtlsAdminAddr, AdminScope, clientUserAgent)
7475
if err != nil {
7576
return nil, err
7677
}
@@ -603,6 +604,7 @@ func (ac *AdminClient) TableIAM(tableID string) *iam.Handle {
603604
}
604605

605606
const instanceAdminAddr = "bigtableadmin.googleapis.com:443"
607+
const mtlsInstanceAdminAddr = "bigtableadmin.mtls.googleapis.com:443"
606608

607609
// InstanceAdminClient is a client type for performing admin operations on instances.
608610
// These operations can be substantially more dangerous than those provided by AdminClient.
@@ -619,7 +621,7 @@ type InstanceAdminClient struct {
619621

620622
// NewInstanceAdminClient creates a new InstanceAdminClient for a given project.
621623
func NewInstanceAdminClient(ctx context.Context, project string, opts ...option.ClientOption) (*InstanceAdminClient, error) {
622-
o, err := btopt.DefaultClientOptions(instanceAdminAddr, InstanceAdminScope, clientUserAgent)
624+
o, err := btopt.DefaultClientOptions(instanceAdminAddr, mtlsInstanceAdminAddr, InstanceAdminScope, clientUserAgent)
623625
if err != nil {
624626
return nil, err
625627
}

bigtable/bigtable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
)
4040

4141
const prodAddr = "bigtable.googleapis.com:443"
42+
const mtlsProdAddr = "bigtable.mtls.googleapis.com:443"
4243

4344
// Client is a client for reading and writing data to tables in an instance.
4445
//
@@ -65,7 +66,7 @@ func NewClient(ctx context.Context, project, instance string, opts ...option.Cli
6566

6667
// NewClientWithConfig creates a new client with the given config.
6768
func NewClientWithConfig(ctx context.Context, project, instance string, config ClientConfig, opts ...option.ClientOption) (*Client, error) {
68-
o, err := btopt.DefaultClientOptions(prodAddr, Scope, clientUserAgent)
69+
o, err := btopt.DefaultClientOptions(prodAddr, mtlsProdAddr, Scope, clientUserAgent)
6970
if err != nil {
7071
return nil, err
7172
}

bigtable/export_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ var headersInterceptor = testutil.DefaultHeadersEnforcer()
138138

139139
// NewAdminClient builds a new connected admin client for this environment
140140
func (e *EmulatedEnv) NewAdminClient() (*AdminClient, error) {
141-
o, err := btopt.DefaultClientOptions(e.server.Addr, AdminScope, clientUserAgent)
141+
o, err := btopt.DefaultClientOptions(e.server.Addr, e.server.Addr, AdminScope, clientUserAgent)
142142
if err != nil {
143143
return nil, err
144144
}
@@ -170,7 +170,7 @@ func (e *EmulatedEnv) NewInstanceAdminClient() (*InstanceAdminClient, error) {
170170

171171
// NewClient builds a new connected data client for this environment
172172
func (e *EmulatedEnv) NewClient() (*Client, error) {
173-
o, err := btopt.DefaultClientOptions(e.server.Addr, Scope, clientUserAgent)
173+
o, err := btopt.DefaultClientOptions(e.server.Addr, e.server.Addr, Scope, clientUserAgent)
174174
if err != nil {
175175
return nil, err
176176
}

bigtable/internal/option/option.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"cloud.google.com/go/internal/version"
2626
gax "github.com/googleapis/gax-go/v2"
2727
"google.golang.org/api/option"
28+
"google.golang.org/api/option/internaloption"
2829
"google.golang.org/grpc"
2930
"google.golang.org/grpc/metadata"
3031
)
@@ -76,7 +77,7 @@ func unaryInterceptor(ctx context.Context, method string, req, reply interface{}
7677

7778
// DefaultClientOptions returns the default client options to use for the
7879
// client's gRPC connection.
79-
func DefaultClientOptions(endpoint, scope, userAgent string) ([]option.ClientOption, error) {
80+
func DefaultClientOptions(endpoint, mtlsEndpoint, scope, userAgent string) ([]option.ClientOption, error) {
8081
var o []option.ClientOption
8182
// Check the environment variables for the bigtable emulator.
8283
// Dial it directly and don't pass any credentials.
@@ -88,7 +89,8 @@ func DefaultClientOptions(endpoint, scope, userAgent string) ([]option.ClientOpt
8889
o = []option.ClientOption{option.WithGRPCConn(conn)}
8990
} else {
9091
o = []option.ClientOption{
91-
option.WithEndpoint(endpoint),
92+
internaloption.WithDefaultEndpoint(endpoint),
93+
internaloption.WithDefaultMTLSEndpoint(mtlsEndpoint),
9294
option.WithScopes(scope),
9395
option.WithUserAgent(userAgent),
9496
}

logging/logadmin/logadmin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func NewClient(ctx context.Context, parent string, opts ...option.ClientOption)
6666
parent = "projects/" + parent
6767
}
6868
opts = append([]option.ClientOption{
69-
option.WithEndpoint(internal.ProdAddr),
7069
option.WithScopes(logging.AdminScope),
7170
}, opts...)
7271
lc, err := vkit.NewClient(ctx, opts...)

logging/logging.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func NewClient(ctx context.Context, parent string, opts ...option.ClientOption)
141141
parent = "projects/" + parent
142142
}
143143
opts = append([]option.ClientOption{
144-
option.WithEndpoint(internal.ProdAddr),
145144
option.WithScopes(WriteScope),
146145
}, opts...)
147146
c, err := vkit.NewClient(ctx, opts...)

spanner/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import (
3636
)
3737

3838
const (
39-
endpoint = "spanner.googleapis.com:443"
39+
endpoint = "spanner.googleapis.com:443"
40+
mtlsEndpoint = "spanner.mtls.googleapis.com:443"
4041

4142
// resourcePrefixHeader is the name of the metadata header used to indicate
4243
// the resource being operated on.
@@ -166,7 +167,8 @@ func NewClientWithConfig(ctx context.Context, database string, config ClientConf
166167
}
167168
// gRPC options.
168169
allOpts := []option.ClientOption{
169-
option.WithEndpoint(endpoint),
170+
internaloption.WithDefaultEndpoint(endpoint),
171+
internaloption.WithDefaultMTLSEndpoint(mtlsEndpoint),
170172
option.WithScopes(Scope),
171173
option.WithGRPCDialOption(
172174
grpc.WithDefaultCallOptions(

0 commit comments

Comments
 (0)