Skip to content

Commit

Permalink
Support credential JSON for Spanner
Browse files Browse the repository at this point in the history
Closes authzed#1941

Signed-off-by: Lex Cao <[email protected]>
  • Loading branch information
lexcao committed Jun 15, 2024
1 parent ebe0417 commit 59c478a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/datastore/spanner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type spannerOptions struct {
followerReadDelay time.Duration
maxRevisionStalenessPercent float64
credentialsFilePath string
credentialsJSON []byte
emulatorHost string
disableStats bool
readMaxOpen int
Expand Down Expand Up @@ -141,6 +142,14 @@ func CredentialsFile(path string) Option {
}
}

// CredentialsJSON is the json containing credentials for a service
// account that can access the cloud spanner instance
func CredentialsJSON(json []byte) Option {
return func(so *spannerOptions) {
so.credentialsJSON = json
}
}

// EmulatorHost is the URI of a Spanner emulator to connect to for
// development and testing use
func EmulatorHost(uri string) Option {
Expand Down
1 change: 1 addition & 0 deletions internal/datastore/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func NewSpannerDatastore(ctx context.Context, database string, opts ...Option) (
client, err := spanner.NewClientWithConfig(context.Background(), database,
spanner.ClientConfig{SessionPoolConfig: cfg},
option.WithCredentialsFile(config.credentialsFilePath),
option.WithCredentialsJSON(config.credentialsJSON),
option.WithGRPCConnectionPool(max(config.readMaxOpen, config.writeMaxOpen)),
option.WithGRPCDialOption(
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
Expand Down

0 comments on commit 59c478a

Please sign in to comment.