[#1402] cli: Support storage group expiration

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-06-20 19:56:41 +03:00 committed by fyrchik
parent cfca88fc5c
commit 12d41918e6
2 changed files with 20 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/ecdsa"
"errors"
"strconv"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
@ -42,6 +43,9 @@ func initSGPutCmd() {
flags.StringSliceVarP(&sgMembers, sgMembersFlag, "m", nil, "ID list of storage group members")
_ = sgPutCmd.MarkFlagRequired(sgMembersFlag)
flags.Uint64(sgLifetimeFlag, 0, "Storage group lifetime in epochs")
_ = sgPutCmd.MarkFlagRequired(sgLifetimeFlag)
}
func putSG(cmd *cobra.Command, _ []string) {
@ -53,6 +57,10 @@ func putSG(cmd *cobra.Command, _ []string) {
var cnr cid.ID
readCID(cmd, &cnr)
lifetimeStr := cmd.Flag(sgLifetimeFlag).Value.String()
lifetime, err := strconv.ParseUint(lifetimeStr, 10, 64)
common.ExitOnErr(cmd, "could not parse lifetime: %w", err)
members := make([]oidSDK.ID, len(sgMembers))
for i := range sgMembers {
@ -78,6 +86,16 @@ func putSG(cmd *cobra.Command, _ []string) {
}, cnr, members)
common.ExitOnErr(cmd, "could not collect storage group members: %w", err)
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
var netInfoPrm internalclient.NetworkInfoPrm
netInfoPrm.SetClient(cli)
ni, err := internalclient.NetworkInfo(netInfoPrm)
common.ExitOnErr(cmd, "can't fetch network info: %w", err)
sg.SetExpirationEpoch(ni.NetworkInfo().CurrentEpoch() + lifetime)
obj := object.New()
obj.SetContainerID(cnr)
obj.SetOwnerID(&ownerID)

View file

@ -25,6 +25,8 @@ const (
cidFlag = "cid"
)
const sgLifetimeFlag = "lifetime"
func init() {
storageGroupChildCommands := []*cobra.Command{
sgPutCmd,