Fix invalid suffix 'd' in timestring string in s3 expiry config.

This commit is contained in:
Kailash Nadh 2023-09-19 14:45:51 +05:30
parent 11f90b2f62
commit 8f2a08b8db
4 changed files with 12 additions and 1 deletions

View file

@ -575,6 +575,7 @@ func initMediaStore() media.Store {
case "s3":
var o s3.Opt
ko.Unmarshal("upload.s3", &o)
up, err := s3.NewS3Store(o)
if err != nil {
lo.Fatalf("error initializing s3 upload provider %s", err)

View file

@ -40,6 +40,11 @@ func NewS3Store(opt Opt) (media.Store, error) {
}
opt.URL = strings.TrimRight(opt.URL, "/")
// Default (and max S3 expiry) is 7 days.
if opt.Expiry.Seconds() < 1 {
opt.Expiry = time.Duration(167) * time.Hour
}
if opt.AccessKey == "" && opt.SecretKey == "" {
// fallback to IAM role if no access key/secret key is provided.
cl, _ = simples3.NewUsingIAM(opt.Region)

View file

@ -13,5 +13,10 @@ func V2_6_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
return err
}
// Fix incorrect "d" (day) time prefix in S3 expiry settings.
if _, err := db.Exec(`UPDATE settings SET value = '"167h"' WHERE key = 'upload.s3.expiry' AND value = '"14d"'`); err != nil {
return err
}
return nil
}

View file

@ -244,7 +244,7 @@ INSERT INTO settings (key, value) VALUES
('upload.s3.bucket_domain', '""'),
('upload.s3.bucket_path', '"/"'),
('upload.s3.bucket_type', '"public"'),
('upload.s3.expiry', '"14d"'),
('upload.s3.expiry', '"167h"'),
('smtp',
'[{"enabled":true, "host":"smtp.yoursite.com","port":25,"auth_protocol":"cram","username":"username","password":"password","hello_hostname":"","max_conns":10,"idle_timeout":"15s","wait_timeout":"5s","max_msg_retries":2,"tls_type":"STARTTLS","tls_skip_verify":false,"email_headers":[]},
{"enabled":false, "host":"smtp.gmail.com","port":465,"auth_protocol":"login","username":"username@gmail.com","password":"password","hello_hostname":"","max_conns":10,"idle_timeout":"15s","wait_timeout":"5s","max_msg_retries":2,"tls_type":"TLS","tls_skip_verify":false,"email_headers":[]}]'),