From 2bb48642ee3102e4f87fa1ef842569652b171fbe Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Sun, 21 Feb 2021 12:51:33 +0300 Subject: [PATCH] [#393] cli: Add dedicated flag to indicate object expiration Add `--expires-on` flag to `put` sub-command of `object` command that indicates object's expiration epoch. Set corresponding object attributes if flag value is set. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/object.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index e3d3442a4..4bbdda06d 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -19,6 +19,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/token" + objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/spf13/cobra" ) @@ -108,6 +109,10 @@ const ( rawFlagDesc = "Set raw request option" ) +const putExpiresOnFlag = "expires-on" + +var putExpiredOn uint64 + func init() { rootCmd.AddCommand(objectCmd) objectCmd.PersistentFlags().String("bearer", "", "File with signed JSON or binary encoded bearer token") @@ -121,6 +126,8 @@ func init() { objectPutCmd.Flags().String("attributes", "", "User attributes in form of Key1=Value1,Key2=Value2") objectPutCmd.Flags().Bool("disable-filename", false, "Do not set well-known filename attribute") objectPutCmd.Flags().Bool("disable-timestamp", false, "Do not set well-known timestamp attribute") + objectPutCmd.Flags().Uint64VarP(&putExpiredOn, putExpiresOnFlag, "e", 0, + "Last epoch in the life of the object") objectCmd.AddCommand(objectDelCmd) objectDelCmd.Flags().String("cid", "", "Container ID") @@ -219,6 +226,26 @@ func putObject(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't parse object attributes: %w", err) } + expiresOn, _ := cmd.Flags().GetUint64(putExpiresOnFlag) + if expiresOn > 0 { + var expAttr *object.Attribute + + for _, a := range attrs { + if a.Key() == objectV2.SysAttributeExpEpoch { + expAttr = a + break + } + } + + if expAttr == nil { + expAttr = object.NewAttribute() + expAttr.SetKey(objectV2.SysAttributeExpEpoch) + attrs = append(attrs, expAttr) + } + + expAttr.SetValue(strconv.FormatUint(expiresOn, 10)) + } + obj := object.NewRaw() obj.SetContainerID(cid) obj.SetOwnerID(ownerID)