Skip to content

Commit

Permalink
feat(datastore): Configure both mTLS and TLS endpoints for Datastore …
Browse files Browse the repository at this point in the history
…client (#9653)

* feat(datastore): Configure both mTLS and TLS endpoints for Datastore client

* feat(datastore): Using endpoint template and universe domain
  • Loading branch information
bhshkh committed Apr 16, 2024
1 parent 54d2990 commit 38bd793
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"cloud.google.com/go/internal/trace"
"google.golang.org/api/option"
"google.golang.org/api/option/internaloption"
"google.golang.org/api/transport"
gtransport "google.golang.org/api/transport/grpc"
pb "google.golang.org/genproto/googleapis/datastore/v1"
Expand All @@ -33,8 +34,10 @@ import (
)

const (
prodAddr = "datastore.googleapis.com:443"
userAgent = "gcloud-golang-datastore/20160401"
prodEndpointTemplate = "datastore.UNIVERSE_DOMAIN:443"
prodUniverseDomain = "googleapis.com"
prodMtlsAddr = "datastore.mtls.googleapis.com:443"
userAgent = "gcloud-golang-datastore/20160401"
)

// ScopeDatastore grants permissions to view and/or manage datastore entities
Expand Down Expand Up @@ -102,7 +105,9 @@ func NewClientWithDatabase(ctx context.Context, projectID, databaseID string, op
// If the emulator is available, dial it without passing any credentials.
if addr := os.Getenv("DATASTORE_EMULATOR_HOST"); addr != "" {
o = []option.ClientOption{
option.WithEndpoint(addr),
internaloption.WithDefaultEndpointTemplate(prodEndpointTemplate),
internaloption.WithDefaultUniverseDomain(prodUniverseDomain),
internaloption.WithDefaultMTLSEndpoint(prodMtlsAddr),
option.WithoutAuthentication(),
option.WithGRPCDialOption(grpc.WithInsecure()),
}
Expand All @@ -114,7 +119,9 @@ func NewClientWithDatabase(ctx context.Context, projectID, databaseID string, op
}
} else {
o = []option.ClientOption{
option.WithEndpoint(prodAddr),
internaloption.WithDefaultEndpointTemplate(prodEndpointTemplate),
internaloption.WithDefaultUniverseDomain(prodUniverseDomain),
internaloption.WithDefaultMTLSEndpoint(prodMtlsAddr),
option.WithScopes(ScopeDatastore),
option.WithUserAgent(userAgent),
}
Expand Down

0 comments on commit 38bd793

Please sign in to comment.