[#1402] cli: object <-> SG conversion via SDK

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-07-01 19:48:15 +03:00 committed by fyrchik
parent bc5882fc89
commit cfca88fc5c
2 changed files with 12 additions and 10 deletions

View file

@ -11,7 +11,7 @@ import (
sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
storagegroupAPI "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
"github.com/spf13/cobra"
)
@ -55,13 +55,16 @@ func getSG(cmd *cobra.Command, _ []string) {
prm.SetAddress(addr)
prm.SetPayloadWriter(buf)
_, err := internalclient.GetObject(prm)
res, err := internalclient.GetObject(prm)
common.ExitOnErr(cmd, "rpc error: %w", err)
var sg storagegroupAPI.StorageGroup
rawObj := res.Header()
rawObj.SetPayload(buf.Bytes())
err = sg.Unmarshal(buf.Bytes())
common.ExitOnErr(cmd, "could not unmarshal storage group: %w", err)
var sg storagegroupSDK.StorageGroup
err = storagegroupSDK.ReadFromObject(&sg, *rawObj)
common.ExitOnErr(cmd, "could not read storage group from the obj: %w", err)
cmd.Printf("Expiration epoch: %d\n", sg.ExpirationEpoch())
cmd.Printf("Group size: %d\n", sg.ValidationDataSize())

View file

@ -16,6 +16,7 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/spf13/cobra"
)
@ -77,16 +78,14 @@ func putSG(cmd *cobra.Command, _ []string) {
}, cnr, members)
common.ExitOnErr(cmd, "could not collect storage group members: %w", err)
sgContent, err := sg.Marshal()
common.ExitOnErr(cmd, "could not marshal storage group: %w", err)
obj := object.New()
obj.SetContainerID(cnr)
obj.SetOwnerID(&ownerID)
obj.SetType(object.TypeStorageGroup)
storagegroupSDK.WriteToObject(*sg, obj)
putPrm.SetHeader(obj)
putPrm.SetPayloadReader(bytes.NewReader(sgContent))
putPrm.SetPayloadReader(bytes.NewReader(obj.Payload()))
res, err := internalclient.PutObject(putPrm)
common.ExitOnErr(cmd, "rpc error: %w", err)