Files
seaweedfs/weed/s3api/s3_objectlock/object_lock_state.go
T
Chris LuandClaude Opus 5.5 a00dbff13b sftp: apply the bucket's default Object Lock retention to uploads (#13017)
* s3_objectlock: read a bucket's default retention from its entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sftp: give uploads into an Object Lock bucket its default retention

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sftp: match uploads against the cleaned buckets folder

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:25:48 -08:00

40 lines
1.5 KiB
Go

package s3_objectlock
import (
"strconv"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
)
// ObjectLockState is an ExpectedExtended condition that makes the filer refuse
// a change if the entry's Object Lock state changed after it was checked.
func ObjectLockState(entry *filer_pb.Entry) map[string][]byte {
state := make(map[string][]byte, 3)
for _, key := range []string{s3_constants.ExtLegalHoldKey, s3_constants.ExtObjectLockModeKey, s3_constants.ExtRetentionUntilDateKey} {
state[key] = entry.Extended[key]
}
return state
}
// DefaultRetention returns the retention that a bucket's Object Lock
// configuration gives a new object.
func DefaultRetention(bucket *filer_pb.Entry, now time.Time) (mode string, retainUntil time.Time, ok bool) {
if bucket == nil {
return "", time.Time{}, false
}
enabled := string(bucket.Extended[s3_constants.ExtObjectLockEnabledKey])
mode = string(bucket.Extended[s3_constants.ExtObjectLockDefaultModeKey])
if enabled != s3_constants.ObjectLockEnabled && enabled != "true" || mode == "" {
return "", time.Time{}, false
}
if days, _ := strconv.Atoi(string(bucket.Extended[s3_constants.ExtObjectLockDefaultDaysKey])); days > 0 {
return mode, now.AddDate(0, 0, days), true
}
if years, _ := strconv.Atoi(string(bucket.Extended[s3_constants.ExtObjectLockDefaultYearsKey])); years > 0 {
return mode, now.AddDate(years, 0, 0), true
}
return "", time.Time{}, false
}