[#243] object/delete: Implement new service processing

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-11 11:04:04 +03:00 committed by Alex Vanin
parent 510e9ff2ec
commit fe3906c295
11 changed files with 654 additions and 217 deletions

View file

@ -5,7 +5,7 @@ import (
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
deletesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/delete"
"github.com/pkg/errors"
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
)
// Service implements Delete operation of Object service v2.
@ -18,6 +18,8 @@ type Option func(*cfg)
type cfg struct {
svc *deletesvc.Service
keyStorage *objutil.KeyStorage
}
// NewService constructs Service instance from provided options.
@ -35,12 +37,22 @@ func NewService(opts ...Option) *Service {
// Delete calls internal service.
func (s *Service) Delete(ctx context.Context, req *objectV2.DeleteRequest) (*objectV2.DeleteResponse, error) {
r, err := s.svc.Delete(ctx, toPrm(req))
resp := new(objectV2.DeleteResponse)
body := new(objectV2.DeleteResponseBody)
resp.SetBody(body)
p, err := s.toPrm(req, body)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not get object header", s)
return nil, err
}
return fromResponse(r), nil
err = s.svc.Delete(ctx, *p)
if err != nil {
return nil, err
}
return resp, nil
}
func WithInternalService(v *deletesvc.Service) Option {
@ -48,3 +60,10 @@ func WithInternalService(v *deletesvc.Service) Option {
c.svc = v
}
}
// WithKeyStorage returns option to set local private key storage.
func WithKeyStorage(ks *objutil.KeyStorage) Option {
return func(c *cfg) {
c.keyStorage = ks
}
}