Skip to content

Commit

Permalink
tfprovider: support intercepting GRPC requests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Apr 26, 2024
1 parent 179b98a commit eb371a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"cloud.google.com/go/bigtable"
"golang.org/x/oauth2"
"google.golang.org/api/option"
"google.golang.org/grpc"
)

type BigtableClientFactory struct {
Expand All @@ -32,6 +33,10 @@ func (s BigtableClientFactory) NewInstanceAdminClient(project string) (*bigtable
opts = append(opts, option.WithTokenSource(s.TokenSource), option.WithUserAgent(s.UserAgent))
opts = append(opts, s.gRPCLoggingOptions...)

if GRPCUnaryClientInterceptor != nil {
opts = append(opts, option.WithGRPCDialOption(grpc.WithUnaryInterceptor(GRPCUnaryClientInterceptor)))
}

return bigtable.NewInstanceAdminClient(context.Background(), project, opts...)
}

Expand All @@ -48,6 +53,10 @@ func (s BigtableClientFactory) NewAdminClient(project, instance string) (*bigtab
opts = append(opts, option.WithTokenSource(s.TokenSource), option.WithUserAgent(s.UserAgent))
opts = append(opts, s.gRPCLoggingOptions...)

if GRPCUnaryClientInterceptor != nil {
opts = append(opts, option.WithGRPCDialOption(grpc.WithUnaryInterceptor(GRPCUnaryClientInterceptor)))
}

return bigtable.NewAdminClient(context.Background(), project, instance, opts...)
}

Expand All @@ -64,5 +73,9 @@ func (s BigtableClientFactory) NewClient(project, instance string) (*bigtable.Cl
opts = append(opts, option.WithTokenSource(s.TokenSource), option.WithUserAgent(s.UserAgent))
opts = append(opts, s.gRPCLoggingOptions...)

if GRPCUnaryClientInterceptor != nil {
opts = append(opts, option.WithGRPCDialOption(grpc.WithUnaryInterceptor(GRPCUnaryClientInterceptor)))
}

return bigtable.NewClient(context.Background(), project, instance, opts...)
}
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ var DefaultHTTPClientTransformer func(ctx context.Context, inner *http.Client) *
// This is very handy in tests, for example.
var OAuth2HTTPClientTransformer func(ctx context.Context, inner *http.Client) *http.Client = nil

var GRPCUnaryClientInterceptor grpc.UnaryClientInterceptor //func(ctx context.Context) *grpc.ClientConn

func HandleSDKDefaults(d *schema.ResourceData) error {
if d.Get("impersonate_service_account") == "" {
d.Set("impersonate_service_account", MultiEnvDefault([]string{
Expand Down

0 comments on commit eb371a4

Please sign in to comment.