feat(backend): moved file tagging feature to EE
This commit is contained in:
parent
96453e96e5
commit
d2cabcdb54
3 changed files with 35 additions and 26 deletions
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
|
@ -28,8 +27,7 @@ type storageImpl struct {
|
|||
uploader *s3manager.Uploader
|
||||
svc *s3.S3
|
||||
bucket *string
|
||||
fileTag string
|
||||
useTags bool
|
||||
fileTag *string
|
||||
}
|
||||
|
||||
func NewS3(cfg *objConfig.ObjectsConfig) (objectstorage.ObjectStorage, error) {
|
||||
|
|
@ -61,18 +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(),
|
||||
useTags: cfg.UseS3Tags,
|
||||
fileTag: tagging(cfg.UseS3Tags),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *storageImpl) tagging() *string {
|
||||
if !s.useTags {
|
||||
return nil
|
||||
}
|
||||
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
|
||||
|
|
@ -94,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
|
||||
}
|
||||
|
|
@ -212,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()
|
||||
}
|
||||
|
|
|
|||
5
backend/pkg/objectstorage/s3/tags.go
Normal file
5
backend/pkg/objectstorage/s3/tags.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package s3
|
||||
|
||||
func tagging(useTags bool) *string {
|
||||
return nil
|
||||
}
|
||||
27
ee/backend/pkg/objectstorage/s3/tags.go
Normal file
27
ee/backend/pkg/objectstorage/s3/tags.go
Normal file
|
|
@ -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()
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue