Skip to content

Commit

Permalink
add option.ClientOption for Spanner clients to wrench config (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazegusuri authored Sep 17, 2023
1 parent c0cfaef commit 64fe17b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ type Client struct {
spannerAdminClient *databasev1.DatabaseAdminClient
}

func NewClient(ctx context.Context, config *Config, opts ...option.ClientOption) (*Client, error) {
func NewClient(ctx context.Context, config *Config) (*Client, error) {
var opts []option.ClientOption

// The options passed by config are evaluated first.
// Most options are last win so the options can be overridden by another option.
opts = append(opts, config.ClientOptions...)

if config.CredentialsFile != "" {
opts = append(opts, option.WithCredentialsFile(config.CredentialsFile))
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/spanner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@

package spanner

import "fmt"
import (
"fmt"

"google.golang.org/api/option"
)

type Config struct {
Project string
Instance string
Database string
CredentialsFile string

// ClientOptions is options of Spanner clients when creating the clients for both normal
// and admin. This options are evaluated first and can be overridden by other
// configurations in Wrench.
//
// Experimental: There will be a breaking change in the future versions.
ClientOptions []option.ClientOption
}

func (c *Config) URL() string {
Expand Down

0 comments on commit 64fe17b

Please sign in to comment.