From de8eefdffcea67ebd74f0f4a498488482420cd94 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 30 Jun 2022 15:22:33 +0200 Subject: [PATCH] feat(backend/s3): added file tag RETENTION (#561) --- backend/pkg/storage/s3.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/pkg/storage/s3.go b/backend/pkg/storage/s3.go index 408dc1864..3e66aa579 100644 --- a/backend/pkg/storage/s3.go +++ b/backend/pkg/storage/s3.go @@ -2,6 +2,7 @@ package storage import ( "io" + "net/url" "sort" "strconv" @@ -15,6 +16,7 @@ type S3 struct { uploader *s3manager.Uploader svc *_s3.S3 bucket *string + fileTag string } func NewS3(region string, bucket string) *S3 { @@ -23,6 +25,7 @@ func NewS3(region string, bucket string) *S3 { uploader: s3manager.NewUploader(sess), svc: _s3.New(sess), // AWS Docs: "These clients are safe to use concurrently." bucket: &bucket, + fileTag: loadFileTag(), } } @@ -40,6 +43,7 @@ func (s3 *S3) Upload(reader io.Reader, key string, contentType string, gzipped b ContentType: &contentType, CacheControl: &cacheControl, ContentEncoding: contentEncoding, + Tagging: &s3.fileTag, }) return err } @@ -95,3 +99,16 @@ func (s3 *S3) GetFrequentlyUsedKeys(projectID uint64) ([]string, error) { } return keyList, nil } + +func loadFileTag() string { + // Load file tag from env + key := "retention" + value := env.String("RETENTION") + if value == "" { + value = "default" + } + // Create URL encoded tag set for file + params := url.Values{} + params.Add(key, value) + return params.Encode() +}