forked from TrueCloudLab/frostfs-node
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package tree
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
|
"github.com/spf13/viper"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
// _client returns grpc Tree service client. Should be removed
|
|
// after making Tree API public.
|
|
func _client(ctx context.Context) (tree.TreeServiceClient, error) {
|
|
var netAddr network.Address
|
|
err := netAddr.FromString(viper.GetString(commonflags.RPC))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
opts := []grpc.DialOption{
|
|
grpc.WithBlock(),
|
|
grpc.WithChainUnaryInterceptor(
|
|
tracing.NewGRPCUnaryClientInteceptor(),
|
|
),
|
|
grpc.WithChainStreamInterceptor(
|
|
tracing.NewGRPCStreamClientInterceptor(),
|
|
),
|
|
}
|
|
|
|
if !strings.HasPrefix(netAddr.URIAddr(), "grpcs:") {
|
|
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
}
|
|
|
|
// a default connection establishing timeout
|
|
const defaultClientConnectTimeout = time.Second * 2
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, defaultClientConnectTimeout)
|
|
cc, err := grpc.DialContext(ctx, netAddr.URIAddr(), opts...)
|
|
cancel()
|
|
|
|
return tree.NewTreeServiceClient(cc), err
|
|
}
|