Skip to content

Commit

Permalink
Fix invalid suffix 'd' in timestring string in s3 expiry config.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Sep 19, 2023
1 parent 11f90b2 commit 8f2a08b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/media/providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/migrations/v2.6.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}]'),
Expand Down

0 comments on commit 8f2a08b

Please sign in to comment.