Skip to content

Commit

Permalink
Merge pull request #39 from unity-sds/lifecycle-health-check-update
Browse files Browse the repository at this point in the history
updated policy to set prefix
  • Loading branch information
jdrodjpl authored Nov 4, 2024
2 parents d1992c4 + f71a8fb commit 1e4128c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions backend/internal/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package aws
import (
"context"
"fmt"
"io"
"math/rand"
"strconv"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
Expand All @@ -11,10 +16,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
appconfig "github.com/unity-sds/unity-management-console/backend/internal/application/config"
"io"
"math/rand"
"time"
"strconv"
)

const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
Expand Down Expand Up @@ -176,9 +177,9 @@ func CreateBucket(s3client S3BucketAPI, conf *appconfig.AppConfig) {
}
}

// Set bucket lifecycle length
log.Printf("Setting lifecycle length on bucket: %s", bucket)
berr = SetBucketLifecycleLength(s3client, conf, bucket, bucketLifecycleInDays)
// Set bucket health_check object lifecycle policy
log.Printf("Setting health_check object lifecycle policy on bucket: %s", bucket)
berr = SetBucketHealthCheckLifecyclePolicy(s3client, conf, bucket, bucketLifecycleInDays)

if berr != nil {
log.Errorf("Error setting lifecycle length on bucket: %v", berr)
Expand Down Expand Up @@ -342,16 +343,19 @@ func EnableBucketVersioning(s3client S3BucketAPI, conf *appconfig.AppConfig, buc
return nil
}

func SetBucketLifecycleLength(s3client S3BucketAPI, conf *appconfig.AppConfig, bucketName string, lifecycleInDays int32) error {
func SetBucketHealthCheckLifecyclePolicy(s3client S3BucketAPI, conf *appconfig.AppConfig, bucketName string, lifecycleInDays int32) error {
if s3client == nil {
s3client = InitS3Client(conf)
}

lifecycleRule := &types.LifecycleRule{
ID: aws.String("delete old health checks"),
Expiration: &types.LifecycleExpiration{
Days: lifecycleInDays,
},
Filter: &types.LifecycleRuleFilterMemberPrefix{},
Filter: &types.LifecycleRuleFilterMemberPrefix{
Value: "health_check",
},
Status: types.ExpirationStatusEnabled,
}

Expand Down

0 comments on commit 1e4128c

Please sign in to comment.