Compare commits

...

2 commits

Author SHA1 Message Date
8412b075a5 [#226] pool/tree: Fix handling access denied error
All checks were successful
Tests and linters / Tests (1.21) (pull_request) Successful in 1m18s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m26s
Tests and linters / Lint (pull_request) Successful in 2m18s
DCO / DCO (pull_request) Successful in 46s
(cherry picked from commit 6a52487edd)

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2024-06-20 17:22:03 +03:00
e5040d35e9 [#212] pool: Control sub tree nodes order
All checks were successful
Tests and linters / Tests (1.21) (pull_request) Successful in 1m34s
DCO / DCO (pull_request) Successful in 1m35s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m59s
Tests and linters / Lint (pull_request) Successful in 2m39s
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2024-04-02 17:15:32 +03:00

View file

@ -26,6 +26,16 @@ const (
defaultStreamTimeout = 10 * time.Second
)
// SubTreeSort defines an order of nodes returned from GetSubTree RPC.
type SubTreeSort int32
const (
// NoneOrder does not specify order of nodes returned in GetSubTree RPC.
NoneOrder SubTreeSort = iota
// AscendingOrder specifies ascending alphabetical order of nodes based on FilePath attribute.
AscendingOrder
)
var (
// ErrNodeNotFound is returned from Tree service in case of not found error.
ErrNodeNotFound = errors.New("not found")
@ -119,6 +129,7 @@ type GetSubTreeParams struct {
RootID uint64
Depth uint32
BearerToken []byte
Order SubTreeSort
}
// AddNodeParams groups parameters of Pool.AddNode operation.
@ -388,12 +399,17 @@ func (p *Pool) GetSubTree(ctx context.Context, prm GetSubTreeParams) (*SubTreeRe
RootId: prm.RootID,
Depth: prm.Depth,
BearerToken: prm.BearerToken,
OrderBy: &grpcService.GetSubTreeRequest_Body_Order{
Direction: grpcService.GetSubTreeRequest_Body_Order_Asc,
},
OrderBy: new(grpcService.GetSubTreeRequest_Body_Order),
},
}
switch prm.Order {
case AscendingOrder:
request.Body.OrderBy.Direction = grpcService.GetSubTreeRequest_Body_Order_Asc
default:
request.Body.OrderBy.Direction = grpcService.GetSubTreeRequest_Body_Order_None
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
@ -583,7 +599,7 @@ func handleError(msg string, err error) error {
}
if strings.Contains(err.Error(), "not found") {
return fmt.Errorf("%w: %s", ErrNodeNotFound, err.Error())
} else if strings.Contains(err.Error(), "is denied by") {
} else if strings.Contains(err.Error(), "denied") {
return fmt.Errorf("%w: %s", ErrNodeAccessDenied, err.Error())
}
return fmt.Errorf("%s: %w", msg, err)