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 (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ type S3 struct {
|
||||||
uploader *s3manager.Uploader
|
uploader *s3manager.Uploader
|
||||||
svc *_s3.S3
|
svc *_s3.S3
|
||||||
bucket *string
|
bucket *string
|
||||||
|
fileTag string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewS3(region string, bucket string) *S3 {
|
func NewS3(region string, bucket string) *S3 {
|
||||||
|
|
@ -23,6 +25,7 @@ func NewS3(region string, bucket string) *S3 {
|
||||||
uploader: s3manager.NewUploader(sess),
|
uploader: s3manager.NewUploader(sess),
|
||||||
svc: _s3.New(sess), // AWS Docs: "These clients are safe to use concurrently."
|
svc: _s3.New(sess), // AWS Docs: "These clients are safe to use concurrently."
|
||||||
bucket: &bucket,
|
bucket: &bucket,
|
||||||
|
fileTag: loadFileTag(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +43,7 @@ func (s3 *S3) Upload(reader io.Reader, key string, contentType string, gzipped b
|
||||||
ContentType: &contentType,
|
ContentType: &contentType,
|
||||||
CacheControl: &cacheControl,
|
CacheControl: &cacheControl,
|
||||||
ContentEncoding: contentEncoding,
|
ContentEncoding: contentEncoding,
|
||||||
|
Tagging: &s3.fileTag,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -95,3 +99,16 @@ func (s3 *S3) GetFrequentlyUsedKeys(projectID uint64) ([]string, error) {
|
||||||
}
|
}
|
||||||
return keyList, nil
|
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