From cfca88fc5cfbf943c6d41df3cd1a591fc80c5add Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 1 Jul 2022 19:48:15 +0300 Subject: [PATCH] [#1402] cli: object <-> SG conversion via SDK Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/storagegroup/get.go | 13 ++++++++----- cmd/neofs-cli/modules/storagegroup/put.go | 9 ++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/neofs-cli/modules/storagegroup/get.go b/cmd/neofs-cli/modules/storagegroup/get.go index 6f6509bf..ab63ab1b 100644 --- a/cmd/neofs-cli/modules/storagegroup/get.go +++ b/cmd/neofs-cli/modules/storagegroup/get.go @@ -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()) diff --git a/cmd/neofs-cli/modules/storagegroup/put.go b/cmd/neofs-cli/modules/storagegroup/put.go index d7039888..f5d7244c 100644 --- a/cmd/neofs-cli/modules/storagegroup/put.go +++ b/cmd/neofs-cli/modules/storagegroup/put.go @@ -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)