From 1edc048870dc13202627eb4f35b1215edb4bc0f3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 28 Sep 2022 15:05:19 +0300 Subject: [PATCH] [#1697] services/object: Return proper error if session token is missing Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 1 + cmd/neofs-node/object.go | 2 +- pkg/services/object/delete/delete.go | 13 +++++++++++++ pkg/services/object/delete/service.go | 10 ++++++++++ pkg/services/object/delete/v2/service.go | 10 ---------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 915015539..6aa3001c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Changelog for NeoFS Node ### Fixed - Description of command `netmap nodeinfo` (#1821) +- Proper status for object.Delete if session token is missing (#1697) ### Removed - Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128) diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 278c157e0..f16140904 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -338,11 +338,11 @@ func initObjectService(c *cfg) { cfg: c, }), + deletesvc.WithKeyStorage(keyStorage), ) sDeleteV2 := deletesvcV2.NewService( deletesvcV2.WithInternalService(sDelete), - deletesvcV2.WithKeyStorage(keyStorage), ) // build service pipeline diff --git a/pkg/services/object/delete/delete.go b/pkg/services/object/delete/delete.go index 56aa74e75..b50e261c6 100644 --- a/pkg/services/object/delete/delete.go +++ b/pkg/services/object/delete/delete.go @@ -3,11 +3,24 @@ package deletesvc import ( "context" + "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "go.uber.org/zap" ) // Delete serves requests to remote the objects. func (s *Service) Delete(ctx context.Context, prm Prm) error { + // If session token is not found we will fail during tombstone PUT. + // Here we fail immediately to ensure no unnecessary network communication is done. + if tok := prm.common.SessionToken(); tok != nil { + _, err := s.keyStorage.GetKey(&util.SessionInfo{ + ID: tok.ID(), + Owner: tok.Issuer(), + }) + if err != nil { + return err + } + } + exec := &execCtx{ svc: s, ctx: ctx, diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index a56ad7dce..a66f16ddd 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -5,6 +5,7 @@ import ( getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search" + "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -55,6 +56,8 @@ type cfg struct { } netInfo NetworkInfo + + keyStorage *util.KeyStorage } func defaultCfg() *cfg { @@ -112,3 +115,10 @@ func WithNetworkInfo(netInfo NetworkInfo) Option { c.netInfo = netInfo } } + +// WithKeyStorage returns option to set local private key storage. +func WithKeyStorage(ks *util.KeyStorage) Option { + return func(c *cfg) { + c.keyStorage = ks + } +} diff --git a/pkg/services/object/delete/v2/service.go b/pkg/services/object/delete/v2/service.go index 9e7a3ceeb..7b450b8a0 100644 --- a/pkg/services/object/delete/v2/service.go +++ b/pkg/services/object/delete/v2/service.go @@ -5,7 +5,6 @@ import ( objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" deletesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/delete" - objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" ) // Service implements Delete operation of Object service v2. @@ -18,8 +17,6 @@ type Option func(*cfg) type cfg struct { svc *deletesvc.Service - - keyStorage *objutil.KeyStorage } // NewService constructs Service instance from provided options. @@ -60,10 +57,3 @@ 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 - } -}