mirror of
https://github.com/nyanotech/object-holder.git
synced 2025-12-16 11:30:24 -08:00
skip getting current retention settings if update-within is 0, default that to 0
on b2, putobjectretention is free, so might as well yolo it
This commit is contained in:
parent
19c5d485ae
commit
0bf0144deb
22
main.go
22
main.go
@ -21,7 +21,7 @@ var bucket = flag.String("bucket", "", "bucket name")
|
|||||||
var accessKeyId = flag.String("access-key-id", "", "aws access key")
|
var accessKeyId = flag.String("access-key-id", "", "aws access key")
|
||||||
var secretAccessKey = flag.String("secret-access-key", "", "aws secret key")
|
var secretAccessKey = flag.String("secret-access-key", "", "aws secret key")
|
||||||
|
|
||||||
var updateExpiresWithin = flag.Int("update-expires-within", 30*24*3600, "only update objects whose lock expires within this many seconds (default 30 days)")
|
var updateExpiresWithin = flag.Int("update-expires-within", 0, "only update objects whose lock expires within this many seconds (default 0)")
|
||||||
var lockFor = flag.Int("lock-for", 90*24*3600, "how many seconds to renew the object lock for (default 90 days)")
|
var lockFor = flag.Int("lock-for", 90*24*3600, "how many seconds to renew the object lock for (default 90 days)")
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@ -71,12 +71,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkAndRenewObjectLock(svc *s3.Client, object string) {
|
func checkAndRenewObjectLock(svc *s3.Client, object string) {
|
||||||
retention, _ := svc.GetObjectRetention(context.TODO(), &s3.GetObjectRetentionInput{
|
updateHold := false
|
||||||
Bucket: bucket,
|
if *updateExpiresWithin == 0 {
|
||||||
Key: &object,
|
updateHold = true
|
||||||
})
|
} else {
|
||||||
|
retention, _ := svc.GetObjectRetention(context.TODO(), &s3.GetObjectRetentionInput{
|
||||||
|
Bucket: bucket,
|
||||||
|
Key: &object,
|
||||||
|
})
|
||||||
|
if retention == nil {
|
||||||
|
updateHold = true
|
||||||
|
} else if retention.Retention.RetainUntilDate.Before(time.Now().Add(time.Second * time.Duration(*updateExpiresWithin))) {
|
||||||
|
updateHold = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if retention == nil || retention.Retention.RetainUntilDate.Before(time.Now().Add(time.Second * time.Duration(*updateExpiresWithin))) {
|
if updateHold {
|
||||||
log.Println("Renewing object lock for object", object)
|
log.Println("Renewing object lock for object", object)
|
||||||
_, err := svc.PutObjectRetention(context.TODO(), &s3.PutObjectRetentionInput{
|
_, err := svc.PutObjectRetention(context.TODO(), &s3.PutObjectRetentionInput{
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user