forked from TrueCloudLab/frostfs-node
[#279] container: Use new methods to work with container format
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
9680dfbdea
commit
e53bf574b5
6 changed files with 16 additions and 18 deletions
|
@ -138,7 +138,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
|
||||||
cnr.SetPlacementPolicy(placementPolicy)
|
cnr.SetPlacementPolicy(placementPolicy)
|
||||||
cnr.SetBasicACL(basicACL)
|
cnr.SetBasicACL(basicACL)
|
||||||
cnr.SetAttributes(attributes)
|
cnr.SetAttributes(attributes)
|
||||||
cnr.SetNonce(nonce[:])
|
cnr.SetNonceUUID(nonce)
|
||||||
|
|
||||||
id, err := cli.PutContainer(ctx, cnr, client.WithTTL(getTTL()))
|
id, err := cli.PutContainer(ctx, cnr, client.WithTTL(getTTL()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -674,9 +674,11 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) {
|
||||||
fmt.Printf("attribute: %s=%s\n", attribute.Key(), attribute.Value())
|
fmt.Printf("attribute: %s=%s\n", attribute.Key(), attribute.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
nonce, err := uuid.FromBytes(cnr.Nonce())
|
nonce, err := cnr.NonceUUID()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Println("nonce:", nonce)
|
fmt.Println("nonce:", nonce)
|
||||||
|
} else {
|
||||||
|
fmt.Println("invalid nonce:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("placement policy:")
|
fmt.Println("placement policy:")
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -17,7 +17,7 @@ require (
|
||||||
github.com/multiformats/go-multihash v0.0.13 // indirect
|
github.com/multiformats/go-multihash v0.0.13 // indirect
|
||||||
github.com/nspcc-dev/hrw v1.0.9
|
github.com/nspcc-dev/hrw v1.0.9
|
||||||
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b
|
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b
|
||||||
github.com/nspcc-dev/neofs-api-go v1.21.1
|
github.com/nspcc-dev/neofs-api-go v1.21.2-0.20201224095453-c4f7be19ea14
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||||
github.com/nspcc-dev/tzhash v1.4.0
|
github.com/nspcc-dev/tzhash v1.4.0
|
||||||
github.com/panjf2000/ants/v2 v2.3.0
|
github.com/panjf2000/ants/v2 v2.3.0
|
||||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
|
@ -1,7 +1,6 @@
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
|
@ -27,7 +26,7 @@ func CheckFormat(c *container.Container) error {
|
||||||
return errors.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln)
|
return errors.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := uuid.FromBytes(c.Nonce()); err != nil {
|
if _, err := c.NonceUUID(); err != nil {
|
||||||
return errors.Wrap(err, "incorrect nonce")
|
return errors.Wrap(err, "incorrect nonce")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,16 +31,14 @@ func TestCheckFormat(t *testing.T) {
|
||||||
|
|
||||||
c.SetOwnerID(owner.NewIDFromNeo3Wallet(wallet))
|
c.SetOwnerID(owner.NewIDFromNeo3Wallet(wallet))
|
||||||
|
|
||||||
c.SetNonce(nil)
|
// set incorrect nonce
|
||||||
|
cV2 := c.ToV2()
|
||||||
|
cV2.SetNonce([]byte{1, 2, 3})
|
||||||
|
c = container.NewContainerFromV2(cV2)
|
||||||
|
|
||||||
require.Error(t, CheckFormat(c))
|
require.Error(t, CheckFormat(c))
|
||||||
|
|
||||||
uid, err := uuid.NewRandom()
|
c.SetNonceUUID(uuid.New())
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
nonce, _ := uid.MarshalBinary()
|
|
||||||
|
|
||||||
c.SetNonce(nonce)
|
|
||||||
|
|
||||||
require.NoError(t, CheckFormat(c))
|
require.NoError(t, CheckFormat(c))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
||||||
containerMorph "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
containerMorph "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
||||||
|
@ -32,13 +31,13 @@ func NewExecutor(client *containerMorph.Client) containerSvc.ServiceExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) {
|
func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) {
|
||||||
cnr := containerSDK.NewContainerFromV2(body.GetContainer())
|
cnr, err := containerSDK.NewVerifiedFromV2(body.GetContainer())
|
||||||
sig := body.GetSignature()
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "invalid format of the container structure")
|
||||||
if err := containerCore.CheckFormat(cnr); err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "incorrect container format")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sig := body.GetSignature()
|
||||||
|
|
||||||
cid, err := s.wrapper.Put(cnr, sig.GetKey(), sig.GetSign())
|
cid, err := s.wrapper.Put(cnr, sig.GetKey(), sig.GetSign())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue