Skip to content

Commit cbbb5b0

Browse files
authored
Merge pull request #1948 from lexcao/fix/spanner-empty-json
Fix empty value on optional credentialsJSON for Spanner
2 parents c965f1d + d1fc4ee commit cbbb5b0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

internal/datastore/spanner/spanner.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,26 @@ func NewSpannerDatastore(ctx context.Context, database string, opts ...Option) (
141141
cfg := spanner.DefaultSessionPoolConfig
142142
cfg.MinOpened = config.minSessions
143143
cfg.MaxOpened = config.maxSessions
144-
client, err := spanner.NewClientWithConfig(context.Background(), database,
145-
spanner.ClientConfig{SessionPoolConfig: cfg},
144+
145+
var spannerOpts []option.ClientOption
146+
if config.credentialsJSON != nil {
147+
spannerOpts = append(spannerOpts, option.WithCredentialsJSON(config.credentialsJSON))
148+
}
149+
150+
spannerOpts = append(spannerOpts,
146151
option.WithCredentialsFile(config.credentialsFilePath),
147-
option.WithCredentialsJSON(config.credentialsJSON),
148152
option.WithGRPCConnectionPool(max(config.readMaxOpen, config.writeMaxOpen)),
149153
option.WithGRPCDialOption(
150154
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
151155
),
152156
)
157+
158+
client, err := spanner.NewClientWithConfig(
159+
context.Background(),
160+
database,
161+
spanner.ClientConfig{SessionPoolConfig: cfg},
162+
spannerOpts...,
163+
)
153164
if err != nil {
154165
return nil, common.RedactAndLogSensitiveConnString(ctx, errUnableToInstantiate, err, database)
155166
}

0 commit comments

Comments
 (0)