diff --git a/pkg/bucket/lifecycle/lifecycle.go b/pkg/bucket/lifecycle/lifecycle.go index 69d548cc2..d71af4864 100644 --- a/pkg/bucket/lifecycle/lifecycle.go +++ b/pkg/bucket/lifecycle/lifecycle.go @@ -66,6 +66,40 @@ type Lifecycle struct { Rules []Rule `xml:"Rule"` } +// UnmarshalXML - decodes XML data. +func (lc *Lifecycle) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { + switch start.Name.Local { + case "LifecycleConfiguration", "BucketLifecycleConfiguration": + default: + return errUnknownXMLTag + } + for { + // Read tokens from the XML document in a stream. + t, err := d.Token() + if err != nil { + if err == io.EOF { + break + } + return err + } + + switch se := t.(type) { + case xml.StartElement: + switch se.Name.Local { + case "Rule": + var r Rule + if err = d.DecodeElement(&r, &se); err != nil { + return err + } + lc.Rules = append(lc.Rules, r) + default: + return errUnknownXMLTag + } + } + } + return nil +} + // HasActiveRules - returns whether policy has active rules for. // Optionally a prefix can be supplied. // If recursive is specified the function will also return true if any level below the diff --git a/pkg/bucket/lifecycle/lifecycle_test.go b/pkg/bucket/lifecycle/lifecycle_test.go index 101336d98..b297c40be 100644 --- a/pkg/bucket/lifecycle/lifecycle_test.go +++ b/pkg/bucket/lifecycle/lifecycle_test.go @@ -336,6 +336,13 @@ func TestComputeActions(t *testing.T) { objectModTime: time.Now().UTC().Add(-24 * time.Hour), // Created 1 day ago expectedAction: DeleteAction, }, + // Should accept BucketLifecycleConfiguration root tag + { + inputConfig: `foodir/Enabled` + time.Now().Truncate(24*time.Hour).UTC().Add(-24*time.Hour).Format(time.RFC3339) + ``, + objectName: "foodir/fooobject", + objectModTime: time.Now().UTC().Add(-24 * time.Hour), // Created 1 day ago + expectedAction: DeleteAction, + }, } for _, tc := range testCases {