Skip to content

Commit

Permalink
Merge pull request #1948 from lexcao/fix/spanner-empty-json
Browse files Browse the repository at this point in the history
Fix empty value on optional credentialsJSON for Spanner
  • Loading branch information
vroldanbet authored Jun 19, 2024
2 parents c965f1d + d1fc4ee commit cbbb5b0
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/datastore/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,26 @@ func NewSpannerDatastore(ctx context.Context, database string, opts ...Option) (
cfg := spanner.DefaultSessionPoolConfig
cfg.MinOpened = config.minSessions
cfg.MaxOpened = config.maxSessions
client, err := spanner.NewClientWithConfig(context.Background(), database,
spanner.ClientConfig{SessionPoolConfig: cfg},

var spannerOpts []option.ClientOption
if config.credentialsJSON != nil {
spannerOpts = append(spannerOpts, option.WithCredentialsJSON(config.credentialsJSON))
}

spannerOpts = append(spannerOpts,
option.WithCredentialsFile(config.credentialsFilePath),
option.WithCredentialsJSON(config.credentialsJSON),
option.WithGRPCConnectionPool(max(config.readMaxOpen, config.writeMaxOpen)),
option.WithGRPCDialOption(
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
),
)

client, err := spanner.NewClientWithConfig(
context.Background(),
database,
spanner.ClientConfig{SessionPoolConfig: cfg},
spannerOpts...,
)
if err != nil {
return nil, common.RedactAndLogSensitiveConnString(ctx, errUnableToInstantiate, err, database)
}
Expand Down

0 comments on commit cbbb5b0

Please sign in to comment.