From 12d41918e642bbc56ddf50a0bf90a593085fc3d7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 20 Jun 2022 19:56:41 +0300 Subject: [PATCH] [#1402] cli: Support storage group expiration Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/storagegroup/put.go | 18 ++++++++++++++++++ cmd/neofs-cli/modules/storagegroup/root.go | 2 ++ 2 files changed, 20 insertions(+) diff --git a/cmd/neofs-cli/modules/storagegroup/put.go b/cmd/neofs-cli/modules/storagegroup/put.go index f5d7244ca..4dce711f5 100644 --- a/cmd/neofs-cli/modules/storagegroup/put.go +++ b/cmd/neofs-cli/modules/storagegroup/put.go @@ -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) diff --git a/cmd/neofs-cli/modules/storagegroup/root.go b/cmd/neofs-cli/modules/storagegroup/root.go index 534bbffe0..5b5d58654 100644 --- a/cmd/neofs-cli/modules/storagegroup/root.go +++ b/cmd/neofs-cli/modules/storagegroup/root.go @@ -25,6 +25,8 @@ const ( cidFlag = "cid" ) +const sgLifetimeFlag = "lifetime" + func init() { storageGroupChildCommands := []*cobra.Command{ sgPutCmd,