diff --git a/cmd/ilm-export.go b/cmd/ilm-export.go index 84a9af18..b881f70d 100644 --- a/cmd/ilm-export.go +++ b/cmd/ilm-export.go @@ -17,6 +17,8 @@ package cmd import ( + "errors" + "github.com/minio/cli" "github.com/minio/mc/cmd/ilm" json "github.com/minio/mc/pkg/colorjson" @@ -86,6 +88,10 @@ func mainILMExport(ctx *cli.Context) error { ilmCfg, err := client.GetLifecycle() fatalIf(err.Trace(args...), "Unable to get lifecycle configuration") + if len(ilmCfg.Rules) == 0 { + fatalIf(probe.NewError(errors.New("lifecycle configuration not set")).Trace(urlStr), + "Unable to export lifecycle configuration") + } printMsg(ilmExportMessage{ Status: "success", diff --git a/cmd/ilm-import.go b/cmd/ilm-import.go index e178ba4b..bdbd993f 100644 --- a/cmd/ilm-import.go +++ b/cmd/ilm-import.go @@ -39,7 +39,7 @@ USAGE: {{.HelpName}} TARGET DESCRIPTION: - Import entire lifecyle configuration from STDIN, input file is expected to be in JSON format. + Import entire lifecycle configuration from STDIN, input file is expected to be in JSON format. EXAMPLES: 1. Set lifecycle configuration for the testbucket on alias 'myminio' to the rules imported from lifecycle.json diff --git a/cmd/ilm-list.go b/cmd/ilm-list.go index 5245111b..18ed6318 100644 --- a/cmd/ilm-list.go +++ b/cmd/ilm-list.go @@ -267,8 +267,8 @@ func mainILMList(ctx *cli.Context) error { fatalIf(err.Trace(args...), "Unable to get lifecycle") if len(ilmCfg.Rules) == 0 { - fatalIf(probe.NewError(errors.New("lifecyle configuration not set")).Trace(urlStr), - "Unable to list lifecyle configuration") + fatalIf(probe.NewError(errors.New("lifecycle configuration not set")).Trace(urlStr), + "Unable to list lifecycle configuration") } printMsg(ilmListMessage{ diff --git a/cmd/ilm-remove.go b/cmd/ilm-remove.go index d97454a2..aad33c56 100644 --- a/cmd/ilm-remove.go +++ b/cmd/ilm-remove.go @@ -100,7 +100,7 @@ func checkILMRemoveSyntax(ctx *cli.Context) { forceChk := (ilmAll && ilmForce) || (!ilmAll && !ilmForce) if !forceChk { fatalIf(errInvalidArgument(), - "It is mandatory to specify --all and --force flag together for mc"+ctx.Command.FullName()+".") + "It is mandatory to specify --all and --force flag together for mc "+ctx.Command.FullName()+".") } if ilmAll && ilmForce { return diff --git a/cmd/ilm/datatypes.go b/cmd/ilm/datatypes.go index b606731f..f77023c7 100644 --- a/cmd/ilm/datatypes.go +++ b/cmd/ilm/datatypes.go @@ -42,7 +42,7 @@ type LifecycleTag struct { Value string `xml:"Value,omitempty" json:"Value,omitempty"` } -// LifecycleTransition structure - transition details of lifeycle configuration +// LifecycleTransition structure - transition details of lifecycle configuration type LifecycleTransition struct { XMLName xml.Name `xml:"Transition" json:"-"` TransitionDate *time.Time `xml:"Date,omitempty" json:"Date,omitempty"` @@ -70,7 +70,7 @@ type LifecycleRuleFilter struct { Tag *LifecycleTag `xml:"Tag,omitempty" json:"-"` } -// LifecycleExpiration structure - expiration details of lifeycle configuration +// LifecycleExpiration structure - expiration details of lifecycle configuration type LifecycleExpiration struct { XMLName xml.Name `xml:"Expiration,omitempty" json:"-"` ExpirationDate *time.Time `xml:"Date,omitempty" json:"Date,omitempty"` diff --git a/cmd/ilm/options.go b/cmd/ilm/options.go index dec6e22b..27286c66 100644 --- a/cmd/ilm/options.go +++ b/cmd/ilm/options.go @@ -74,6 +74,9 @@ func getRightAligned(label string, maxLen int) string { // RemoveILMRule - Remove the ILM rule (with ilmID) from the configuration in XML that is provided. func RemoveILMRule(lfcCfg LifecycleConfiguration, ilmID string) (LifecycleConfiguration, *probe.Error) { + if len(lfcCfg.Rules) == 0 { + return lfcCfg, probe.NewError(fmt.Errorf("lifecycle configuration not set")) + } n := 0 for _, rule := range lfcCfg.Rules { if rule.ID != ilmID { @@ -81,12 +84,12 @@ func RemoveILMRule(lfcCfg LifecycleConfiguration, ilmID string) (LifecycleConfig n++ } } - lfcCfg.Rules = lfcCfg.Rules[:n] if n == len(lfcCfg.Rules) && len(lfcCfg.Rules) > 0 { // if there was no filtering then rules will be of same length, means we didn't find // our ilm id return an error here. return lfcCfg, probe.NewError(fmt.Errorf("lifecycle rule for id '%s' not found", ilmID)) } + lfcCfg.Rules = lfcCfg.Rules[:n] return lfcCfg, nil } @@ -181,7 +184,7 @@ func getLifecycleOptions(ctx *cli.Context) lifecycleOptions { } } -// ApplyNewILMConfig apply new lifecyle rules to existing lifecycle configuration, this +// ApplyNewILMConfig apply new lifecycle rules to existing lifecycle configuration, this // function returns modified/overwritten rules if any. func ApplyNewILMConfig(ctx *cli.Context, lfcCfg LifecycleConfiguration) (LifecycleConfiguration, *probe.Error) { opts := getLifecycleOptions(ctx) diff --git a/cmd/ilm/parse.go b/cmd/ilm/parse.go index 8d674035..1fce092d 100644 --- a/cmd/ilm/parse.go +++ b/cmd/ilm/parse.go @@ -75,7 +75,7 @@ func validateTranDays(rule LifecycleRule) error { transitionSet := (rule.Transition != nil) transitionDaySet := transitionSet && (rule.Transition.TransitionInDays > 0) if transitionDaySet && rule.Transition.TransitionInDays < 30 && strings.ToLower(rule.Transition.StorageClass) == "standard_ia" { - return errors.New("Transition Date/Days are less than or equal to 30 and Storage class is STANDARD_IA") + return errors.New("Transition Date/Days are less than or equal to 30 when Storage class is STANDARD_IA") } return nil } @@ -148,6 +148,7 @@ func parseTransition(storageClass, transitionDateStr, transitionDayStr string) ( } else { return LifecycleTransition{}, probe.NewError(errors.New("if storage class is set a valid transitionDate or transitionDay must be set")) } + transition.StorageClass = storageClass } return transition, nil