[#286] client: Add TLS options

Add `WithTLSConfig` option to client.
If it is not nil then client will
try to open secured connection.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-05-20 18:51:28 +03:00 committed by Leonard Lyubich
parent 634e405e9c
commit 89aede1fb3
3 changed files with 35 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/rpc/grpc"
grpcstd "google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
func (c *Client) createGRPCClient() (err error) {
@ -33,8 +34,17 @@ func (c *Client) openGRPCConn() error {
var err error
var credOpt grpcstd.DialOption
if c.tlsCfg != nil {
creds := credentials.NewTLS(c.tlsCfg)
credOpt = grpcstd.WithTransportCredentials(creds)
} else {
credOpt = grpcstd.WithInsecure()
}
dialCtx, cancel := context.WithTimeout(context.Background(), c.dialTimeout)
c.conn, err = grpcstd.DialContext(dialCtx, c.addr, grpcstd.WithInsecure())
c.conn, err = grpcstd.DialContext(dialCtx, c.addr, credOpt)
cancel()
return err