forked from TrueCloudLab/frostfs-node
[#1461] cli: Require LOCK object to be expired
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
595fc60d72
commit
de31bb27b6
1 changed files with 28 additions and 4 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue