From f5fc59324a809b63c42395ddda05fee144d123d8 Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Fri, 4 Feb 2022 17:25:46 -0800 Subject: [PATCH] Fix deprecations --- cmd/grpcurl/grpcurl.go | 4 +--- grpcurl.go | 13 +++++++------ grpcurl_test.go | 5 +++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index d5ec16d..6707837 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -438,9 +438,7 @@ func main() { } if overrideName != "" { - if err := creds.OverrideServerName(overrideName); err != nil { - fail(err, "Failed to override server name as %q", overrideName) - } + opts = append(opts, grpc.WithAuthority(overrideName)) } } else if *authority != "" { opts = append(opts, grpc.WithAuthority(*authority)) diff --git a/grpcurl.go b/grpcurl.go index 8f09aa3..f36fc9e 100644 --- a/grpcurl.go +++ b/grpcurl.go @@ -27,6 +27,7 @@ import ( "github.com/jhump/protoreflect/dynamic" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" protov2 "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/descriptorpb" @@ -632,11 +633,11 @@ func BlockingDial(ctx context.Context, network, address string, creds credential dialer := func(ctx context.Context, address string) (net.Conn, error) { // NB: We *could* handle the TLS handshake ourselves, in the custom // dialer (instead of customizing both the dialer and the credentials). - // But that requires using WithInsecure dial option (so that the gRPC - // library doesn't *also* try to do a handshake). And that would mean - // that the library would send the wrong ":scheme" metaheader to - // servers: it would send "http" instead of "https" because it is - // unaware that TLS is actually in use. + // But that requires using insecure.NewCredentials() dial transport + // option (so that the gRPC library doesn't *also* try to do a + // handshake). And that would mean that the library would send the + // wrong ":scheme" metaheader to servers: it would send "http" instead + // of "https" because it is unaware that TLS is actually in use. conn, err := (&net.Dialer{}).DialContext(ctx, network, address) if err != nil { writeResult(err) @@ -657,7 +658,7 @@ func BlockingDial(ctx context.Context, network, address string, creds credential opts = append(opts, grpc.WithBlock(), grpc.WithContextDialer(dialer)) if creds == nil { - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { opts = append(opts, grpc.WithTransportCredentials(creds)) } diff --git a/grpcurl_test.go b/grpcurl_test.go index b16b18d..25b4276 100644 --- a/grpcurl_test.go +++ b/grpcurl_test.go @@ -18,6 +18,7 @@ import ( "github.com/jhump/protoreflect/grpcreflect" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" "google.golang.org/grpc/reflection" reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" @@ -77,7 +78,7 @@ func TestMain(m *testing.M) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if ccReflect, err = grpc.DialContext(ctx, fmt.Sprintf("127.0.0.1:%d", portReflect), - grpc.WithInsecure(), grpc.WithBlock()); err != nil { + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()); err != nil { panic(err) } defer ccReflect.Close() @@ -102,7 +103,7 @@ func TestMain(m *testing.M) { ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if ccNoReflect, err = grpc.DialContext(ctx, fmt.Sprintf("127.0.0.1:%d", portProtoset), - grpc.WithInsecure(), grpc.WithBlock()); err != nil { + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()); err != nil { panic(err) } defer ccNoReflect.Close()