[#1902] tree: Extend grpc service with ListTrees
method
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
24e9e3f3bf
commit
6d4beea187
5 changed files with 70 additions and 0 deletions
|
@ -522,6 +522,51 @@ func (s *Service) GetOpLog(req *GetOpLogRequest, srv TreeService_GetOpLogServer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) TreeList(ctx context.Context, req *TreeListRequest) (*TreeListResponse, error) {
|
||||||
|
var cid cidSDK.ID
|
||||||
|
|
||||||
|
err := cid.Decode(req.GetBody().GetContainerId())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// just verify the signature, not ACL checks
|
||||||
|
// since tree ID list is not protected like
|
||||||
|
// the containers list
|
||||||
|
err = verifyMessage(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ns, pos, err := s.getContainerNodes(cid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if pos < 0 {
|
||||||
|
var resp *TreeListResponse
|
||||||
|
var outErr error
|
||||||
|
err = s.forEachNode(ctx, ns, func(c TreeServiceClient) bool {
|
||||||
|
resp, outErr = c.TreeList(ctx, req)
|
||||||
|
return outErr == nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp, outErr
|
||||||
|
}
|
||||||
|
|
||||||
|
ids, err := s.forest.TreeList(cid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TreeListResponse{
|
||||||
|
Body: &TreeListResponse_Body{
|
||||||
|
Ids: ids,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func protoToMeta(arr []*KeyValue) []pilorama.KeyValue {
|
func protoToMeta(arr []*KeyValue) []pilorama.KeyValue {
|
||||||
meta := make([]pilorama.KeyValue, len(arr))
|
meta := make([]pilorama.KeyValue, len(arr))
|
||||||
for i, kv := range arr {
|
for i, kv := range arr {
|
||||||
|
|
BIN
pkg/services/tree/service.pb.go
generated
BIN
pkg/services/tree/service.pb.go
generated
Binary file not shown.
|
@ -39,6 +39,8 @@ service TreeService {
|
||||||
rpc GetNodeByPath (GetNodeByPathRequest) returns (GetNodeByPathResponse);
|
rpc GetNodeByPath (GetNodeByPathRequest) returns (GetNodeByPathResponse);
|
||||||
// GetSubTree returns tree corresponding to a specific node.
|
// GetSubTree returns tree corresponding to a specific node.
|
||||||
rpc GetSubTree (GetSubTreeRequest) returns (stream GetSubTreeResponse);
|
rpc GetSubTree (GetSubTreeRequest) returns (stream GetSubTreeResponse);
|
||||||
|
// TreeList return list of the existing trees in the container.
|
||||||
|
rpc TreeList (TreeListRequest) returns (TreeListResponse);
|
||||||
|
|
||||||
/* Synchronization API */
|
/* Synchronization API */
|
||||||
|
|
||||||
|
@ -273,6 +275,29 @@ message GetSubTreeResponse {
|
||||||
Signature signature = 2;
|
Signature signature = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
message TreeListRequest {
|
||||||
|
message Body {
|
||||||
|
// Container ID in V2 format.
|
||||||
|
bytes container_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request body.
|
||||||
|
Body body = 1;
|
||||||
|
// Request signature.
|
||||||
|
Signature signature = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TreeListResponse {
|
||||||
|
message Body {
|
||||||
|
// Tree IDs.
|
||||||
|
repeated string ids = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response body.
|
||||||
|
Body body = 1;
|
||||||
|
Signature signature = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
message ApplyRequest {
|
message ApplyRequest {
|
||||||
message Body {
|
message Body {
|
||||||
|
|
BIN
pkg/services/tree/service_grpc.pb.go
generated
BIN
pkg/services/tree/service_grpc.pb.go
generated
Binary file not shown.
BIN
pkg/services/tree/service_neofs.pb.go
generated
BIN
pkg/services/tree/service_neofs.pb.go
generated
Binary file not shown.
Loading…
Reference in a new issue