From 0c83e84613f913024d91857ad430f977837e64b6 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 25 Aug 2020 19:18:24 +0300 Subject: [PATCH] [#13] services/object: Implement GetRangeHash handlers Signed-off-by: Leonard Lyubich --- pkg/services/object/executor.go | 13 +++++++++++-- pkg/services/object/sign.go | 28 ++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pkg/services/object/executor.go b/pkg/services/object/executor.go index 845f3758a6..2e84db6080 100644 --- a/pkg/services/object/executor.go +++ b/pkg/services/object/executor.go @@ -205,6 +205,15 @@ func (s *executorSvc) GetRange(ctx context.Context, req *object.GetRangeRequest) }, nil } -func (*executorSvc) GetRangeHash(context.Context, *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) { - panic("implement me") +func (s *executorSvc) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) { + respBody, err := s.exec.GetRangeHash(ctx, req.GetBody()) + if err != nil { + return nil, errors.Wrap(err, "could not execute GetRangeHash request") + } + + resp := new(object.GetRangeHashResponse) + resp.SetBody(respBody) + resp.SetMetaHeader(s.metaHeader) + + return resp, nil } diff --git a/pkg/services/object/sign.go b/pkg/services/object/sign.go index f0e09bc76d..5d62a260b4 100644 --- a/pkg/services/object/sign.go +++ b/pkg/services/object/sign.go @@ -13,12 +13,13 @@ import ( type signService struct { key *ecdsa.PrivateKey - searchSigService *util.UnarySignService - getSigService *util.UnarySignService - putService object.Service - rangeSigService *util.UnarySignService - headSigService *util.UnarySignService - delSigService *util.UnarySignService + searchSigService *util.UnarySignService + getSigService *util.UnarySignService + putService object.Service + rangeSigService *util.UnarySignService + headSigService *util.UnarySignService + delSigService *util.UnarySignService + rangeHashSigService *util.UnarySignService } type searchStreamSigner struct { @@ -79,6 +80,12 @@ func NewSignService(key *ecdsa.PrivateKey, svc object.Service) object.Service { return svc.Delete(ctx, req.(*object.DeleteRequest)) }, ), + rangeHashSigService: util.NewUnarySignService( + key, + func(ctx context.Context, req interface{}) (interface{}, error) { + return svc.GetRangeHash(ctx, req.(*object.GetRangeHashRequest)) + }, + ), } } @@ -208,6 +215,11 @@ func (s *signService) GetRange(ctx context.Context, req *object.GetRangeRequest) }, nil } -func (s *signService) GetRangeHash(context.Context, *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) { - panic("implement me") +func (s *signService) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) { + resp, err := s.rangeHashSigService.HandleUnaryRequest(ctx, req) + if err != nil { + return nil, err + } + + return resp.(*object.GetRangeHashResponse), nil }