[#564] Upgrade NeoFS SDK Go with changed container API
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
d2a3ba0c06
commit
4a8a248f34
6 changed files with 57 additions and 67 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/user"
|
||||
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -73,6 +74,7 @@ func prepareHandlerContext(t *testing.T) *handlerContext {
|
|||
|
||||
func createTestBucket(ctx context.Context, t *testing.T, h *handlerContext, bktName string) {
|
||||
_, err := h.MockedPool().CreateContainer(ctx, layer.PrmContainerCreate{
|
||||
Creator: *usertest.ID(),
|
||||
Name: bktName,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
@ -80,6 +82,7 @@ func createTestBucket(ctx context.Context, t *testing.T, h *handlerContext, bktN
|
|||
|
||||
func createTestBucketWithLock(ctx context.Context, t *testing.T, h *handlerContext, bktName string, conf *data.ObjectLockConfiguration) *data.BucketInfo {
|
||||
cnrID, err := h.MockedPool().CreateContainer(ctx, layer.PrmContainerCreate{
|
||||
Creator: *usertest.ID(),
|
||||
Name: bktName,
|
||||
AdditionalAttributes: [][2]string{{layer.AttributeLockEnabled, "true"}},
|
||||
})
|
||||
|
|
|
@ -52,31 +52,21 @@ func (n *layer) containerInfo(ctx context.Context, idCnr cid.ID) (*data.BucketIn
|
|||
return nil, fmt.Errorf("get neofs container: %w", err)
|
||||
}
|
||||
|
||||
info.Owner = *res.OwnerID()
|
||||
cnr := *res
|
||||
|
||||
for _, attr := range res.Attributes() {
|
||||
switch key, val := attr.Key(), attr.Value(); key {
|
||||
case container.AttributeName:
|
||||
info.Name = val
|
||||
case container.AttributeTimestamp:
|
||||
unix, err := strconv.ParseInt(attr.Value(), 10, 64)
|
||||
if err != nil {
|
||||
log.Error("could not parse container creation time",
|
||||
zap.String("created_at", val), zap.Error(err))
|
||||
info.Owner = cnr.Owner()
|
||||
info.Name = container.Name(cnr)
|
||||
info.Created = container.CreatedAt(cnr)
|
||||
info.LocationConstraint = cnr.Attribute(attributeLocationConstraint)
|
||||
|
||||
continue
|
||||
}
|
||||
attrLockEnabled := cnr.Attribute(AttributeLockEnabled)
|
||||
|
||||
info.Created = time.Unix(unix, 0)
|
||||
case attributeLocationConstraint:
|
||||
info.LocationConstraint = val
|
||||
case AttributeLockEnabled:
|
||||
info.ObjectLockEnabled, err = strconv.ParseBool(val)
|
||||
info.ObjectLockEnabled, err = strconv.ParseBool(attrLockEnabled)
|
||||
if err != nil {
|
||||
log.Error("could not parse container object lock enabled attribute",
|
||||
zap.String("lock_enabled", val), zap.Error(err))
|
||||
}
|
||||
}
|
||||
zap.String("lock_enabled", attrLockEnabled),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
if err = n.bucketCache.Put(info); err != nil {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -55,36 +54,35 @@ func (t *TestNeoFS) AddObject(key string, obj *object.Object) {
|
|||
|
||||
func (t *TestNeoFS) ContainerID(name string) (*cid.ID, error) {
|
||||
for id, cnr := range t.containers {
|
||||
for _, attr := range cnr.Attributes() {
|
||||
if attr.Key() == container.AttributeName && attr.Value() == name {
|
||||
if container.Name(*cnr) == name {
|
||||
var cnrID cid.ID
|
||||
return &cnrID, cnrID.DecodeString(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
|
||||
func (t *TestNeoFS) CreateContainer(_ context.Context, prm PrmContainerCreate) (*cid.ID, error) {
|
||||
opts := []container.Option{
|
||||
container.WithOwnerID(&prm.Creator),
|
||||
container.WithPolicy(&prm.Policy),
|
||||
container.WithCustomBasicACL(prm.BasicACL),
|
||||
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10)),
|
||||
var cnr container.Container
|
||||
cnr.Init()
|
||||
cnr.SetOwner(prm.Creator)
|
||||
cnr.SetPlacementPolicy(prm.Policy)
|
||||
cnr.SetBasicACL(prm.BasicACL)
|
||||
container.SetCreationTime(&cnr, time.Now())
|
||||
|
||||
if prm.Name != "" {
|
||||
container.SetName(&cnr, prm.Name)
|
||||
}
|
||||
|
||||
for i := range prm.AdditionalAttributes {
|
||||
cnr.SetAttribute(prm.AdditionalAttributes[i][0], prm.AdditionalAttributes[i][1])
|
||||
}
|
||||
|
||||
if prm.Name != "" {
|
||||
opts = append(opts, container.WithAttribute(container.AttributeName, prm.Name))
|
||||
}
|
||||
var d container.Domain
|
||||
d.SetName(prm.Name)
|
||||
|
||||
for _, attr := range prm.AdditionalAttributes {
|
||||
opts = append(opts, container.WithAttribute(attr[0], attr[1]))
|
||||
}
|
||||
|
||||
cnr := container.New(opts...)
|
||||
|
||||
if prm.Name != "" {
|
||||
container.SetNativeName(cnr, prm.Name)
|
||||
container.WriteDomain(&cnr, d)
|
||||
}
|
||||
|
||||
b := make([]byte, 32)
|
||||
|
@ -94,7 +92,7 @@ func (t *TestNeoFS) CreateContainer(_ context.Context, prm PrmContainerCreate) (
|
|||
|
||||
var id cid.ID
|
||||
id.SetSHA256(sha256.Sum256(b))
|
||||
t.containers[id.EncodeToString()] = cnr
|
||||
t.containers[id.EncodeToString()] = &cnr
|
||||
|
||||
return &id, nil
|
||||
}
|
||||
|
|
4
go.mod
4
go.mod
|
@ -9,8 +9,8 @@ require (
|
|||
github.com/gorilla/mux v1.8.0
|
||||
github.com/nats-io/nats.go v1.13.1-0.20220121202836-972a071d373d
|
||||
github.com/nspcc-dev/neo-go v0.98.2
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220621170933-dd233c3fbc84
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220628114722-ab4d1e34a8ac
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220630100506-c6f7ab3ef1bf
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220704082116-2ad89085a341
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.7.1
|
||||
|
|
8
go.sum
8
go.sum
|
@ -296,8 +296,8 @@ github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321113211-526c423a6152 h1:JK
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321113211-526c423a6152/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220621170933-dd233c3fbc84 h1:4tZSQ2DL/oatbte35+vDSt2nYpQ0G2et1DrpxodGwRM=
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220621170933-dd233c3fbc84/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU=
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220630100506-c6f7ab3ef1bf h1:QRPx+DdyN2KmJ5/oDYH4c86Bl81d1ZacQL5Q9IC9wZA=
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220630100506-c6f7ab3ef1bf/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU=
|
||||
github.com/nspcc-dev/neofs-contract v0.15.1 h1:1r27t4SGKF7W1PRPOIfircEXHvALThNYNagT+SIabcA=
|
||||
github.com/nspcc-dev/neofs-contract v0.15.1/go.mod h1:kxO5ZTqdzFnRM5RMvM+Fhd+3GGrJo6AmG2ZyA9OCqqQ=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
|
@ -306,8 +306,8 @@ github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnB
|
|||
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40=
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220628114722-ab4d1e34a8ac h1:FRxNic8MeVF7bNWE31H5MLh7EoD/6uNpskwJxfEuiM4=
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220628114722-ab4d1e34a8ac/go.mod h1:EpzpilARa1/7Pgtn8qB/iXXyvC1AIzhlm8mbU+S52MU=
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220704082116-2ad89085a341 h1:poXrrTjCClTMUpEZ7xlQ3Pk4+vtLH+EqaTduBmn+Z9Y=
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220704082116-2ad89085a341/go.mod h1:ck/wjPGFZ7mqcz6vZLMuQFEfL1Qu5zVrBrBJrH0VjOo=
|
||||
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||
|
|
|
@ -112,20 +112,19 @@ func (x *NeoFS) CreateContainer(ctx context.Context, prm layer.PrmContainerCreat
|
|||
prm.BasicACL = acl.PublicRWExtended
|
||||
}
|
||||
|
||||
// fill container structure
|
||||
cnrOptions := []container.Option{
|
||||
container.WithPolicy(&prm.Policy),
|
||||
container.WithOwnerID(&prm.Creator),
|
||||
container.WithCustomBasicACL(prm.BasicACL),
|
||||
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10)),
|
||||
}
|
||||
var cnr container.Container
|
||||
cnr.Init()
|
||||
cnr.SetPlacementPolicy(prm.Policy)
|
||||
cnr.SetOwner(prm.Creator)
|
||||
cnr.SetBasicACL(prm.BasicACL)
|
||||
container.SetCreationTime(&cnr, time.Now())
|
||||
|
||||
if prm.Name != "" {
|
||||
cnrOptions = append(cnrOptions, container.WithAttribute(container.AttributeName, prm.Name))
|
||||
container.SetName(&cnr, prm.Name)
|
||||
}
|
||||
|
||||
for _, attr := range prm.AdditionalAttributes {
|
||||
cnrOptions = append(cnrOptions, container.WithAttribute(attr[0], attr[1]))
|
||||
for i := range prm.AdditionalAttributes {
|
||||
cnr.SetAttribute(prm.AdditionalAttributes[i][0], prm.AdditionalAttributes[i][1])
|
||||
}
|
||||
|
||||
// https://github.com/nspcc-dev/neofs-s3-gw/issues/435
|
||||
|
@ -134,18 +133,18 @@ func (x *NeoFS) CreateContainer(ctx context.Context, prm layer.PrmContainerCreat
|
|||
if hhDisabled, err := isHomomorphicHashDisabled(ctx, x.pool); err != nil {
|
||||
return nil, fmt.Errorf("check homomorphic hash enabled: %w", err)
|
||||
} else if hhDisabled {
|
||||
cnrOptions = append(cnrOptions, container.WithAttribute(
|
||||
"__NEOFS__DISABLE_HOMOMORPHIC_HASHING", "true"))
|
||||
container.DisableHomomorphicHashing(&cnr)
|
||||
}
|
||||
|
||||
cnr := container.New(cnrOptions...)
|
||||
|
||||
if prm.Name != "" {
|
||||
container.SetNativeName(cnr, prm.Name)
|
||||
var d container.Domain
|
||||
d.SetName(prm.Name)
|
||||
|
||||
container.WriteDomain(&cnr, d)
|
||||
}
|
||||
|
||||
var prmPut pool.PrmContainerPut
|
||||
prmPut.SetContainer(*cnr)
|
||||
prmPut.SetContainer(cnr)
|
||||
prmPut.SetWaitParams(x.await)
|
||||
|
||||
if prm.SessionToken != nil {
|
||||
|
|
Loading…
Reference in a new issue