From 8f2a08b8db8b470c3a0258a52bd7583de622b8d5 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Tue, 19 Sep 2023 14:45:51 +0530 Subject: [PATCH] Fix invalid suffix 'd' in timestring string in s3 expiry config. --- cmd/init.go | 1 + internal/media/providers/s3/s3.go | 5 +++++ internal/migrations/v2.6.0.go | 5 +++++ schema.sql | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/init.go b/cmd/init.go index 4239d5d..865a5b1 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -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) diff --git a/internal/media/providers/s3/s3.go b/internal/media/providers/s3/s3.go index 7d9ffc3..bd90356 100644 --- a/internal/media/providers/s3/s3.go +++ b/internal/media/providers/s3/s3.go @@ -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) diff --git a/internal/migrations/v2.6.0.go b/internal/migrations/v2.6.0.go index f7a11f0..2e4ebf6 100644 --- a/internal/migrations/v2.6.0.go +++ b/internal/migrations/v2.6.0.go @@ -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 } diff --git a/schema.sql b/schema.sql index 3f89f6d..c4bc638 100644 --- a/schema.sql +++ b/schema.sql @@ -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":[]}]'),