From 7b9dfd87553a6759b9d49d89f194cd37f1139c2d Mon Sep 17 00:00:00 2001 From: nimistry Date: Thu, 6 Apr 2023 11:08:33 +0100 Subject: [PATCH] * Re-added insecure function and corrected the logic * Added more information for connection errors * Replaced deprecated functions --- internal/pkg/grpc/client.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/pkg/grpc/client.go b/internal/pkg/grpc/client.go index d6a467f..ade99d8 100644 --- a/internal/pkg/grpc/client.go +++ b/internal/pkg/grpc/client.go @@ -17,6 +17,7 @@ package grpc import ( "bytes" "fmt" + "google.golang.org/grpc/credentials/insecure" "log" "mittens/internal/pkg/placeholders" "mittens/internal/pkg/response" @@ -61,8 +62,14 @@ func (c *Client) Connect(headers []string) error { headersMetadata := grpcurl.MetadataFromHeaders(headers) contextWithMetadata := metadata.NewOutgoingContext(ctx, headersMetadata) - dialOptions := []grpc.DialOption{grpc.WithBlock()} + // grpc.WithReturnConnectionError() is EXPERIMENTAL and may be changed or removed in a later release + // Added to provide more information if a connection error occurs + dialOptions := []grpc.DialOption{grpc.WithBlock(), grpc.WithReturnConnectionError()} if c.insecure { + log.Print("ignoring gRPC server SSL/TLS authentication") + dialOptions = append(dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) + } else { + log.Print("using gRPC server SSL/TLS authentication") tlsConf, err := grpcurl.ClientTLSConfig(c.insecure, "", "", "") if err != nil { return fmt.Errorf("failed to create TLS config: %v", err) @@ -71,12 +78,13 @@ func (c *Client) Connect(headers []string) error { dialOptions = append(dialOptions, grpc.WithTransportCredentials(creds)) } + grpc.WithReturnConnectionError() conn, err := grpc.DialContext(ctx, c.host, dialOptions...) if err != nil { return fmt.Errorf("gRPC dial: %v", err) } - reflectionClient := grpcreflect.NewClient(contextWithMetadata, reflectpb.NewServerReflectionClient(conn)) + reflectionClient := grpcreflect.NewClientV1Alpha(contextWithMetadata, reflectpb.NewServerReflectionClient(conn)) descriptorSource := grpcurl.DescriptorSourceFromServer(contextWithMetadata, reflectionClient) log.Print("gRPC client connected")