forked from TrueCloudLab/frostfs-s3-gw
[#75] Make grpc tree client implementation internal
Since we have pkg 'internal/frostfs/services/tree' that is downloading during build we cannot export any package that is depended on it. Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
6c68e21777
commit
01afa1cae4
4 changed files with 45 additions and 43 deletions
|
@ -21,6 +21,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/notifications"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/notifications"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/resolver"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/resolver"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/services"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/version"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/version"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/wallet"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/wallet"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/xml"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/xml"
|
||||||
|
@ -114,7 +115,7 @@ func (a *App) initLayer(ctx context.Context) {
|
||||||
|
|
||||||
treeServiceEndpoint := a.cfg.GetString(cfgTreeServiceEndpoint)
|
treeServiceEndpoint := a.cfg.GetString(cfgTreeServiceEndpoint)
|
||||||
grpcDialOpt := grpc.WithTransportCredentials(insecure.NewCredentials())
|
grpcDialOpt := grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||||
treeGRPCClient, err := tree.NewTreeServiceClientGRPC(ctx, treeServiceEndpoint, a.key, grpcDialOpt)
|
treeGRPCClient, err := services.NewTreeServiceClientGRPC(ctx, treeServiceEndpoint, a.key, grpcDialOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Fatal("failed to create tree service", zap.Error(err))
|
a.log.Fatal("failed to create tree service", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package tree
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -10,14 +10,15 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/services/tree"
|
grpcService "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/services/tree"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/service/tree"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetNodeByPathResponseInfoWrapper struct {
|
type GetNodeByPathResponseInfoWrapper struct {
|
||||||
response *tree.GetNodeByPathResponse_Info
|
response *grpcService.GetNodeByPathResponse_Info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n GetNodeByPathResponseInfoWrapper) GetNodeID() uint64 {
|
func (n GetNodeByPathResponseInfoWrapper) GetNodeID() uint64 {
|
||||||
|
@ -32,8 +33,8 @@ func (n GetNodeByPathResponseInfoWrapper) GetTimestamp() uint64 {
|
||||||
return n.response.GetTimestamp()
|
return n.response.GetTimestamp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n GetNodeByPathResponseInfoWrapper) GetMeta() []Meta {
|
func (n GetNodeByPathResponseInfoWrapper) GetMeta() []tree.Meta {
|
||||||
res := make([]Meta, len(n.response.Meta))
|
res := make([]tree.Meta, len(n.response.Meta))
|
||||||
for i, value := range n.response.Meta {
|
for i, value := range n.response.Meta {
|
||||||
res[i] = value
|
res[i] = value
|
||||||
}
|
}
|
||||||
|
@ -41,7 +42,7 @@ func (n GetNodeByPathResponseInfoWrapper) GetMeta() []Meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetSubTreeResponseBodyWrapper struct {
|
type GetSubTreeResponseBodyWrapper struct {
|
||||||
response *tree.GetSubTreeResponse_Body
|
response *grpcService.GetSubTreeResponse_Body
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n GetSubTreeResponseBodyWrapper) GetNodeID() uint64 {
|
func (n GetSubTreeResponseBodyWrapper) GetNodeID() uint64 {
|
||||||
|
@ -56,8 +57,8 @@ func (n GetSubTreeResponseBodyWrapper) GetTimestamp() uint64 {
|
||||||
return n.response.GetTimestamp()
|
return n.response.GetTimestamp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n GetSubTreeResponseBodyWrapper) GetMeta() []Meta {
|
func (n GetSubTreeResponseBodyWrapper) GetMeta() []tree.Meta {
|
||||||
res := make([]Meta, len(n.response.Meta))
|
res := make([]tree.Meta, len(n.response.Meta))
|
||||||
for i, value := range n.response.Meta {
|
for i, value := range n.response.Meta {
|
||||||
res[i] = value
|
res[i] = value
|
||||||
}
|
}
|
||||||
|
@ -67,7 +68,7 @@ func (n GetSubTreeResponseBodyWrapper) GetMeta() []Meta {
|
||||||
type ServiceClientGRPC struct {
|
type ServiceClientGRPC struct {
|
||||||
key *keys.PrivateKey
|
key *keys.PrivateKey
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
service tree.TreeServiceClient
|
service grpcService.TreeServiceClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTreeServiceClientGRPC(ctx context.Context, addr string, key *keys.PrivateKey, grpcOpts ...grpc.DialOption) (*ServiceClientGRPC, error) {
|
func NewTreeServiceClientGRPC(ctx context.Context, addr string, key *keys.PrivateKey, grpcOpts ...grpc.DialOption) (*ServiceClientGRPC, error) {
|
||||||
|
@ -76,8 +77,8 @@ func NewTreeServiceClientGRPC(ctx context.Context, addr string, key *keys.Privat
|
||||||
return nil, fmt.Errorf("did not connect: %v", err)
|
return nil, fmt.Errorf("did not connect: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := tree.NewTreeServiceClient(conn)
|
c := grpcService.NewTreeServiceClient(conn)
|
||||||
if _, err = c.Healthcheck(ctx, &tree.HealthcheckRequest{}); err != nil {
|
if _, err = c.Healthcheck(ctx, &grpcService.HealthcheckRequest{}); err != nil {
|
||||||
return nil, fmt.Errorf("healthcheck: %w", err)
|
return nil, fmt.Errorf("healthcheck: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,14 +89,14 @@ func NewTreeServiceClientGRPC(ctx context.Context, addr string, key *keys.Privat
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceClientGRPC) GetNodes(ctx context.Context, p *GetNodesParams) ([]NodeResponse, error) {
|
func (c *ServiceClientGRPC) GetNodes(ctx context.Context, p *tree.GetNodesParams) ([]tree.NodeResponse, error) {
|
||||||
request := &tree.GetNodeByPathRequest{
|
request := &grpcService.GetNodeByPathRequest{
|
||||||
Body: &tree.GetNodeByPathRequest_Body{
|
Body: &grpcService.GetNodeByPathRequest_Body{
|
||||||
ContainerId: p.BktInfo.CID[:],
|
ContainerId: p.BktInfo.CID[:],
|
||||||
TreeId: p.TreeID,
|
TreeId: p.TreeID,
|
||||||
Path: p.Path,
|
Path: p.Path,
|
||||||
Attributes: p.Meta,
|
Attributes: p.Meta,
|
||||||
PathAttribute: FileNameKey,
|
PathAttribute: tree.FileNameKey,
|
||||||
LatestOnly: p.LatestOnly,
|
LatestOnly: p.LatestOnly,
|
||||||
AllAttributes: p.AllAttrs,
|
AllAttributes: p.AllAttrs,
|
||||||
BearerToken: getBearer(ctx, p.BktInfo),
|
BearerToken: getBearer(ctx, p.BktInfo),
|
||||||
|
@ -103,7 +104,7 @@ func (c *ServiceClientGRPC) GetNodes(ctx context.Context, p *GetNodesParams) ([]
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||||
request.Signature = &tree.Signature{
|
request.Signature = &grpcService.Signature{
|
||||||
Key: key,
|
Key: key,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
}
|
}
|
||||||
|
@ -116,7 +117,7 @@ func (c *ServiceClientGRPC) GetNodes(ctx context.Context, p *GetNodesParams) ([]
|
||||||
return nil, handleError("failed to get node by path", err)
|
return nil, handleError("failed to get node by path", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make([]NodeResponse, len(resp.GetBody().GetNodes()))
|
res := make([]tree.NodeResponse, len(resp.GetBody().GetNodes()))
|
||||||
for i, info := range resp.GetBody().GetNodes() {
|
for i, info := range resp.GetBody().GetNodes() {
|
||||||
res[i] = GetNodeByPathResponseInfoWrapper{info}
|
res[i] = GetNodeByPathResponseInfoWrapper{info}
|
||||||
}
|
}
|
||||||
|
@ -124,9 +125,9 @@ func (c *ServiceClientGRPC) GetNodes(ctx context.Context, p *GetNodesParams) ([]
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceClientGRPC) GetSubTree(ctx context.Context, bktInfo *data.BucketInfo, treeID string, rootID uint64, depth uint32) ([]NodeResponse, error) {
|
func (c *ServiceClientGRPC) GetSubTree(ctx context.Context, bktInfo *data.BucketInfo, treeID string, rootID uint64, depth uint32) ([]tree.NodeResponse, error) {
|
||||||
request := &tree.GetSubTreeRequest{
|
request := &grpcService.GetSubTreeRequest{
|
||||||
Body: &tree.GetSubTreeRequest_Body{
|
Body: &grpcService.GetSubTreeRequest_Body{
|
||||||
ContainerId: bktInfo.CID[:],
|
ContainerId: bktInfo.CID[:],
|
||||||
TreeId: treeID,
|
TreeId: treeID,
|
||||||
RootId: rootID,
|
RootId: rootID,
|
||||||
|
@ -136,7 +137,7 @@ func (c *ServiceClientGRPC) GetSubTree(ctx context.Context, bktInfo *data.Bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||||
request.Signature = &tree.Signature{
|
request.Signature = &grpcService.Signature{
|
||||||
Key: key,
|
Key: key,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
}
|
}
|
||||||
|
@ -149,7 +150,7 @@ func (c *ServiceClientGRPC) GetSubTree(ctx context.Context, bktInfo *data.Bucket
|
||||||
return nil, handleError("failed to get sub tree client", err)
|
return nil, handleError("failed to get sub tree client", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var subtree []NodeResponse
|
var subtree []tree.NodeResponse
|
||||||
for {
|
for {
|
||||||
resp, err := cli.Recv()
|
resp, err := cli.Recv()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
@ -164,8 +165,8 @@ func (c *ServiceClientGRPC) GetSubTree(ctx context.Context, bktInfo *data.Bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceClientGRPC) AddNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, parent uint64, meta map[string]string) (uint64, error) {
|
func (c *ServiceClientGRPC) AddNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, parent uint64, meta map[string]string) (uint64, error) {
|
||||||
request := &tree.AddRequest{
|
request := &grpcService.AddRequest{
|
||||||
Body: &tree.AddRequest_Body{
|
Body: &grpcService.AddRequest_Body{
|
||||||
ContainerId: bktInfo.CID[:],
|
ContainerId: bktInfo.CID[:],
|
||||||
TreeId: treeID,
|
TreeId: treeID,
|
||||||
ParentId: parent,
|
ParentId: parent,
|
||||||
|
@ -174,7 +175,7 @@ func (c *ServiceClientGRPC) AddNode(ctx context.Context, bktInfo *data.BucketInf
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||||
request.Signature = &tree.Signature{
|
request.Signature = &grpcService.Signature{
|
||||||
Key: key,
|
Key: key,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
}
|
}
|
||||||
|
@ -191,19 +192,19 @@ func (c *ServiceClientGRPC) AddNode(ctx context.Context, bktInfo *data.BucketInf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceClientGRPC) AddNodeByPath(ctx context.Context, bktInfo *data.BucketInfo, treeID string, path []string, meta map[string]string) (uint64, error) {
|
func (c *ServiceClientGRPC) AddNodeByPath(ctx context.Context, bktInfo *data.BucketInfo, treeID string, path []string, meta map[string]string) (uint64, error) {
|
||||||
request := &tree.AddByPathRequest{
|
request := &grpcService.AddByPathRequest{
|
||||||
Body: &tree.AddByPathRequest_Body{
|
Body: &grpcService.AddByPathRequest_Body{
|
||||||
ContainerId: bktInfo.CID[:],
|
ContainerId: bktInfo.CID[:],
|
||||||
TreeId: treeID,
|
TreeId: treeID,
|
||||||
Path: path,
|
Path: path,
|
||||||
Meta: metaToKV(meta),
|
Meta: metaToKV(meta),
|
||||||
PathAttribute: FileNameKey,
|
PathAttribute: tree.FileNameKey,
|
||||||
BearerToken: getBearer(ctx, bktInfo),
|
BearerToken: getBearer(ctx, bktInfo),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||||
request.Signature = &tree.Signature{
|
request.Signature = &grpcService.Signature{
|
||||||
Key: key,
|
Key: key,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
}
|
}
|
||||||
|
@ -228,8 +229,8 @@ func (c *ServiceClientGRPC) AddNodeByPath(ctx context.Context, bktInfo *data.Buc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceClientGRPC) MoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID, parentID uint64, meta map[string]string) error {
|
func (c *ServiceClientGRPC) MoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID, parentID uint64, meta map[string]string) error {
|
||||||
request := &tree.MoveRequest{
|
request := &grpcService.MoveRequest{
|
||||||
Body: &tree.MoveRequest_Body{
|
Body: &grpcService.MoveRequest_Body{
|
||||||
ContainerId: bktInfo.CID[:],
|
ContainerId: bktInfo.CID[:],
|
||||||
TreeId: treeID,
|
TreeId: treeID,
|
||||||
NodeId: nodeID,
|
NodeId: nodeID,
|
||||||
|
@ -240,7 +241,7 @@ func (c *ServiceClientGRPC) MoveNode(ctx context.Context, bktInfo *data.BucketIn
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||||
request.Signature = &tree.Signature{
|
request.Signature = &grpcService.Signature{
|
||||||
Key: key,
|
Key: key,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
}
|
}
|
||||||
|
@ -256,8 +257,8 @@ func (c *ServiceClientGRPC) MoveNode(ctx context.Context, bktInfo *data.BucketIn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceClientGRPC) RemoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID uint64) error {
|
func (c *ServiceClientGRPC) RemoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID uint64) error {
|
||||||
request := &tree.RemoveRequest{
|
request := &grpcService.RemoveRequest{
|
||||||
Body: &tree.RemoveRequest_Body{
|
Body: &grpcService.RemoveRequest_Body{
|
||||||
ContainerId: bktInfo.CID[:],
|
ContainerId: bktInfo.CID[:],
|
||||||
TreeId: treeID,
|
TreeId: treeID,
|
||||||
NodeId: nodeID,
|
NodeId: nodeID,
|
||||||
|
@ -265,7 +266,7 @@ func (c *ServiceClientGRPC) RemoveNode(ctx context.Context, bktInfo *data.Bucket
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||||
request.Signature = &tree.Signature{
|
request.Signature = &grpcService.Signature{
|
||||||
Key: key,
|
Key: key,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
}
|
}
|
||||||
|
@ -280,11 +281,11 @@ func (c *ServiceClientGRPC) RemoveNode(ctx context.Context, bktInfo *data.Bucket
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func metaToKV(meta map[string]string) []*tree.KeyValue {
|
func metaToKV(meta map[string]string) []*grpcService.KeyValue {
|
||||||
result := make([]*tree.KeyValue, 0, len(meta))
|
result := make([]*grpcService.KeyValue, 0, len(meta))
|
||||||
|
|
||||||
for key, value := range meta {
|
for key, value := range meta {
|
||||||
result = append(result, &tree.KeyValue{Key: key, Value: []byte(value)})
|
result = append(result, &grpcService.KeyValue{Key: key, Value: []byte(value)})
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -303,9 +304,9 @@ func getBearer(ctx context.Context, bktInfo *data.BucketInfo) []byte {
|
||||||
|
|
||||||
func handleError(msg string, err error) error {
|
func handleError(msg string, err error) error {
|
||||||
if strings.Contains(err.Error(), "not found") {
|
if strings.Contains(err.Error(), "not found") {
|
||||||
return fmt.Errorf("%w: %s", ErrNodeNotFound, err.Error())
|
return fmt.Errorf("%w: %s", tree.ErrNodeNotFound, err.Error())
|
||||||
} else if strings.Contains(err.Error(), "is denied by") {
|
} else if strings.Contains(err.Error(), "is denied by") {
|
||||||
return fmt.Errorf("%w: %s", ErrNodeAccessDenied, err.Error())
|
return fmt.Errorf("%w: %s", tree.ErrNodeAccessDenied, err.Error())
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s: %w", msg, err)
|
return fmt.Errorf("%s: %w", msg, err)
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*REMOVE THIS AFTER SIGNATURE WILL BE AVAILABLE IN TREE CLIENT FROM FROSTFS NODE*/
|
/*REMOVE THIS AFTER SIGNATURE WILL BE AVAILABLE IN TREE CLIENT FROM FROSTFS NODE*/
|
||||||
package tree
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
|
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
|
|
@ -1,4 +1,4 @@
|
||||||
package tree
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
Loading…
Reference in a new issue