From 397d912e19a99c79d35b5fcd7c62d3364871d13b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 8 Dec 2020 15:59:01 +0300 Subject: [PATCH] [#235] object/head: Support raw flag in service Signed-off-by: Leonard Lyubich --- pkg/services/object/head/local.go | 2 +- pkg/services/object/head/prm.go | 10 ++++++++++ pkg/services/object/head/remote.go | 3 ++- pkg/services/object/head/v2/service.go | 7 +++++++ pkg/services/object/head/v2/util.go | 14 +++++++++++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pkg/services/object/head/local.go b/pkg/services/object/head/local.go index b2d9108078..1435c7b449 100644 --- a/pkg/services/object/head/local.go +++ b/pkg/services/object/head/local.go @@ -13,7 +13,7 @@ type localHeader struct { } func (h *localHeader) head(ctx context.Context, prm *Prm, handler func(*object.Object)) error { - head, err := engine.Head(h.storage, prm.addr) + head, err := engine.HeadRaw(h.storage, prm.addr, prm.raw) if err != nil { return errors.Wrapf(err, "(%T) could not get header from local storage", h) } diff --git a/pkg/services/object/head/prm.go b/pkg/services/object/head/prm.go index 167bdb4bb9..7a7e62d1f3 100644 --- a/pkg/services/object/head/prm.go +++ b/pkg/services/object/head/prm.go @@ -11,6 +11,8 @@ type Prm struct { short bool addr *object.Address + + raw bool } func (p *Prm) WithCommonPrm(v *util.CommonPrm) *Prm { @@ -36,3 +38,11 @@ func (p *Prm) WithAddress(v *object.Address) *Prm { return p } + +func (p *Prm) WithRaw(v bool) *Prm { + if p != nil { + p.raw = v + } + + return p +} diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index e6979e3282..eeeb1cec8b 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -74,7 +74,8 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob } p := new(client.ObjectHeaderParams). - WithAddress(prm.commonHeadPrm.addr) + WithAddress(prm.commonHeadPrm.addr). + WithRawFlag(prm.commonHeadPrm.raw) if prm.commonHeadPrm.short { p = p.WithMainFields() diff --git a/pkg/services/object/head/v2/service.go b/pkg/services/object/head/v2/service.go index fbb8985a17..728a461922 100644 --- a/pkg/services/object/head/v2/service.go +++ b/pkg/services/object/head/v2/service.go @@ -3,6 +3,7 @@ package headsvc import ( "context" + "github.com/nspcc-dev/neofs-api-go/pkg/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head" "github.com/pkg/errors" @@ -40,6 +41,12 @@ func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV return nil, errors.Wrapf(err, "(%T) could not get object header", s) } + var splitErr *object.SplitInfoError + + if errors.As(err, &splitErr) { + return splitInfoResponse(splitErr.SplitInfo()), nil + } + return fromResponse(r, req.GetBody().GetMainOnly()), nil } diff --git a/pkg/services/object/head/v2/util.go b/pkg/services/object/head/v2/util.go index 4066be22df..be41a9cfe1 100644 --- a/pkg/services/object/head/v2/util.go +++ b/pkg/services/object/head/v2/util.go @@ -15,7 +15,8 @@ func toPrm(req *objectV2.HeadRequest) *headsvc.Prm { object.NewAddressFromV2(body.GetAddress()), ). Short(body.GetMainOnly()). - WithCommonPrm(util.CommonPrmFromV2(req)) + WithCommonPrm(util.CommonPrmFromV2(req)). + WithRaw(body.GetRaw()) } func fromResponse(r *headsvc.Response, short bool) *objectV2.HeadResponse { @@ -55,3 +56,14 @@ func shortPartFromResponse(r *headsvc.Response) objectV2.GetHeaderPart { return sh } + +func splitInfoResponse(info *object.SplitInfo) *objectV2.HeadResponse { + resp := new(objectV2.HeadResponse) + + body := new(objectV2.HeadResponseBody) + resp.SetBody(body) + + body.SetHeaderPart(info.ToV2()) + + return resp +}