drop AuthTLS option and use client TLSConfig option

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-04-20 12:21:00 +03:00
parent 637e3df24a
commit a4683c0b78
2 changed files with 4 additions and 18 deletions

View File

@ -35,14 +35,11 @@ type grpcClient struct {
// secure returns the dial option for whether its a secure or insecure connection // secure returns the dial option for whether its a secure or insecure connection
func (g *grpcClient) secure(addr string) grpc.DialOption { func (g *grpcClient) secure(addr string) grpc.DialOption {
// first we check if theres'a tls config // first we check if theres'a tls config
if g.opts.Context != nil { if g.opts.TLSConfig != nil {
if v := g.opts.Context.Value(tlsAuth{}); v != nil { creds := credentials.NewTLS(g.opts.TLSConfig)
tls := v.(*tls.Config)
creds := credentials.NewTLS(tls)
// return tls config if it exists // return tls config if it exists
return grpc.WithTransportCredentials(creds) return grpc.WithTransportCredentials(creds)
} }
}
// default config // default config
tlsConfig := &tls.Config{} tlsConfig := &tls.Config{}

View File

@ -3,7 +3,6 @@ package grpc
import ( import (
"context" "context"
"crypto/tls"
"github.com/unistack-org/micro/v3/client" "github.com/unistack-org/micro/v3/client"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -72,16 +71,6 @@ func Codec(contentType string, c encoding.Codec) client.Option {
} }
} }
// AuthTLS should be used to setup a secure authentication using TLS
func AuthTLS(t *tls.Config) client.Option {
return func(o *client.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tlsAuth{}, t)
}
}
// //
// MaxRecvMsgSize set the maximum size of message that client can receive. // MaxRecvMsgSize set the maximum size of message that client can receive.
// //