Skip to content

Commit 2be0ae1

Browse files
Improve the error message when trying to add multiple expiry options in a single rule
1 parent 0019b7b commit 2be0ae1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/ilm/options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
272272
}
273273
}
274274

275+
expiryRulesCount := 0
276+
275277
if ctx.IsSet("size-lt") {
276278
szStr := ctx.String("size-lt")
277279
szLt, err := humanize.ParseBytes(szStr)
@@ -321,9 +323,11 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
321323
tags = strPtr(ctx.String("tags"))
322324
}
323325
if ctx.IsSet("expiry-date") {
326+
expiryRulesCount++
324327
expiryDate = strPtr(ctx.String("expiry-date"))
325328
}
326329
if ctx.IsSet("expiry-days") {
330+
expiryRulesCount++
327331
expiryDays = strPtr(ctx.String("expiry-days"))
328332
}
329333
if f := "expire-days"; ctx.IsSet(f) {
@@ -339,6 +343,7 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
339343
expiredObjectDeleteMarker = boolPtr(ctx.Bool("expired-object-delete-marker"))
340344
}
341345
if f := "expire-delete-marker"; ctx.IsSet(f) {
346+
expiryRulesCount++
342347
expiredObjectDeleteMarker = boolPtr(ctx.Bool(f))
343348
}
344349
if ctx.IsSet("noncurrentversion-expiration-days") {
@@ -374,6 +379,10 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
374379
expiredObjectAllversions = boolPtr(ctx.Bool("expire-all-object-versions"))
375380
}
376381

382+
if expiryRulesCount > 1 {
383+
return LifecycleOptions{}, probe.NewError(errors.New("only one of expiry-date, expiry-days and expire-delete-marker can be used in a single rule. Try adding multiple rules to achieve the desired effect"))
384+
}
385+
377386
return LifecycleOptions{
378387
ID: id,
379388
Status: status,

0 commit comments

Comments
 (0)