[#1461] cli: Require LOCK object to be expired

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-05-31 19:59:07 +03:00 committed by fyrchik
parent 595fc60d72
commit de31bb27b6

View file

@ -2,19 +2,23 @@ package object
import ( import (
"fmt" "fmt"
"strconv"
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client" 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/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session" sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/user" "github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const lockExpiresOnFlag = "expires-on"
// object lock command. // object lock command.
var objectLockCmd = &cobra.Command{ var objectLockCmd = &cobra.Command{
Use: "lock CONTAINER OBJECT...", Use: "lock CONTAINER OBJECT...",
@ -41,13 +45,30 @@ var objectLockCmd = &cobra.Command{
var idOwner user.ID var idOwner user.ID
user.IDFromKey(&idOwner, key.PublicKey) user.IDFromKey(&idOwner, key.PublicKey)
var lock object.Lock var lock objectSDK.Lock
lock.WriteMembers(lockList) lock.WriteMembers(lockList)
obj := object.New() exp, relative, err := common.ParseEpoch(cmd, lockExpiresOnFlag)
common.ExitOnErr(cmd, "Parsing expiration epoch: %w", err)
if relative {
endpoint, _ := cmd.Flags().GetString(commonflags.RPC)
currEpoch, err := internalclient.GetCurrentEpoch(endpoint)
common.ExitOnErr(cmd, "Request current epoch: %w", err)
exp += currEpoch
}
var expirationAttr objectSDK.Attribute
expirationAttr.SetKey(objectV2.SysAttributeExpEpoch)
expirationAttr.SetValue(strconv.FormatUint(exp, 10))
obj := objectSDK.New()
obj.SetContainerID(cnr) obj.SetContainerID(cnr)
obj.SetOwnerID(&idOwner) obj.SetOwnerID(&idOwner)
obj.SetType(object.TypeLock) obj.SetType(objectSDK.TypeLock)
obj.SetAttributes(expirationAttr)
obj.SetPayload(lock.Marshal()) obj.SetPayload(lock.Marshal())
var prm internalclient.PutObjectPrm var prm internalclient.PutObjectPrm
@ -66,4 +87,7 @@ var objectLockCmd = &cobra.Command{
func initCommandObjectLock() { func initCommandObjectLock() {
commonflags.Init(objectLockCmd) commonflags.Init(objectLockCmd)
commonflags.InitSession(objectLockCmd) commonflags.InitSession(objectLockCmd)
objectLockCmd.Flags().StringP(lockExpiresOnFlag, "e", "", "Lock expiration epoch")
_ = objectLockCmd.MarkFlagRequired(lockExpiresOnFlag)
} }