2022-02-16 15:56:16 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
2022-05-18 09:22:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
2022-02-16 15:56:16 +00:00
|
|
|
objectcore "github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// object lock command.
|
|
|
|
var cmdObjectLock = &cobra.Command{
|
|
|
|
Use: "lock CONTAINER OBJECT...",
|
|
|
|
Short: "Lock object in container",
|
|
|
|
Long: "Lock object in container",
|
|
|
|
Args: cobra.MinimumNArgs(2),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
var cnr cid.ID
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
err := cnr.DecodeString(args[0])
|
2022-02-16 15:56:16 +00:00
|
|
|
exitOnErr(cmd, errf("Incorrect container arg: %v", err))
|
|
|
|
|
|
|
|
argsList := args[1:]
|
|
|
|
|
|
|
|
lockList := make([]oid.ID, len(argsList))
|
|
|
|
|
|
|
|
for i := range argsList {
|
2022-05-12 16:37:46 +00:00
|
|
|
err = lockList[i].DecodeString(argsList[i])
|
2022-02-16 15:56:16 +00:00
|
|
|
exitOnErr(cmd, errf(fmt.Sprintf("Incorrect object arg #%d: %%v", i+1), err))
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := getKey()
|
|
|
|
exitOnErr(cmd, errf("can't fetch private key: %w", err))
|
|
|
|
|
|
|
|
idOwner, err := getOwnerID(key)
|
|
|
|
exitOnErr(cmd, err)
|
|
|
|
|
|
|
|
var lock object.Lock
|
|
|
|
lock.WriteMembers(lockList)
|
|
|
|
|
2022-03-05 08:49:19 +00:00
|
|
|
obj := object.New()
|
2022-05-12 16:37:46 +00:00
|
|
|
obj.SetContainerID(cnr)
|
2022-02-16 15:56:16 +00:00
|
|
|
obj.SetOwnerID(idOwner)
|
|
|
|
obj.SetType(object.TypeLock)
|
|
|
|
obj.SetPayload(lock.Marshal())
|
|
|
|
|
|
|
|
var prm internalclient.PutObjectPrm
|
|
|
|
|
|
|
|
prepareSessionPrmWithOwner(cmd, objectcore.AddressOf(obj), key, idOwner, &prm)
|
|
|
|
prepareObjectPrm(cmd, &prm)
|
2022-03-05 08:49:19 +00:00
|
|
|
prm.SetHeader(obj)
|
2022-02-16 15:56:16 +00:00
|
|
|
|
|
|
|
_, err = internalclient.PutObject(prm)
|
|
|
|
exitOnErr(cmd, errf("Store lock object in NeoFS: %w", err))
|
|
|
|
|
|
|
|
cmd.Println("Objects successfully locked.")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initCommandObjectLock() {
|
2022-05-18 09:22:02 +00:00
|
|
|
commonflags.Init(cmdObjectLock)
|
2022-02-16 15:56:16 +00:00
|
|
|
}
|