[#1902] tree: Extend grpc service with ListTrees method

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-10-18 16:03:03 +03:00 committed by Pavel Karpy
parent 24e9e3f3bf
commit 6d4beea187
5 changed files with 70 additions and 0 deletions

View file

@ -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 {
meta := make([]pilorama.KeyValue, len(arr))
for i, kv := range arr {

Binary file not shown.

View file

@ -39,6 +39,8 @@ service TreeService {
rpc GetNodeByPath (GetNodeByPathRequest) returns (GetNodeByPathResponse);
// GetSubTree returns tree corresponding to a specific node.
rpc GetSubTree (GetSubTreeRequest) returns (stream GetSubTreeResponse);
// TreeList return list of the existing trees in the container.
rpc TreeList (TreeListRequest) returns (TreeListResponse);
/* Synchronization API */
@ -273,6 +275,29 @@ message GetSubTreeResponse {
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 Body {

Binary file not shown.

Binary file not shown.