From bb25ecbd15d19aaba3173bcb49975ed37720efe9 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 17 May 2022 16:59:46 +0300 Subject: [PATCH] [#1400] owner: Upgrade SDK package Signed-off-by: Leonard Lyubich --- .../internal/modules/morph/subnet.go | 18 +++---- cmd/neofs-cli/modules/accounting/balance.go | 12 ++--- cmd/neofs-cli/modules/bearer/create.go | 9 ++-- cmd/neofs-cli/modules/container.go | 16 +++--- cmd/neofs-cli/modules/object.go | 11 +++-- cmd/neofs-cli/modules/root.go | 15 +++--- cmd/neofs-cli/modules/session/create.go | 10 ++-- cmd/neofs-cli/modules/storagegroup.go | 4 +- cmd/neofs-node/cache.go | 12 ++--- cmd/neofs-node/config.go | 10 ++-- cmd/neofs-node/container.go | 6 +-- cmd/neofs-node/object.go | 6 +-- cmd/neofs-node/session.go | 4 +- go.mod | 4 +- go.sum | Bin 98218 -> 98218 bytes pkg/core/container/fmt.go | 5 +- pkg/core/container/fmt_test.go | 7 +-- pkg/core/object/fmt.go | 16 +++--- pkg/core/object/fmt_test.go | 14 ++++-- pkg/innerring/processors/container/common.go | 18 +++++-- .../processors/container/process_container.go | 12 ++--- .../processors/neofs/process_bind.go | 7 ++- .../processors/settlement/audit/calculate.go | 9 ++-- .../processors/settlement/basic/collect.go | 2 +- .../processors/settlement/basic/context.go | 20 ++++---- .../processors/settlement/basic/distribute.go | 4 +- .../processors/settlement/common/types.go | 8 +-- .../processors/settlement/common/util.go | 6 +-- pkg/innerring/processors/subnet/put.go | 6 +-- pkg/innerring/processors/subnet/put_test.go | 12 ++--- pkg/innerring/settlement.go | 17 ++++--- pkg/innerring/subnet.go | 7 ++- .../engine/engine_test.go | 11 ++--- pkg/local_object_storage/metabase/db_test.go | 11 ++--- pkg/local_object_storage/shard/shard_test.go | 9 ++-- pkg/morph/client/balance/balanceOf.go | 6 +-- pkg/morph/client/balance/transfer.go | 8 +-- pkg/morph/client/container/list.go | 17 +++---- pkg/morph/client/neofsid/keys.go | 8 +-- pkg/services/accounting/morph/executor.go | 18 ++++++- pkg/services/container/morph/executor.go | 20 ++++++-- pkg/services/container/morph/executor_test.go | 17 ++----- pkg/services/object/acl/acl.go | 18 +++++-- pkg/services/object/acl/acl_test.go | 12 ++--- pkg/services/object/acl/eacl/v2/headers.go | 4 +- pkg/services/object/acl/eacl/v2/object.go | 6 ++- pkg/services/object/acl/v2/classifier.go | 7 ++- pkg/services/object/acl/v2/request.go | 18 ++++--- pkg/services/object/acl/v2/service.go | 14 ++++-- pkg/services/object/acl/v2/types.go | 4 +- pkg/services/object/acl/v2/util.go | 46 ++++++------------ pkg/services/object/delete/service.go | 4 +- pkg/services/object/put/streamer.go | 17 +++++-- pkg/services/object/util/key.go | 4 +- pkg/services/object/util/key_test.go | 11 ++++- .../session/storage/persistent/executor.go | 27 +++++----- .../storage/persistent/executor_test.go | 32 +++++++----- .../session/storage/persistent/storage.go | 15 +++--- .../session/storage/temporary/executor.go | 16 ++++-- .../session/storage/temporary/storage.go | 11 ++--- 60 files changed, 375 insertions(+), 323 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/subnet.go b/cmd/neofs-adm/internal/modules/morph/subnet.go index 7cb81a86..03649451 100644 --- a/cmd/neofs-adm/internal/modules/morph/subnet.go +++ b/cmd/neofs-adm/internal/modules/morph/subnet.go @@ -14,9 +14,9 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/client" morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet" "github.com/nspcc-dev/neofs-node/pkg/util/rand" - "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/subnet" subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -217,7 +217,8 @@ var cmdSubnetCreate = &cobra.Command{ } // declare creator ID and encode it - creator := *owner.NewIDFromPublicKey(&key.PrivateKey.PublicKey) + var creator user.ID + user.IDFromKey(&creator, key.PrivateKey.PublicKey) // fill subnet info and encode it var info subnet.Info @@ -393,7 +394,7 @@ var cmdSubnetGet = &cobra.Command{ } // print information - var ownerID owner.ID + var ownerID user.ID info.ReadOwner(&ownerID) @@ -607,18 +608,13 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error { } // read client ID and encode it - var clientID owner.ID + var clientID user.ID - err = clientID.Parse(viper.GetString(flagSubnetClientID)) + err = clientID.DecodeString(viper.GetString(flagSubnetClientID)) if err != nil { return fmt.Errorf("decode client ID text: %w", err) } - binClientID, err := clientID.Marshal() - if err != nil { - return fmt.Errorf("marshal client ID: %w", err) - } - // read group ID and encode it var groupID internal.SubnetClientGroupID @@ -636,7 +632,7 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error { prm.SetGroup(binGroupID) prm.SetSubnet(binID) - prm.SetClient(binClientID) + prm.SetClient(clientID.WalletBytes()) if rm { prm.SetRemove() diff --git a/cmd/neofs-cli/modules/accounting/balance.go b/cmd/neofs-cli/modules/accounting/balance.go index 8a25073f..dc4d6c9f 100644 --- a/cmd/neofs-cli/modules/accounting/balance.go +++ b/cmd/neofs-cli/modules/accounting/balance.go @@ -10,7 +10,7 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/util/precision" "github.com/nspcc-dev/neofs-sdk-go/accounting" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -24,18 +24,16 @@ var accountingBalanceCmd = &cobra.Command{ Short: "Get internal balance of NeoFS account", Long: `Get internal balance of NeoFS account`, Run: func(cmd *cobra.Command, args []string) { - var oid *owner.ID + var oid user.ID pk, err := key.GetOrGenerate() common.ExitOnErr(cmd, "", err) balanceOwner, _ := cmd.Flags().GetString(ownerFlag) if balanceOwner == "" { - oid = owner.NewIDFromPublicKey(&pk.PublicKey) + user.IDFromKey(&oid, pk.PublicKey) } else { - oid := owner.NewID() - err := oid.Parse(balanceOwner) - common.ExitOnErr(cmd, "can't decode owner ID wallet address: %w", err) + common.ExitOnErr(cmd, "can't decode owner ID wallet address: %w", oid.DecodeString(balanceOwner)) } cli, err := internalclient.GetSDKClientByFlag(pk, commonflags.RPC) @@ -43,7 +41,7 @@ var accountingBalanceCmd = &cobra.Command{ var prm internalclient.BalanceOfPrm prm.SetClient(cli) - prm.SetAccount(*oid) + prm.SetAccount(oid) res, err := internalclient.BalanceOf(prm) common.ExitOnErr(cmd, "rpc error: %w", err) diff --git a/cmd/neofs-cli/modules/bearer/create.go b/cmd/neofs-cli/modules/bearer/create.go index 2bdec6f1..4a50456c 100644 --- a/cmd/neofs-cli/modules/bearer/create.go +++ b/cmd/neofs-cli/modules/bearer/create.go @@ -17,7 +17,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/client" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" ) @@ -96,8 +96,9 @@ func createToken(cmd *cobra.Command, _ []string) error { } ownerStr, _ := cmd.Flags().GetString(ownerFlag) - ownerID := owner.NewID() - if err := ownerID.Parse(ownerStr); err != nil { + + var ownerID user.ID + if err := ownerID.DecodeString(ownerStr); err != nil { return fmt.Errorf("can't parse recipient: %w", err) } @@ -105,7 +106,7 @@ func createToken(cmd *cobra.Command, _ []string) error { b.SetExpiration(exp) b.SetNotBefore(nvb) b.SetIssuedAt(iat) - b.SetOwnerID(*ownerID) + b.SetOwnerID(ownerID) eaclPath, _ := cmd.Flags().GetString(eaclFlag) if eaclPath != "" { diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index ec44fc44..0572188d 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -23,10 +23,10 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/object" addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/policy" "github.com/nspcc-dev/neofs-sdk-go/session" subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id" + "github.com/nspcc-dev/neofs-sdk-go/user" versionSDK "github.com/nspcc-dev/neofs-sdk-go/version" "github.com/spf13/cobra" ) @@ -114,22 +114,21 @@ var listContainersCmd = &cobra.Command{ Short: "List all created containers", Long: "List all created containers", Run: func(cmd *cobra.Command, args []string) { - var oid *owner.ID + var idUser user.ID key, err := getKey() common.ExitOnErr(cmd, "", err) if containerOwner == "" { - oid = owner.NewIDFromPublicKey(&key.PublicKey) + user.IDFromKey(&idUser, key.PublicKey) } else { - oid, err = ownerFromString(containerOwner) - common.ExitOnErr(cmd, "", err) + common.ExitOnErr(cmd, "", userFromString(&idUser, containerOwner)) } var prm internalclient.ListContainersPrm prepareAPIClientWithKey(cmd, key, &prm) - prm.SetAccount(*oid) + prm.SetAccount(idUser) res, err := internalclient.ListContainers(prm) common.ExitOnErr(cmd, "rpc error: %w", err) @@ -168,10 +167,11 @@ It will be stored in sidechain when inner ring will accepts it.`, key, err := getKey() common.ExitOnErr(cmd, "", err) - var idOwner *owner.ID + var idOwner *user.ID if idOwner = tok.OwnerID(); idOwner == nil { - idOwner = owner.NewIDFromPublicKey(&key.PublicKey) + idOwner = new(user.ID) + user.IDFromKey(idOwner, key.PublicKey) } ver := versionSDK.Current() diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 1026d3ac..0c41c101 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -27,8 +27,8 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/object" addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" - "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" ) @@ -335,7 +335,7 @@ func prepareSessionPrmWithOwner( cmd *cobra.Command, addr *addressSDK.Address, key *ecdsa.PrivateKey, - ownerID *owner.ID, + ownerID *user.ID, prms ...clientKeySession, ) { cli, err := internalclient.GetSDKClientByFlag(key, commonflags.RPC) @@ -739,8 +739,11 @@ func getObjectHash(cmd *cobra.Command, _ []string) { } } -func getOwnerID(key *ecdsa.PrivateKey) (*owner.ID, error) { - return owner.NewIDFromPublicKey(&key.PublicKey), nil +func getOwnerID(key *ecdsa.PrivateKey) (*user.ID, error) { + var res user.ID + user.IDFromKey(&res, key.PublicKey) + + return &res, nil } var searchUnaryOpVocabulary = map[string]object.SearchMatchType{ diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 49b798e1..1c2d1d27 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -2,7 +2,6 @@ package cmd import ( "crypto/ecdsa" - "errors" "fmt" "os" "path/filepath" @@ -21,8 +20,8 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/gendoc" "github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/client" - "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -187,16 +186,14 @@ func getTTL() uint32 { return ttl } -// ownerFromString converts string with NEO3 wallet address to neofs owner ID. -func ownerFromString(s string) (*owner.ID, error) { - result := owner.NewID() - - err := result.Parse(s) +// userFromString decodes user ID from string input. +func userFromString(id *user.ID, s string) error { + err := id.DecodeString(s) if err != nil { - return nil, errors.New("can't decode owner ID wallet address") + return fmt.Errorf("invalid user ID: %w", err) } - return result, nil + return nil } func printVerbose(format string, a ...interface{}) { diff --git a/cmd/neofs-cli/modules/session/create.go b/cmd/neofs-cli/modules/session/create.go index 27d2923f..96a0b5a7 100644 --- a/cmd/neofs-cli/modules/session/create.go +++ b/cmd/neofs-cli/modules/session/create.go @@ -9,8 +9,8 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-sdk-go/client" - "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -69,8 +69,10 @@ func createSession(cmd *cobra.Command, _ []string) error { lifetime = lfArg } - ownerID := owner.NewIDFromPublicKey(&privKey.PublicKey) - tok, err := CreateSession(c, ownerID, lifetime) + var ownerID user.ID + user.IDFromKey(&ownerID, privKey.PublicKey) + + tok, err := CreateSession(c, &ownerID, lifetime) if err != nil { return err } @@ -95,7 +97,7 @@ func createSession(cmd *cobra.Command, _ []string) error { // CreateSession returns newly created session token with the specified owner and lifetime. // `Issued-At` and `Not-Valid-Before` fields are set to current epoch. -func CreateSession(c *client.Client, owner *owner.ID, lifetime uint64) (*session.Token, error) { +func CreateSession(c *client.Client, owner *user.ID, lifetime uint64) (*session.Token, error) { var netInfoPrm internalclient.NetworkInfoPrm netInfoPrm.SetClient(c) diff --git a/cmd/neofs-cli/modules/storagegroup.go b/cmd/neofs-cli/modules/storagegroup.go index 7534ba3e..32c69df1 100644 --- a/cmd/neofs-cli/modules/storagegroup.go +++ b/cmd/neofs-cli/modules/storagegroup.go @@ -13,8 +13,8 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/object" addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" - "github.com/nspcc-dev/neofs-sdk-go/owner" storagegroupAPI "github.com/nspcc-dev/neofs-sdk-go/storagegroup" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" ) @@ -140,7 +140,7 @@ func init() { type sgHeadReceiver struct { cmd *cobra.Command key *ecdsa.PrivateKey - ownerID *owner.ID + ownerID *user.ID prm internalclient.HeadObjectPrm } diff --git a/cmd/neofs-node/cache.go b/cmd/neofs-node/cache.go index 874a6f9d..a0c66abd 100644 --- a/cmd/neofs-node/cache.go +++ b/cmd/neofs-node/cache.go @@ -12,7 +12,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) type netValueReader func(interface{}) (interface{}, error) @@ -248,14 +248,14 @@ func newCachedContainerLister(c *cntClient.Client) *ttlContainerLister { lruCnrListerCache := newNetworkTTLCache(containerListerCacheSize, containerListerCacheTTL, func(key interface{}) (interface{}, error) { var ( - id *owner.ID + id *user.ID strID = key.(string) ) if strID != "" { - id = owner.NewID() + id = new(user.ID) - err := id.Parse(strID) + err := id.DecodeString(strID) if err != nil { return nil, err } @@ -270,7 +270,7 @@ func newCachedContainerLister(c *cntClient.Client) *ttlContainerLister { // List returns list of container IDs from the cache. If list is missing in the // cache or expired, then it returns container IDs from side chain and updates // the cache. -func (s *ttlContainerLister) List(id *owner.ID) ([]*cid.ID, error) { +func (s *ttlContainerLister) List(id *user.ID) ([]*cid.ID, error) { var str string if id != nil { @@ -286,7 +286,7 @@ func (s *ttlContainerLister) List(id *owner.ID) ([]*cid.ID, error) { } // InvalidateContainerList removes cached list of container IDs. -func (s *ttlContainerLister) InvalidateContainerList(id *owner.ID) { +func (s *ttlContainerLister) InvalidateContainerList(id *user.ID) { (*ttlNetCache)(s).remove(id.String()) } diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 904914ff..658bf26f 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -45,7 +45,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/state" "github.com/nspcc-dev/neofs-sdk-go/netmap" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/nspcc-dev/neofs-sdk-go/version" "github.com/panjf2000/ants/v2" "go.etcd.io/bbolt" @@ -77,7 +77,7 @@ type cfg struct { key *keys.PrivateKey - ownerIDFromKey *owner.ID // owner ID calculated from key + ownerIDFromKey user.ID // user ID calculated from key apiVersion version.Version @@ -234,8 +234,6 @@ func initCfg(path string) *cfg { key := nodeconfig.Key(appCfg) - ownerIDFromKey := owner.NewIDFromPublicKey(&key.PrivateKey.PublicKey) - var logPrm logger.Prm err := logPrm.SetLevelString( @@ -316,10 +314,10 @@ func initCfg(path string) *cfg { Key: &key.PrivateKey, }), persistate: persistate, - - ownerIDFromKey: ownerIDFromKey, } + user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey) + if metricsconfig.Address(c.appCfg) != "" { c.metricsCollector = metrics.NewStorageMetrics() netState.metrics = c.metricsCollector diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 4db787b8..a29aba24 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -32,7 +32,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" "github.com/nspcc-dev/neofs-sdk-go/netmap" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" ) @@ -557,7 +557,7 @@ type morphContainerReader struct { get containerCore.Source lister interface { - List(*owner.ID) ([]*cid.ID, error) + List(*user.ID) ([]*cid.ID, error) } } @@ -569,7 +569,7 @@ func (x *morphContainerReader) GetEACL(id *cid.ID) (*eaclSDK.Table, error) { return x.eacl.GetEACL(id) } -func (x *morphContainerReader) List(id *owner.ID) ([]*cid.ID, error) { +func (x *morphContainerReader) List(id *user.ID) ([]*cid.ID, error) { return x.lister.List(id) } diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index fe28a0ab..06852efa 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -43,7 +43,7 @@ import ( eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" ) @@ -124,8 +124,8 @@ func (i *delNetInfo) TombstoneLifetime() (uint64, error) { // returns node owner ID calculated from configured private key. // // Implements method needed for Object.Delete service. -func (i *delNetInfo) LocalNodeID() *owner.ID { - return i.cfg.ownerIDFromKey +func (i *delNetInfo) LocalNodeID() *user.ID { + return &i.cfg.ownerIDFromKey } type innerRingFetcherWithNotary struct { diff --git a/cmd/neofs-node/session.go b/cmd/neofs-node/session.go index c78f93d6..b96e9d7b 100644 --- a/cmd/neofs-node/session.go +++ b/cmd/neofs-node/session.go @@ -15,12 +15,12 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage/persistent" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage/temporary" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) type sessionStorage interface { Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) - Get(ownerID *owner.ID, tokenID []byte) *storage.PrivateToken + Get(ownerID *user.ID, tokenID []byte) *storage.PrivateToken RemoveOld(epoch uint64) Close() error diff --git a/go.mod b/go.mod index 55b3304e..d9c6dbc2 100644 --- a/go.mod +++ b/go.mod @@ -18,8 +18,8 @@ require ( github.com/nspcc-dev/neo-go v0.98.2 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321144137-d5a9af5860af // indirect github.com/nspcc-dev/neofs-api-go/v2 v2.12.1 - github.com/nspcc-dev/neofs-contract v0.14.2 - github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220419095511-d20999113a2e + github.com/nspcc-dev/neofs-contract v0.15.1 + github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220424111116-497053c785f5 github.com/nspcc-dev/tzhash v1.5.2 github.com/panjf2000/ants/v2 v2.4.0 github.com/paulmach/orb v0.2.2 diff --git a/go.sum b/go.sum index 11c3cf584964dacac29c0f8b680f19d5b878279f..65cc8fac025a9a9f2b2e455beba5d22929c67909 100644 GIT binary patch delta 289 zcmZ4WpLNxL)(tf?j7;?m6*3I142z7+OH6{@z1_^i4FiG#{5{h$i;`ULNfd! z{Swndw1Yhplad`L3(l0ATrh*j5~x)_Jzp<3KLun$c7?xbR7hb;m0MnruW68PnXk56 zMvAtvyL*vWzL{gLyHQl7qou!dVPW8A!I>+WT#QT%LBLGc#M0cr)HvDP!ZghkWKwBC zW{6p4n17{(VM%7BQH80cv8#o4Zbd| E03=vl`Tzg` delta 284 zcmZ4WpLNxL)(tf?j7;>56fz90a*e|)Onv+<1AV%SibG9;1B%VegVI8r zgUteiD>Dk6vz;9$3(l0ATrh*j5~x)_Jzp<3KLun$d9b5FPOeL#Yfy2LflqO8K!tx* zc4VkeQHXP*f3l@ll)IUMWvQQ^Q&sY2!I>+WoDD4vEKN-f4RuqD3@j}z4GoPGjZ#4- zrDdj=I2SpYJ9!lshh}64CYkz`IBGjb7= t.NotBefore() && epoch <= t.Expiration() } -func isOwnerFromKey(id *owner.ID, key *keys.PublicKey) bool { +func isOwnerFromKey(id *user.ID, key *keys.PublicKey) bool { if id == nil || key == nil { return false } - return id.Equal(owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key))) + var id2 user.ID + user.IDFromKey(&id2, (ecdsa.PublicKey)(*key)) + + return id.Equals(id2) } func unmarshalPublicKey(bs []byte) *keys.PublicKey { diff --git a/pkg/services/object/acl/acl_test.go b/pkg/services/object/acl/acl_test.go index fea870ea..409ab008 100644 --- a/pkg/services/object/acl/acl_test.go +++ b/pkg/services/object/acl/acl_test.go @@ -7,8 +7,8 @@ import ( v2 "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/v2" cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" - "github.com/nspcc-dev/neofs-sdk-go/owner" - ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test" + "github.com/nspcc-dev/neofs-sdk-go/user" + usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/stretchr/testify/require" ) @@ -40,11 +40,11 @@ func TestStickyCheck(t *testing.T) { setSticky(&info, true) - require.True(t, checker.StickyBitCheck(info, ownertest.ID())) + require.True(t, checker.StickyBitCheck(info, usertest.ID())) setSticky(&info, false) - require.True(t, checker.StickyBitCheck(info, ownertest.ID())) + require.True(t, checker.StickyBitCheck(info, usertest.ID())) }) t.Run("owner ID and/or public key emptiness", func(t *testing.T) { @@ -65,10 +65,10 @@ func TestStickyCheck(t *testing.T) { info.SetSenderKey(nil) } - var ownerID *owner.ID + var ownerID *user.ID if withOwner { - ownerID = ownertest.ID() + ownerID = usertest.ID() } require.Equal(t, expected, checker.StickyBitCheck(info, ownerID)) diff --git a/pkg/services/object/acl/eacl/v2/headers.go b/pkg/services/object/acl/eacl/v2/headers.go index dd2163cd..3caf9984 100644 --- a/pkg/services/object/acl/eacl/v2/headers.go +++ b/pkg/services/object/acl/eacl/v2/headers.go @@ -13,7 +13,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/object" objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address" objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) type Option func(*cfg) @@ -216,7 +216,7 @@ func oidHeader(oid objectSDKID.ID) sysObjHdr { } } -func ownerIDHeader(ownerID *owner.ID) sysObjHdr { +func ownerIDHeader(ownerID user.ID) sysObjHdr { return sysObjHdr{ k: acl.FilterObjectOwnerID, v: ownerID.String(), diff --git a/pkg/services/object/acl/eacl/v2/object.go b/pkg/services/object/acl/eacl/v2/object.go index 531b5c47..8f4ee3fb 100644 --- a/pkg/services/object/acl/eacl/v2/object.go +++ b/pkg/services/object/acl/eacl/v2/object.go @@ -38,8 +38,6 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac res = append(res, cidHeader(cnr), - // owner ID - ownerIDHeader(obj.OwnerID()), // creation epoch sysObjHdr{ k: acl.FilterObjectCreationEpoch, @@ -63,6 +61,10 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac }, ) + if idOwner := obj.OwnerID(); idOwner != nil { + res = append(res, ownerIDHeader(*idOwner)) + } + cs, ok := obj.PayloadChecksum() if ok { res = append(res, sysObjHdr{ diff --git a/pkg/services/object/acl/v2/classifier.go b/pkg/services/object/acl/v2/classifier.go index 72410d6c..8fe2329a 100644 --- a/pkg/services/object/acl/v2/classifier.go +++ b/pkg/services/object/acl/v2/classifier.go @@ -35,6 +35,11 @@ func (c senderClassifier) classify( return nil, errContainerIDNotSet } + ownerCnr := cnr.OwnerID() + if ownerCnr == nil { + return nil, errors.New("missing container owner") + } + ownerID, ownerKey, err := req.RequestOwner() if err != nil { return nil, err @@ -45,7 +50,7 @@ func (c senderClassifier) classify( // TODO: #767 get owner from neofs.id if present // if request owner is the same as container owner, return RoleUser - if ownerID.Equal(cnr.OwnerID()) { + if ownerID.Equals(*ownerCnr) { return &classifyResult{ role: eaclSDK.RoleUser, isIR: false, diff --git a/pkg/services/object/acl/v2/request.go b/pkg/services/object/acl/v2/request.go index 547765bb..331c7928 100644 --- a/pkg/services/object/acl/v2/request.go +++ b/pkg/services/object/acl/v2/request.go @@ -10,8 +10,8 @@ import ( containerIDSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" - "github.com/nspcc-dev/neofs-sdk-go/owner" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" ) // RequestInfo groups parsed version-independent (from SDK library) @@ -21,7 +21,7 @@ type RequestInfo struct { requestRole eaclSDK.Role isInnerRing bool operation eaclSDK.Operation // put, get, head, etc. - cnrOwner *owner.ID // container owner + cnrOwner *user.ID // container owner idCnr *containerIDSDK.ID @@ -52,7 +52,7 @@ func (r RequestInfo) Request() interface{} { } // ContainerOwner returns owner if the container. -func (r RequestInfo) ContainerOwner() *owner.ID { +func (r RequestInfo) ContainerOwner() *user.ID { return r.cnrOwner } @@ -112,7 +112,7 @@ type MetaWithToken struct { // RequestOwner returns ownerID and its public key // according to internal meta information. -func (r MetaWithToken) RequestOwner() (*owner.ID, *keys.PublicKey, error) { +func (r MetaWithToken) RequestOwner() (*user.ID, *keys.PublicKey, error) { if r.vheader == nil { return nil, nil, fmt.Errorf("%w: nil verification header", ErrMalformedRequest) } @@ -129,7 +129,13 @@ func (r MetaWithToken) RequestOwner() (*owner.ID, *keys.PublicKey, error) { return nil, nil, fmt.Errorf("%w: nil at body signature", ErrMalformedRequest) } - key := unmarshalPublicKey(bodySignature.GetKey()) + key, err := unmarshalPublicKey(bodySignature.GetKey()) + if err != nil { + return nil, nil, fmt.Errorf("invalid key in body signature: %w", err) + } - return owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key)), key, nil + var idSender user.ID + user.IDFromKey(&idSender, (ecdsa.PublicKey)(*key)) + + return &idSender, key, nil } diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index d671afae..e51a6b2e 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -12,6 +12,7 @@ import ( cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" ) @@ -366,9 +367,16 @@ func (p putStreamBasicChecker) Send(request *objectV2.PutRequest) error { return err } - ownerID, err := getObjectOwnerFromMessage(request) + idV2 := part.GetHeader().GetOwnerID() + if idV2 == nil { + return errors.New("missing object owner") + } + + var idOwner user.ID + + err = idOwner.ReadFromV2(*idV2) if err != nil { - return err + return fmt.Errorf("invalid object owner: %w", err) } sTok := sessionSDK.NewTokenFromV2(request.GetMetaHeader().GetSessionToken()) @@ -392,7 +400,7 @@ func (p putStreamBasicChecker) Send(request *objectV2.PutRequest) error { useObjectIDFromSession(&reqInfo, sTok) - if !p.source.checker.CheckBasicACL(reqInfo) || !p.source.checker.StickyBitCheck(reqInfo, ownerID) { + if !p.source.checker.CheckBasicACL(reqInfo) || !p.source.checker.StickyBitCheck(reqInfo, &idOwner) { return basicACLErr(reqInfo) } else if err := p.source.checker.CheckEACL(request, reqInfo); err != nil { return eACLErr(reqInfo, err) diff --git a/pkg/services/object/acl/v2/types.go b/pkg/services/object/acl/v2/types.go index 0ce0146e..bf92c4ac 100644 --- a/pkg/services/object/acl/v2/types.go +++ b/pkg/services/object/acl/v2/types.go @@ -1,7 +1,7 @@ package v2 import ( - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) // ACLChecker is an interface that must provide @@ -16,7 +16,7 @@ type ACLChecker interface { // StickyBitCheck must return true only if sticky bit // is disabled or enabled but request contains correct // owner field. - StickyBitCheck(RequestInfo, *owner.ID) bool + StickyBitCheck(RequestInfo, *user.ID) bool } // InnerRingFetcher is an interface that must provide diff --git a/pkg/services/object/acl/v2/util.go b/pkg/services/object/acl/v2/util.go index 91eb1631..a5fb291d 100644 --- a/pkg/services/object/acl/v2/util.go +++ b/pkg/services/object/acl/v2/util.go @@ -14,8 +14,8 @@ import ( containerIDSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" - "github.com/nspcc-dev/neofs-sdk-go/owner" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" ) var errMissingContainerID = errors.New("missing container ID") @@ -113,27 +113,6 @@ func getObjectIDFromRequestBody(body interface{}) (*oidSDK.ID, error) { return &id, nil } -func getObjectOwnerFromMessage(req interface{}) (id *owner.ID, err error) { - switch v := req.(type) { - case *objectV2.PutRequest: - objPart := v.GetBody().GetObjectPart() - if part, ok := objPart.(*objectV2.PutObjectPartInit); ok { - return owner.NewIDFromV2(part.GetHeader().GetOwnerID()), nil - } - - return nil, errors.New("can't get container ID in chunk") - case *objectV2.GetResponse: - objPart := v.GetBody().GetObjectPart() - if part, ok := objPart.(*objectV2.GetObjectPartInit); ok { - return owner.NewIDFromV2(part.GetHeader().GetOwnerID()), nil - } - - return nil, errors.New("can't get container ID in chunk") - default: - return nil, errors.New("unsupported request type") - } -} - // sourceVerbOfRequest looks for verb in session token and if it is not found, // returns reqVerb. Second return value is true if operation is unknown. func sourceVerbOfRequest(tok *sessionSDK.Token, reqVerb eaclSDK.Operation) (eaclSDK.Operation, bool) { @@ -185,7 +164,7 @@ func tokenVerbToOperation(ctx *sessionSDK.ObjectContext) eaclSDK.Operation { } } -func ownerFromToken(token *sessionSDK.Token) (*owner.ID, *keys.PublicKey, error) { +func ownerFromToken(token *sessionSDK.Token) (*user.ID, *keys.PublicKey, error) { // 1. First check signature of session token. if !token.VerifySignature() { return nil, nil, fmt.Errorf("%w: invalid session token signature", ErrMalformedRequest) @@ -195,7 +174,11 @@ func ownerFromToken(token *sessionSDK.Token) (*owner.ID, *keys.PublicKey, error) // TODO(@cthulhu-rider): #1387 implement and use another approach to avoid conversion tokV2 := token.ToV2() - tokenIssuerKey := unmarshalPublicKey(tokV2.GetSignature().GetKey()) + tokenIssuerKey, err := unmarshalPublicKey(tokV2.GetSignature().GetKey()) + if err != nil { + return nil, nil, fmt.Errorf("invalid key in session token signature: %w", err) + } + tokenOwner := token.OwnerID() if !isOwnerFromKey(tokenOwner, tokenIssuerKey) { @@ -218,20 +201,19 @@ func originalBodySignature(v *sessionV2.RequestVerificationHeader) *refsV2.Signa return v.GetBodySignature() } -func unmarshalPublicKey(bs []byte) *keys.PublicKey { - pub, err := keys.NewPublicKeyFromBytes(bs, elliptic.P256()) - if err != nil { - return nil - } - return pub +func unmarshalPublicKey(bs []byte) (*keys.PublicKey, error) { + return keys.NewPublicKeyFromBytes(bs, elliptic.P256()) } -func isOwnerFromKey(id *owner.ID, key *keys.PublicKey) bool { +func isOwnerFromKey(id *user.ID, key *keys.PublicKey) bool { if id == nil || key == nil { return false } - return id.Equal(owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key))) + var id2 user.ID + user.IDFromKey(&id2, (ecdsa.PublicKey)(*key)) + + return id2.Equals(*id) } // isVerbCompatible checks that tokenVerb operation can create auxiliary op operation. diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index 2a711bb3..45ebe7fe 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/object" oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" ) @@ -30,7 +30,7 @@ type NetworkInfo interface { // Returns user ID of the local storage node. Result must not be nil. // New tombstone objects will have the result as an owner ID if removal is executed w/o a session. - LocalNodeID() *owner.ID + LocalNodeID() *user.ID } type cfg struct { diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 68370241..42a09ee7 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/nspcc-dev/neofs-sdk-go/object" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) type Streamer struct { @@ -91,9 +91,20 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error { // In case session token is missing, the line above returns the default key. // If it isn't owner key, replication attempts will fail, thus this check. - if sToken == nil && !prm.hdr.OwnerID().Equal(owner.NewIDFromPublicKey(&sessionKey.PublicKey)) { - return fmt.Errorf("(%T) session token is missing but object owner id is different from the default key", p) + if sToken == nil { + ownerObj := prm.hdr.OwnerID() + if ownerObj == nil { + return errors.New("missing object owner") + } + + var ownerSession user.ID + user.IDFromKey(&ownerSession, sessionKey.PublicKey) + + if !ownerObj.Equals(ownerSession) { + return fmt.Errorf("(%T) session token is missing but object owner id is different from the default key", p) + } } + p.target = &validatingTarget{ fmt: p.fmtValidator, unpreparedObject: true, diff --git a/pkg/services/object/util/key.go b/pkg/services/object/util/key.go index a5e86db8..93c324bb 100644 --- a/pkg/services/object/util/key.go +++ b/pkg/services/object/util/key.go @@ -6,8 +6,8 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" + "github.com/nspcc-dev/neofs-sdk-go/user" ) // SessionSource is an interface tha provides @@ -19,7 +19,7 @@ type SessionSource interface { // token has not been created, has been expired // of it is impossible to get information about the // token Get must return nil. - Get(owner *owner.ID, tokenID []byte) *storage.PrivateToken + Get(owner *user.ID, tokenID []byte) *storage.PrivateToken } // KeyStorage represents private key storage of the local node. diff --git a/pkg/services/object/util/key_test.go b/pkg/services/object/util/key_test.go index 0e42b70f..528a3031 100644 --- a/pkg/services/object/util/key_test.go +++ b/pkg/services/object/util/key_test.go @@ -7,10 +7,12 @@ import ( "github.com/google/uuid" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neofs-api-go/v2/refs" sessionV2 "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage/temporary" "github.com/nspcc-dev/neofs-sdk-go/session" + usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/stretchr/testify/require" ) @@ -62,13 +64,19 @@ func generateToken(t *testing.T) *session.Token { tok := session.NewToken() tok.SetSessionKey(pubKey) tok.SetID(id) + tok.SetOwnerID(usertest.ID()) return tok } func createToken(t *testing.T, store *tokenStorage.TokenStore, exp uint64) *session.Token { + owner := usertest.ID() + + var ownerV2 refs.OwnerID + owner.WriteToV2(&ownerV2) + req := new(sessionV2.CreateRequestBody) - req.SetOwnerID(nil) + req.SetOwnerID(&ownerV2) req.SetExpiration(exp) resp, err := store.Create(context.Background(), req) @@ -77,6 +85,7 @@ func createToken(t *testing.T, store *tokenStorage.TokenStore, exp uint64) *sess tok := session.NewToken() tok.SetSessionKey(resp.GetSessionKey()) tok.SetID(resp.GetID()) + tok.SetOwnerID(owner) return tok } diff --git a/pkg/services/session/storage/persistent/executor.go b/pkg/services/session/storage/persistent/executor.go index 415a428e..da1de95c 100644 --- a/pkg/services/session/storage/persistent/executor.go +++ b/pkg/services/session/storage/persistent/executor.go @@ -2,13 +2,13 @@ package persistent import ( "context" - "encoding/hex" + "errors" "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "go.etcd.io/bbolt" ) @@ -18,9 +18,16 @@ import ( // Returns response that is filled with just created token's // ID and public key for it. func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) { - ownerBytes, err := owner.NewIDFromV2(body.GetOwnerID()).Marshal() + idV2 := body.GetOwnerID() + if idV2 == nil { + return nil, errors.New("missing owner") + } + + var id user.ID + + err := id.ReadFromV2(*idV2) if err != nil { - panic(err) + return nil, fmt.Errorf("invalid owner: %w", err) } uidBytes, err := storage.NewTokenID() @@ -41,21 +48,15 @@ func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody err = s.db.Update(func(tx *bbolt.Tx) error { rootBucket := tx.Bucket(sessionsBucket) - ownerBucket, err := rootBucket.CreateBucketIfNotExists(ownerBytes) + ownerBucket, err := rootBucket.CreateBucketIfNotExists(id.WalletBytes()) if err != nil { return fmt.Errorf( - "could not get/create %s owner bucket: %w", - hex.EncodeToString(ownerBytes), - err, - ) + "could not get/create %s owner bucket: %w", id, err) } err = ownerBucket.Put(uidBytes, value) if err != nil { - return fmt.Errorf("could not put session token for %s oid: %w", - hex.EncodeToString(ownerBytes), - err, - ) + return fmt.Errorf("could not put session token for %s oid: %w", id, err) } return nil diff --git a/pkg/services/session/storage/persistent/executor_test.go b/pkg/services/session/storage/persistent/executor_test.go index c843c521..ea7933c5 100644 --- a/pkg/services/session/storage/persistent/executor_test.go +++ b/pkg/services/session/storage/persistent/executor_test.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/session" - ownerSDK "github.com/nspcc-dev/neofs-sdk-go/owner" + usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/stretchr/testify/require" "go.etcd.io/bbolt" ) @@ -22,11 +22,13 @@ func TestTokenStore(t *testing.T) { defer ts.Close() - owner := new(refs.OwnerID) - owner.SetValue([]byte{0, 1, 2, 3, 4, 5}) + owner := usertest.ID() + + var ownerV2 refs.OwnerID + owner.WriteToV2(&ownerV2) req := new(session.CreateRequestBody) - req.SetOwnerID(owner) + req.SetOwnerID(&ownerV2) const tokenNumber = 5 @@ -50,7 +52,7 @@ func TestTokenStore(t *testing.T) { } for i, token := range tokens { - savedToken := ts.Get(ownerSDK.NewIDFromV2(owner), token.id) + savedToken := ts.Get(owner, token.id) require.Equal(t, uint64(i), savedToken.ExpiredAt()) @@ -64,13 +66,15 @@ func TestTokenStore_Persistent(t *testing.T) { ts, err := NewTokenStore(path) require.NoError(t, err) - owner := new(refs.OwnerID) - owner.SetValue([]byte{0, 1, 2, 3, 4, 5}) + idOwner := usertest.ID() + + var idOwnerV2 refs.OwnerID + idOwner.WriteToV2(&idOwnerV2) const exp = 12345 req := new(session.CreateRequestBody) - req.SetOwnerID(owner) + req.SetOwnerID(&idOwnerV2) req.SetExpiration(exp) res, err := ts.Create(context.Background(), req) @@ -88,7 +92,7 @@ func TestTokenStore_Persistent(t *testing.T) { defer ts.Close() - savedToken := ts.Get(ownerSDK.NewIDFromV2(owner), id) + savedToken := ts.Get(idOwner, id) equalKeys(t, pubKey, savedToken.SessionKey()) } @@ -123,11 +127,13 @@ func TestTokenStore_RemoveOld(t *testing.T) { defer ts.Close() - owner := new(refs.OwnerID) - owner.SetValue([]byte{0, 1, 2, 3, 4, 5}) + owner := usertest.ID() + + var ownerV2 refs.OwnerID + owner.WriteToV2(&ownerV2) req := new(session.CreateRequestBody) - req.SetOwnerID(owner) + req.SetOwnerID(&ownerV2) for _, test := range tests { req.SetExpiration(test.epoch) @@ -144,7 +150,7 @@ func TestTokenStore_RemoveOld(t *testing.T) { ts.RemoveOld(currEpoch) for _, test := range tests { - token := ts.Get(ownerSDK.NewIDFromV2(owner), test.id) + token := ts.Get(owner, test.id) if test.epoch <= currEpoch { require.Nil(t, token) diff --git a/pkg/services/session/storage/persistent/storage.go b/pkg/services/session/storage/persistent/storage.go index 3e52a8dc..65f1e388 100644 --- a/pkg/services/session/storage/persistent/storage.go +++ b/pkg/services/session/storage/persistent/storage.go @@ -7,7 +7,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" - ownerSDK "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -83,16 +83,11 @@ func NewTokenStore(path string, opts ...Option) (*TokenStore, error) { // Get returns private token corresponding to the given identifiers. // // Returns nil is there is no element in storage. -func (s *TokenStore) Get(ownerID *ownerSDK.ID, tokenID []byte) (t *storage.PrivateToken) { - ownerBytes, err := ownerID.Marshal() - if err != nil { - panic(err) - } - - err = s.db.View(func(tx *bbolt.Tx) error { +func (s *TokenStore) Get(ownerID *user.ID, tokenID []byte) (t *storage.PrivateToken) { + err := s.db.View(func(tx *bbolt.Tx) error { rootBucket := tx.Bucket(sessionsBucket) - ownerBucket := rootBucket.Bucket(ownerBytes) + ownerBucket := rootBucket.Bucket(ownerID.WalletBytes()) if ownerBucket == nil { return nil } @@ -102,6 +97,8 @@ func (s *TokenStore) Get(ownerID *ownerSDK.ID, tokenID []byte) (t *storage.Priva return nil } + var err error + t, err = s.unpackToken(rawToken) if err != nil { return err diff --git a/pkg/services/session/storage/temporary/executor.go b/pkg/services/session/storage/temporary/executor.go index 6ca5f17d..b896e631 100644 --- a/pkg/services/session/storage/temporary/executor.go +++ b/pkg/services/session/storage/temporary/executor.go @@ -2,19 +2,27 @@ package temporary import ( "context" + "errors" "fmt" "github.com/mr-tron/base58" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) { - ownerBytes, err := owner.NewIDFromV2(body.GetOwnerID()).Marshal() + idV2 := body.GetOwnerID() + if idV2 == nil { + return nil, errors.New("missing owner") + } + + var id user.ID + + err := id.ReadFromV2(*idV2) if err != nil { - panic(err) + return nil, fmt.Errorf("invalid owner: %w", err) } uidBytes, err := storage.NewTokenID() @@ -30,7 +38,7 @@ func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody s.mtx.Lock() s.tokens[key{ tokenID: base58.Encode(uidBytes), - ownerID: base58.Encode(ownerBytes), + ownerID: base58.Encode(id.WalletBytes()), }] = storage.NewPrivateToken(&sk.PrivateKey, body.GetExpiration()) s.mtx.Unlock() diff --git a/pkg/services/session/storage/temporary/storage.go b/pkg/services/session/storage/temporary/storage.go index 7ede70ce..7ea5bd1a 100644 --- a/pkg/services/session/storage/temporary/storage.go +++ b/pkg/services/session/storage/temporary/storage.go @@ -5,7 +5,7 @@ import ( "github.com/mr-tron/base58" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" - "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/user" ) type key struct { @@ -36,16 +36,11 @@ func NewTokenStore() *TokenStore { // Get returns private token corresponding to the given identifiers. // // Returns nil is there is no element in storage. -func (s *TokenStore) Get(ownerID *owner.ID, tokenID []byte) *storage.PrivateToken { - ownerBytes, err := ownerID.Marshal() - if err != nil { - panic(err) - } - +func (s *TokenStore) Get(ownerID *user.ID, tokenID []byte) *storage.PrivateToken { s.mtx.RLock() t := s.tokens[key{ tokenID: base58.Encode(tokenID), - ownerID: base58.Encode(ownerBytes), + ownerID: base58.Encode(ownerID.WalletBytes()), }] s.mtx.RUnlock()