mirror of
https://github.com/nyanotech/object-holder.git
synced 2025-12-16 11:30:24 -08:00
plumb these through using a struct
This commit is contained in:
parent
3a46e8982d
commit
dc1ec748df
31
main.go
31
main.go
@ -28,11 +28,20 @@ var lockFor = flag.Int("lock-for", 90*24*3600, "how many seconds to renew the ob
|
|||||||
|
|
||||||
var threadCount = flag.Int("threads", 1024, "how many objects to operate on at a time")
|
var threadCount = flag.Int("threads", 1024, "how many objects to operate on at a time")
|
||||||
|
|
||||||
|
type objectLockOptions struct {
|
||||||
|
CheckExistingHold bool
|
||||||
|
UpdateExpiry time.Time
|
||||||
|
LockExpiry time.Time
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
updateExpiry := time.Now().Add(time.Second * time.Duration(*updateExpiresWithin))
|
objectLockArguments := objectLockOptions{
|
||||||
lockExpiry := time.Now().Add(time.Second * time.Duration(*lockFor))
|
CheckExistingHold: *updateExpiresWithin != 0,
|
||||||
|
UpdateExpiry: time.Now().Add(time.Second * time.Duration(*updateExpiresWithin)),
|
||||||
|
LockExpiry: time.Now().Add(time.Second * time.Duration(*lockFor)),
|
||||||
|
}
|
||||||
|
|
||||||
options := []func(*config.LoadOptions) error{}
|
options := []func(*config.LoadOptions) error{}
|
||||||
|
|
||||||
@ -73,7 +82,7 @@ func main() {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
queueWorker(svc, updateExpiry, lockExpiry, objectQueue)
|
queueWorker(svc, objectLockArguments, objectQueue)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,26 +101,24 @@ func main() {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func queueWorker(svc *s3.Client, updateExpiry, lockExpiry time.Time, inQueue chan string) {
|
func queueWorker(svc *s3.Client, options objectLockOptions, inQueue chan string) {
|
||||||
for {
|
for {
|
||||||
object, more := <-inQueue
|
object, more := <-inQueue
|
||||||
if !more {
|
if !more {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
checkAndRenewObjectLock(svc, updateExpiry, lockExpiry, object)
|
checkAndRenewObjectLock(svc, options, object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkAndRenewObjectLock(svc *s3.Client, updateExpiry, lockExpiry time.Time, object string) {
|
func checkAndRenewObjectLock(svc *s3.Client, options objectLockOptions, object string) {
|
||||||
updateHold := false
|
updateHold := !options.CheckExistingHold
|
||||||
if *updateExpiresWithin == 0 {
|
if !updateHold {
|
||||||
updateHold = true
|
|
||||||
} else {
|
|
||||||
retention, _ := svc.GetObjectRetention(context.TODO(), &s3.GetObjectRetentionInput{
|
retention, _ := svc.GetObjectRetention(context.TODO(), &s3.GetObjectRetentionInput{
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Key: &object,
|
Key: &object,
|
||||||
})
|
})
|
||||||
if retention == nil || retention.Retention.RetainUntilDate.Before(updateExpiry) {
|
if retention == nil || retention.Retention.RetainUntilDate.Before(options.UpdateExpiry) {
|
||||||
updateHold = true
|
updateHold = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +131,7 @@ func checkAndRenewObjectLock(svc *s3.Client, updateExpiry, lockExpiry time.Time,
|
|||||||
Retention: &types.ObjectLockRetention{
|
Retention: &types.ObjectLockRetention{
|
||||||
// TODO: add flag for governance mode
|
// TODO: add flag for governance mode
|
||||||
Mode: "COMPLIANCE",
|
Mode: "COMPLIANCE",
|
||||||
RetainUntilDate: aws.Time(lockExpiry),
|
RetainUntilDate: aws.Time(options.LockExpiry),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user