[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
cb9e6ea6fa
commit
2bb48642ee
1 changed files with 27 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue