forked from TrueCloudLab/frostfs-node
[#943] service/object: Remove KeyStore from CommonPrm
There is no point to pass key storage in parameters because it can be defined on the service level of application. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
c30aa20b04
commit
fbed86da2c
9 changed files with 40 additions and 40 deletions
|
@ -300,6 +300,7 @@ func initObjectService(c *cfg) {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
searchsvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
searchsvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
||||||
|
searchsvc.WithKeyStorage(keyStorage),
|
||||||
)
|
)
|
||||||
|
|
||||||
sSearchV2 := searchsvcV2.NewService(
|
sSearchV2 := searchsvcV2.NewService(
|
||||||
|
@ -317,6 +318,7 @@ func initObjectService(c *cfg) {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
getsvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
getsvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
||||||
|
getsvc.WithKeyStorage(keyStorage),
|
||||||
)
|
)
|
||||||
|
|
||||||
sGetV2 := getsvcV2.NewService(
|
sGetV2 := getsvcV2.NewService(
|
||||||
|
|
|
@ -18,9 +18,7 @@ func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteRe
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(deletesvc.Prm)
|
p := new(deletesvc.Prm)
|
||||||
p.SetCommonParameters(commonPrm.
|
p.SetCommonParameters(commonPrm)
|
||||||
WithKeyStorage(s.keyStorage),
|
|
||||||
)
|
|
||||||
|
|
||||||
body := req.GetBody()
|
body := req.GetBody()
|
||||||
p.WithAddress(object.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(object.NewAddressFromV2(body.GetAddress()))
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (exec execCtx) isChild(obj *object.Object) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec execCtx) key() (*ecdsa.PrivateKey, error) {
|
func (exec execCtx) key() (*ecdsa.PrivateKey, error) {
|
||||||
return exec.prm.common.KeyStorage().GetKey(exec.prm.common.SessionToken())
|
return exec.svc.keyStore.GetKey(exec.prm.common.SessionToken())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec execCtx) callOptions() ([]client.CallOption, error) {
|
func (exec execCtx) callOptions() ([]client.CallOption, error) {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package getsvc
|
package getsvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
|
|
||||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
@ -44,6 +47,10 @@ type cfg struct {
|
||||||
currentEpochReceiver interface {
|
currentEpochReceiver interface {
|
||||||
currentEpoch() (uint64, error)
|
currentEpoch() (uint64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyStore interface {
|
||||||
|
GetKey(token *session.Token) (*ecdsa.PrivateKey, error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -119,3 +126,11 @@ func WithNetMapSource(nmSrc netmap.Source) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithKeyStorage returns option to set private
|
||||||
|
// key storage for session tokens and node key.
|
||||||
|
func WithKeyStorage(store *util.KeyStorage) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.keyStore = store
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -38,9 +38,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(getsvc.Prm)
|
p := new(getsvc.Prm)
|
||||||
p.SetCommonParameters(commonPrm.
|
p.SetCommonParameters(commonPrm)
|
||||||
WithKeyStorage(s.keyStorage),
|
|
||||||
)
|
|
||||||
|
|
||||||
body := req.GetBody()
|
body := req.GetBody()
|
||||||
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
||||||
|
@ -165,9 +163,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(getsvc.RangePrm)
|
p := new(getsvc.RangePrm)
|
||||||
p.SetCommonParameters(commonPrm.
|
p.SetCommonParameters(commonPrm)
|
||||||
WithKeyStorage(s.keyStorage),
|
|
||||||
)
|
|
||||||
|
|
||||||
body := req.GetBody()
|
body := req.GetBody()
|
||||||
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
||||||
|
@ -266,9 +262,7 @@ func (s *Service) toHashRangePrm(req *objectV2.GetRangeHashRequest) (*getsvc.Ran
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(getsvc.RangeHashPrm)
|
p := new(getsvc.RangeHashPrm)
|
||||||
p.SetCommonParameters(commonPrm.
|
p.SetCommonParameters(commonPrm)
|
||||||
WithKeyStorage(s.keyStorage),
|
|
||||||
)
|
|
||||||
|
|
||||||
body := req.GetBody()
|
body := req.GetBody()
|
||||||
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
||||||
|
@ -324,9 +318,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(getsvc.HeadPrm)
|
p := new(getsvc.HeadPrm)
|
||||||
p.SetCommonParameters(commonPrm.
|
p.SetCommonParameters(commonPrm)
|
||||||
WithKeyStorage(s.keyStorage),
|
|
||||||
)
|
|
||||||
|
|
||||||
body := req.GetBody()
|
body := req.GetBody()
|
||||||
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(objectSDK.NewAddressFromV2(body.GetAddress()))
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package searchsvc
|
package searchsvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
|
|
||||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||||
|
@ -47,6 +50,10 @@ type cfg struct {
|
||||||
currentEpochReceiver interface {
|
currentEpochReceiver interface {
|
||||||
currentEpoch() (uint64, error)
|
currentEpoch() (uint64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyStore interface {
|
||||||
|
GetKey(token *session.Token) (*ecdsa.PrivateKey, error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -109,3 +116,11 @@ func WithNetMapSource(nmSrc netmap.Source) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithKeyStorage returns option to set private
|
||||||
|
// key storage for session tokens and node key.
|
||||||
|
func WithKeyStorage(store *util.KeyStorage) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.keyStore = store
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]*o
|
||||||
return exec.prm.forwarder(info, c.client)
|
return exec.prm.forwarder(info, c.client)
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := exec.prm.common.KeyStorage().GetKey(exec.prm.common.SessionToken())
|
key, err := exec.svc.keyStore.GetKey(exec.prm.common.SessionToken())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,7 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(searchsvc.Prm)
|
p := new(searchsvc.Prm)
|
||||||
p.SetCommonParameters(commonPrm.
|
p.SetCommonParameters(commonPrm)
|
||||||
WithKeyStorage(s.keyStorage),
|
|
||||||
)
|
|
||||||
|
|
||||||
p.SetWriter(&streamWriter{
|
p.SetWriter(&streamWriter{
|
||||||
stream: stream,
|
stream: stream,
|
||||||
|
|
|
@ -20,8 +20,6 @@ type CommonPrm struct {
|
||||||
|
|
||||||
bearer *token.BearerToken
|
bearer *token.BearerToken
|
||||||
|
|
||||||
keyStor *KeyStorage
|
|
||||||
|
|
||||||
callOpts []client.CallOption
|
callOpts []client.CallOption
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,24 +61,6 @@ func (p *CommonPrm) WithBearerToken(token *token.BearerToken) *CommonPrm {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithKeyStorage sets private key storage to use during execution.
|
|
||||||
func (p *CommonPrm) WithKeyStorage(stor *KeyStorage) *CommonPrm {
|
|
||||||
if p != nil {
|
|
||||||
p.keyStor = stor
|
|
||||||
}
|
|
||||||
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeyStorage returns private key storage to use during execution.
|
|
||||||
func (p *CommonPrm) KeyStorage() *KeyStorage {
|
|
||||||
if p != nil {
|
|
||||||
return p.keyStor
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithRemoteCallOptions sets call options remote remote client calls.
|
// WithRemoteCallOptions sets call options remote remote client calls.
|
||||||
func (p *CommonPrm) WithRemoteCallOptions(opts ...client.CallOption) *CommonPrm {
|
func (p *CommonPrm) WithRemoteCallOptions(opts ...client.CallOption) *CommonPrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
|
|
Loading…
Reference in a new issue