forked from TrueCloudLab/frostfs-node
[#1556] Upgrade NeoFS SDK Go with changed container API
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f699e82ea7
commit
c165d1a9b5
36 changed files with 207 additions and 480 deletions
|
@ -3,7 +3,6 @@ package v2
|
|||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
|
||||
core "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||
|
@ -27,12 +26,7 @@ type classifyResult struct {
|
|||
func (c senderClassifier) classify(
|
||||
req MetaWithToken,
|
||||
idCnr cid.ID,
|
||||
cnr *container.Container) (res *classifyResult, err error) {
|
||||
ownerCnr := cnr.OwnerID()
|
||||
if ownerCnr == nil {
|
||||
return nil, errors.New("missing container owner")
|
||||
}
|
||||
|
||||
cnr container.Container) (res *classifyResult, err error) {
|
||||
ownerID, ownerKey, err := req.RequestOwner()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -43,7 +37,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.Equals(*ownerCnr) {
|
||||
if ownerID.Equals(cnr.Owner()) {
|
||||
return &classifyResult{
|
||||
role: acl.RoleOwner,
|
||||
key: ownerKeyInBytes,
|
||||
|
@ -104,7 +98,7 @@ func (c senderClassifier) isInnerRingKey(owner []byte) (bool, error) {
|
|||
|
||||
func (c senderClassifier) isContainerKey(
|
||||
owner, idCnr []byte,
|
||||
cnr *container.Container) (bool, error) {
|
||||
cnr container.Container) (bool, error) {
|
||||
nm, err := core.GetLatestNetworkMap(c.netmap) // first check current netmap
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -130,13 +124,8 @@ func (c senderClassifier) isContainerKey(
|
|||
func lookupKeyInContainer(
|
||||
nm *netmap.NetMap,
|
||||
owner, idCnr []byte,
|
||||
cnr *container.Container) (bool, error) {
|
||||
policy := cnr.PlacementPolicy()
|
||||
if policy == nil {
|
||||
return false, errors.New("missing placement policy in container")
|
||||
}
|
||||
|
||||
cnrVectors, err := nm.ContainerNodes(*policy, idCnr)
|
||||
cnr container.Container) (bool, error) {
|
||||
cnrVectors, err := nm.ContainerNodes(cnr.PlacementPolicy(), idCnr)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -506,8 +506,6 @@ func (b Service) findRequestInfo(req MetaWithToken, idCnr cid.ID, op acl.Op) (in
|
|||
cnr, err := b.containers.Get(idCnr) // fetch actual container
|
||||
if err != nil {
|
||||
return info, err
|
||||
} else if cnr.Value.OwnerID() == nil {
|
||||
return info, errors.New("missing owner in container descriptor")
|
||||
}
|
||||
|
||||
if req.token != nil {
|
||||
|
@ -534,7 +532,7 @@ func (b Service) findRequestInfo(req MetaWithToken, idCnr cid.ID, op acl.Op) (in
|
|||
info.basicACL = cnr.Value.BasicACL()
|
||||
info.requestRole = res.role
|
||||
info.operation = op
|
||||
info.cnrOwner = *cnr.Value.OwnerID()
|
||||
info.cnrOwner = cnr.Value.Owner()
|
||||
info.idCnr = idCnr
|
||||
|
||||
// it is assumed that at the moment the key will be valid,
|
||||
|
|
|
@ -35,7 +35,7 @@ type testStorage struct {
|
|||
}
|
||||
|
||||
type testTraverserGenerator struct {
|
||||
c *container.Container
|
||||
c container.Container
|
||||
b map[uint64]placement.Builder
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func newTestStorage() *testStorage {
|
|||
}
|
||||
|
||||
func (g *testTraverserGenerator) GenerateTraverser(cnr cid.ID, obj *oid.ID, e uint64) (*placement.Traverser, error) {
|
||||
opts := make([]placement.Option, 3, 4)
|
||||
opts := make([]placement.Option, 0, 4)
|
||||
opts = append(opts,
|
||||
placement.ForContainer(g.c),
|
||||
placement.UseBuilder(g.b[e]),
|
||||
|
@ -466,9 +466,11 @@ func generateChain(ln int, cnr cid.ID) ([]*objectSDK.Object, []oid.ID, []byte) {
|
|||
func TestGetRemoteSmall(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
pp := netmaptest.PlacementPolicy()
|
||||
cnr := container.New(container.WithPolicy(&pp))
|
||||
idCnr := container.CalculateID(cnr)
|
||||
var cnr container.Container
|
||||
cnr.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
||||
|
||||
var idCnr cid.ID
|
||||
container.CalculateID(&idCnr, cnr)
|
||||
|
||||
newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service {
|
||||
svc := &Service{cfg: new(cfg)}
|
||||
|
@ -1119,9 +1121,11 @@ func TestGetRemoteSmall(t *testing.T) {
|
|||
func TestGetFromPastEpoch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
pp := netmaptest.PlacementPolicy()
|
||||
cnr := container.New(container.WithPolicy(&pp))
|
||||
idCnr := container.CalculateID(cnr)
|
||||
var cnr container.Container
|
||||
cnr.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
||||
|
||||
var idCnr cid.ID
|
||||
container.CalculateID(&idCnr, cnr)
|
||||
|
||||
addr := oidtest.Address()
|
||||
addr.SetContainer(idCnr)
|
||||
|
|
|
@ -33,7 +33,7 @@ type testStorage struct {
|
|||
}
|
||||
|
||||
type testTraverserGenerator struct {
|
||||
c *container.Container
|
||||
c container.Container
|
||||
b map[uint64]placement.Builder
|
||||
}
|
||||
|
||||
|
@ -241,8 +241,11 @@ func TestGetRemoteSmall(t *testing.T) {
|
|||
var pp netmap.PlacementPolicy
|
||||
pp.AddReplicas(rs...)
|
||||
|
||||
cnr := container.New(container.WithPolicy(&pp))
|
||||
id := container.CalculateID(cnr)
|
||||
var cnr container.Container
|
||||
cnr.SetPlacementPolicy(pp)
|
||||
|
||||
var id cid.ID
|
||||
container.CalculateID(&id, cnr)
|
||||
|
||||
newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service {
|
||||
svc := &Service{cfg: new(cfg)}
|
||||
|
@ -327,8 +330,11 @@ func TestGetFromPastEpoch(t *testing.T) {
|
|||
var pp netmap.PlacementPolicy
|
||||
pp.AddReplicas(rs...)
|
||||
|
||||
cnr := container.New(container.WithPolicy(&pp))
|
||||
idCnr := container.CalculateID(cnr)
|
||||
var cnr container.Container
|
||||
cnr.SetPlacementPolicy(pp)
|
||||
|
||||
var idCnr cid.ID
|
||||
container.CalculateID(&idCnr, cnr)
|
||||
|
||||
var addr oid.Address
|
||||
addr.SetContainer(idCnr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue