From eb371a4d2c26a123c170359c93cdd6aa1aa64a3b Mon Sep 17 00:00:00 2001 From: justinsb Date: Fri, 26 Apr 2024 11:29:14 -0400 Subject: [PATCH] tfprovider: support intercepting GRPC requests --- .../transport/bigtable_client_factory.go | 13 +++++++++++++ .../google-beta/transport/config.go | 2 ++ 2 files changed, 15 insertions(+) diff --git a/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/bigtable_client_factory.go b/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/bigtable_client_factory.go index 48e320e51e..c38828d669 100644 --- a/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/bigtable_client_factory.go +++ b/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/bigtable_client_factory.go @@ -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 { @@ -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...) } @@ -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...) } @@ -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...) } diff --git a/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/config.go b/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/config.go index cf5ccc2d76..635dce4da0 100644 --- a/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/config.go +++ b/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/transport/config.go @@ -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{