pkg/lifecycle: Add SetPredictionHeaders method (#12755)

This method is used to add expected expiration and transition time 
for an object in GET/HEAD Object response headers.

Also fixed bugs in lifecycle.PredictTransitionTime and
getLifecycleTransitionTier in handling current and 
non-current versions.
This commit is contained in:
Krishnan Parthasarathi
2021-07-20 17:36:55 -07:00
committed by GitHub
parent 6ea083d197
commit d0963974a5
8 changed files with 204 additions and 59 deletions

View File

@@ -163,3 +163,20 @@ func (t Transition) IsDateNull() bool {
func (t Transition) IsNull() bool {
return t.IsDaysNull() && t.IsDateNull()
}
// NextDue returns upcoming transition date for obj and true if applicable,
// returns false otherwise.
func (t Transition) NextDue(obj ObjectOpts) (time.Time, bool) {
if !obj.IsLatest {
return time.Time{}, false
}
switch {
case !t.IsDateNull():
return t.Date.Time, true
case !t.IsDaysNull():
return ExpectedExpiryTime(obj.ModTime, int(t.Days)), true
}
return time.Time{}, false
}