2022-06-02 12:07:30 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
|
|
|
objectCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/object"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-07-01 16:48:15 +00:00
|
|
|
storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
2022-06-02 12:07:30 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sgID string
|
|
|
|
|
|
|
|
var sgGetCmd = &cobra.Command{
|
|
|
|
Use: "get",
|
|
|
|
Short: "Get storage group from NeoFS",
|
|
|
|
Long: "Get storage group from NeoFS",
|
|
|
|
Run: getSG,
|
|
|
|
}
|
|
|
|
|
|
|
|
func initSGGetCmd() {
|
|
|
|
commonflags.Init(sgGetCmd)
|
|
|
|
|
|
|
|
flags := sgGetCmd.Flags()
|
|
|
|
|
2022-06-20 16:33:34 +00:00
|
|
|
flags.String(cidFlag, "", "Container ID")
|
|
|
|
_ = sgGetCmd.MarkFlagRequired(cidFlag)
|
2022-06-02 12:07:30 +00:00
|
|
|
|
2022-10-11 14:02:03 +00:00
|
|
|
flags.StringVarP(&sgID, sgIDFlag, "", "", "Storage group identifier")
|
2022-06-02 12:07:30 +00:00
|
|
|
_ = sgGetCmd.MarkFlagRequired(sgIDFlag)
|
|
|
|
|
|
|
|
flags.Bool(sgRawFlag, false, "Set raw request option")
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSG(cmd *cobra.Command, _ []string) {
|
|
|
|
var cnr cid.ID
|
|
|
|
var obj oid.ID
|
|
|
|
|
|
|
|
addr := readObjectAddress(cmd, &cnr, &obj)
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
|
2022-10-20 09:40:33 +00:00
|
|
|
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
|
|
|
|
2022-06-02 12:07:30 +00:00
|
|
|
var prm internalclient.GetObjectPrm
|
|
|
|
objectCli.Prepare(cmd, &prm)
|
2022-10-20 09:40:33 +00:00
|
|
|
prm.SetClient(cli)
|
2022-06-02 12:07:30 +00:00
|
|
|
|
|
|
|
raw, _ := cmd.Flags().GetBool(sgRawFlag)
|
|
|
|
prm.SetRawFlag(raw)
|
|
|
|
prm.SetAddress(addr)
|
|
|
|
prm.SetPayloadWriter(buf)
|
|
|
|
|
2022-07-01 16:48:15 +00:00
|
|
|
res, err := internalclient.GetObject(prm)
|
2022-06-02 12:07:30 +00:00
|
|
|
common.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
|
2022-07-01 16:48:15 +00:00
|
|
|
rawObj := res.Header()
|
|
|
|
rawObj.SetPayload(buf.Bytes())
|
2022-06-02 12:07:30 +00:00
|
|
|
|
2022-07-01 16:48:15 +00:00
|
|
|
var sg storagegroupSDK.StorageGroup
|
|
|
|
|
|
|
|
err = storagegroupSDK.ReadFromObject(&sg, *rawObj)
|
|
|
|
common.ExitOnErr(cmd, "could not read storage group from the obj: %w", err)
|
2022-06-02 12:07:30 +00:00
|
|
|
|
|
|
|
cmd.Printf("Expiration epoch: %d\n", sg.ExpirationEpoch())
|
|
|
|
cmd.Printf("Group size: %d\n", sg.ValidationDataSize())
|
|
|
|
common.PrintChecksum(cmd, "Group hash", sg.ValidationDataHash)
|
|
|
|
|
|
|
|
if members := sg.Members(); len(members) > 0 {
|
|
|
|
cmd.Println("Members:")
|
|
|
|
|
|
|
|
for i := range members {
|
|
|
|
cmd.Printf("\t%s\n", members[i].String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|