feat(backend/s3): added file tag RETENTION (#561)
This commit is contained in:
parent
cf1e007311
commit
de8eefdffc
1 changed files with 17 additions and 0 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue