Skip to content

Commit

Permalink
Improve the error message when trying to add multiple expiry options …
Browse files Browse the repository at this point in the history
…in a single rule
  • Loading branch information
marktheunissen committed Jan 22, 2025
1 parent 0019b7b commit 8752478
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/ilm/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
}
}

expiryRulesCount := 0

if ctx.IsSet("size-lt") {
szStr := ctx.String("size-lt")
szLt, err := humanize.ParseBytes(szStr)
Expand Down Expand Up @@ -321,9 +323,11 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
tags = strPtr(ctx.String("tags"))
}
if ctx.IsSet("expiry-date") {
expiryRulesCount++
expiryDate = strPtr(ctx.String("expiry-date"))
}
if ctx.IsSet("expiry-days") {
expiryRulesCount++
expiryDays = strPtr(ctx.String("expiry-days"))
}
if f := "expire-days"; ctx.IsSet(f) {
Expand All @@ -339,6 +343,7 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
expiredObjectDeleteMarker = boolPtr(ctx.Bool("expired-object-delete-marker"))
}
if f := "expire-delete-marker"; ctx.IsSet(f) {
expiryRulesCount++
expiredObjectDeleteMarker = boolPtr(ctx.Bool(f))
}
if ctx.IsSet("noncurrentversion-expiration-days") {
Expand Down Expand Up @@ -374,6 +379,11 @@ func GetLifecycleOptions(ctx *cli.Context) (LifecycleOptions, *probe.Error) {
expiredObjectAllversions = boolPtr(ctx.Bool("expire-all-object-versions"))
}

// Return an error if more than one of these three flags is set.
if expiryRulesCount > 1 {
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"))
}

return LifecycleOptions{
ID: id,
Status: status,
Expand Down

0 comments on commit 8752478

Please sign in to comment.