Skip to content

Commit

Permalink
Add support for NewerNoncurrentVersions (#1596)
Browse files Browse the repository at this point in the history
NewerNoncurrentVersions replaces MaxNoncurrentVersions (breaking change)
  • Loading branch information
krisis authored Dec 7, 2021
1 parent 0917518 commit e924c33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
17 changes: 9 additions & 8 deletions pkg/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ 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"`
MaxNoncurrentVersions int `xml:"MaxNoncurrentVersions,omitempty"`
XMLName xml.Name `xml:"NoncurrentVersionExpiration" json:"-"`
NoncurrentDays ExpirationDays `xml:"NoncurrentDays,omitempty"`
NewerNoncurrentVersions int `xml:"NewerNoncurrentVersions,omitempty"`
}

// MarshalXML if non-current days not set to non zero value
// MarshalXML if n is non-empty, i.e has a non-zero NoncurrentDays or NewerNoncurrentVersions.
func (n NoncurrentVersionExpiration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if n.isNull() {
return nil
Expand All @@ -73,16 +73,17 @@ func (n NoncurrentVersionExpiration) IsDaysNull() bool {
}

func (n NoncurrentVersionExpiration) isNull() bool {
return n.IsDaysNull() && n.MaxNoncurrentVersions == 0
return n.IsDaysNull() && n.NewerNoncurrentVersions == 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.
type NoncurrentVersionTransition struct {
XMLName xml.Name `xml:"NoncurrentVersionTransition,omitempty" json:"-"`
StorageClass string `xml:"StorageClass,omitempty" json:"StorageClass,omitempty"`
NoncurrentDays ExpirationDays `xml:"NoncurrentDays" json:"NoncurrentDays"`
XMLName xml.Name `xml:"NoncurrentVersionTransition,omitempty" json:"-"`
StorageClass string `xml:"StorageClass,omitempty" json:"StorageClass,omitempty"`
NoncurrentDays ExpirationDays `xml:"NoncurrentDays" json:"NoncurrentDays"`
NewerNoncurrentVersions int `xml:"NewerNoncurrentVersions,omitempty" json:"NewerNoncurrentVersions,omitempty"`
}

// IsDaysNull returns true if days field is null
Expand Down
21 changes: 17 additions & 4 deletions pkg/lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestLifecycleUnmarshalJSON(t *testing.T) {
"ID": "noncurrent-transition-missing",
"Status": "Enabled",
"NoncurrentVersionTransition": {
"Days": 0
"NoncurrentDays": 0
}
}
]
Expand All @@ -78,7 +78,7 @@ func TestLifecycleUnmarshalJSON(t *testing.T) {
"ID": "noncurrent-transition-missing-1",
"Status": "Enabled",
"NoncurrentVersionTransition": {
"Days": 1
"NoncurrentDays": 1
}
}
]
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestLifecycleUnmarshalJSON(t *testing.T) {
"Status": "Enabled",
"NoncurrentVersionTransition": {
"StorageClass": "S3TIER-1",
"Days": 1
"NoncurrentDays": 1
}
}
]
Expand Down Expand Up @@ -187,6 +187,19 @@ func TestLifecycleJSONRoundtrip(t *testing.T) {
ID: "rule-4",
Status: "Enabled",
},
{
NoncurrentVersionExpiration: NoncurrentVersionExpiration{
NoncurrentDays: ExpirationDays(3),
NewerNoncurrentVersions: 1,
},
NoncurrentVersionTransition: NoncurrentVersionTransition{
NoncurrentDays: ExpirationDays(3),
NewerNoncurrentVersions: 1,
StorageClass: "MINIOTIER-2",
},
ID: "rule-5",
Status: "Enabled",
},
},
}

Expand Down Expand Up @@ -251,7 +264,7 @@ func TestLifecycleXMLRoundtrip(t *testing.T) {
ID: "max-noncurrent-versions",
Status: "Enabled",
NoncurrentVersionExpiration: NoncurrentVersionExpiration{
MaxNoncurrentVersions: 5,
NewerNoncurrentVersions: 5,
},
},
},
Expand Down

0 comments on commit e924c33

Please sign in to comment.