From ec867328bad93d42405e085437b06101b89d5b02 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Mar 2024 14:15:37 +0100 Subject: [PATCH] feat(backend): moved file tagging feature to EE (#1981) --- backend/pkg/objectstorage/s3/s3.go | 24 +++------------------- backend/pkg/objectstorage/s3/tags.go | 5 +++++ ee/backend/pkg/objectstorage/s3/tags.go | 27 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 backend/pkg/objectstorage/s3/tags.go create mode 100644 ee/backend/pkg/objectstorage/s3/tags.go diff --git a/backend/pkg/objectstorage/s3/s3.go b/backend/pkg/objectstorage/s3/s3.go index c47c5802a..76b5c9060 100644 --- a/backend/pkg/objectstorage/s3/s3.go +++ b/backend/pkg/objectstorage/s3/s3.go @@ -6,7 +6,6 @@ import ( "io" "log" "net/http" - "net/url" "os" "sort" "strconv" @@ -28,7 +27,7 @@ type storageImpl struct { uploader *s3manager.Uploader svc *s3.S3 bucket *string - fileTag string + fileTag *string } func NewS3(cfg *objConfig.ObjectsConfig) (objectstorage.ObjectStorage, error) { @@ -60,14 +59,10 @@ func NewS3(cfg *objConfig.ObjectsConfig) (objectstorage.ObjectStorage, error) { uploader: s3manager.NewUploader(sess), svc: s3.New(sess), // AWS Docs: "These clients are safe to use concurrently." bucket: &cfg.BucketName, - fileTag: loadFileTag(), + fileTag: tagging(cfg.UseS3Tags), }, nil } -func (s *storageImpl) tagging() *string { - return &s.fileTag -} - func (s *storageImpl) Upload(reader io.Reader, key string, contentType string, compression objectstorage.CompressionType) error { cacheControl := "max-age=2628000, immutable, private" var contentEncoding *string @@ -89,7 +84,7 @@ func (s *storageImpl) Upload(reader io.Reader, key string, contentType string, c ContentType: &contentType, CacheControl: &cacheControl, ContentEncoding: contentEncoding, - Tagging: s.tagging(), + Tagging: s.fileTag, }) return err } @@ -207,16 +202,3 @@ func (s *storageImpl) GetPreSignedUploadUrl(key string) (string, error) { } return urlStr, nil } - -func loadFileTag() string { - // Load file tag from env - key := "retention" - value := os.Getenv("RETENTION") - if value == "" { - value = "default" - } - // Create URL encoded tag set for file - params := url.Values{} - params.Add(key, value) - return params.Encode() -} diff --git a/backend/pkg/objectstorage/s3/tags.go b/backend/pkg/objectstorage/s3/tags.go new file mode 100644 index 000000000..ec8c10838 --- /dev/null +++ b/backend/pkg/objectstorage/s3/tags.go @@ -0,0 +1,5 @@ +package s3 + +func tagging(useTags bool) *string { + return nil +} diff --git a/ee/backend/pkg/objectstorage/s3/tags.go b/ee/backend/pkg/objectstorage/s3/tags.go new file mode 100644 index 000000000..8831855af --- /dev/null +++ b/ee/backend/pkg/objectstorage/s3/tags.go @@ -0,0 +1,27 @@ +package s3 + +import ( + "net/url" + "os" +) + +func tagging(useTags bool) *string { + if !useTags { + return nil + } + tag := loadFileTag() + return &tag +} + +func loadFileTag() string { + // Load file tag from env + key := "retention" + value := os.Getenv("RETENTION") + if value == "" { + value = "default" + } + // Create URL encoded tag set for file + params := url.Values{} + params.Add(key, value) + return params.Encode() +}