Skip to content

Commit

Permalink
Add MaxNoncurrentVersions to NoncurrentVersionExpiration (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisis committed Nov 8, 2021
1 parent 2be244f commit a7a36ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/lifecycle/lifecycle.go
Expand Up @@ -53,13 +53,14 @@ func (n AbortIncompleteMultipartUpload) MarshalXML(e *xml.Encoder, start xml.Sta
// (or suspended) to request server delete noncurrent object versions at a
// specific period in the object's lifetime.
type NoncurrentVersionExpiration struct {
XMLName xml.Name `xml:"NoncurrentVersionExpiration" json:"-"`
NoncurrentDays ExpirationDays `xml:"NoncurrentDays,omitempty"`
XMLName xml.Name `xml:"NoncurrentVersionExpiration" json:"-"`
NoncurrentDays ExpirationDays `xml:"NoncurrentDays,omitempty"`
MaxNoncurrentVersions int `xml:"MaxNoncurrentVersions,omitempty"`
}

// MarshalXML if non-current days not set to non zero value
func (n NoncurrentVersionExpiration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if n.IsDaysNull() {
if n.isNull() {
return nil
}
type noncurrentVersionExpirationWrapper NoncurrentVersionExpiration
Expand All @@ -71,6 +72,10 @@ func (n NoncurrentVersionExpiration) IsDaysNull() bool {
return n.NoncurrentDays == ExpirationDays(0)
}

func (n NoncurrentVersionExpiration) isNull() bool {
return n.IsDaysNull() && n.MaxNoncurrentVersions == 0
}

// NoncurrentVersionTransition structure, set this action to request server to
// transition noncurrent object versions to different set storage classes
// at a specific period in the object's lifetime.
Expand Down Expand Up @@ -405,7 +410,7 @@ func (r Rule) MarshalJSON() ([]byte, error) {
if !r.Transition.IsNull() {
newr.Transition = &r.Transition
}
if !r.NoncurrentVersionExpiration.IsDaysNull() {
if !r.NoncurrentVersionExpiration.isNull() {
newr.NoncurrentVersionExpiration = &r.NoncurrentVersionExpiration
}
if !r.NoncurrentVersionTransition.isNull() {
Expand Down
7 changes: 7 additions & 0 deletions pkg/lifecycle/lifecycle_test.go
Expand Up @@ -247,6 +247,13 @@ func TestLifecycleXMLRoundtrip(t *testing.T) {
StorageClass: "S3TIER-1",
},
},
{
ID: "max-noncurrent-versions",
Status: "Enabled",
NoncurrentVersionExpiration: NoncurrentVersionExpiration{
MaxNoncurrentVersions: 5,
},
},
},
}

Expand Down

0 comments on commit a7a36ee

Please sign in to comment.