From f4eeb8d322f4adf6cda546fd6dafa454f67d9931 Mon Sep 17 00:00:00 2001 From: Galen Hollins <47542238+galenatjpl@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:49:52 -0700 Subject: [PATCH 1/2] updated policy to set prefix --- backend/internal/aws/s3.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/internal/aws/s3.go b/backend/internal/aws/s3.go index b034960..ebba8fa 100644 --- a/backend/internal/aws/s3.go +++ b/backend/internal/aws/s3.go @@ -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" @@ -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" @@ -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) @@ -342,17 +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{}, Status: types.ExpirationStatusEnabled, + Prefix: aws.String("health_check"), } putBucketLifecycleConfigurationInput := &s3.PutBucketLifecycleConfigurationInput{ From f71a8fb35a6b50dc6bda7aa8c0ad2842ad177d1c Mon Sep 17 00:00:00 2001 From: Joshua Rodriguez Date: Mon, 4 Nov 2024 10:30:08 -0800 Subject: [PATCH 2/2] Fix (?) to MalformedXML error when setting bucket lifecycle rules --- backend/internal/aws/s3.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/internal/aws/s3.go b/backend/internal/aws/s3.go index ebba8fa..a3ad35e 100644 --- a/backend/internal/aws/s3.go +++ b/backend/internal/aws/s3.go @@ -353,9 +353,10 @@ func SetBucketHealthCheckLifecyclePolicy(s3client S3BucketAPI, conf *appconfig.A Expiration: &types.LifecycleExpiration{ Days: lifecycleInDays, }, - Filter: &types.LifecycleRuleFilterMemberPrefix{}, + Filter: &types.LifecycleRuleFilterMemberPrefix{ + Value: "health_check", + }, Status: types.ExpirationStatusEnabled, - Prefix: aws.String("health_check"), } putBucketLifecycleConfigurationInput := &s3.PutBucketLifecycleConfigurationInput{