Read Mattermost s3 timeout value and used a default if not exist (#3817)

* read Mattermost s3 timeout value and used a default if not exist

* Protection from setting 0 or negative timeout
This commit is contained in:
Harshil Sharma 2022-09-09 15:12:55 +05:30 committed by GitHub
parent 4652a15bab
commit 5f4ad80ef0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View file

@ -13,6 +13,8 @@ import (
mm_model "github.com/mattermost/mattermost-server/v6/model"
)
const defaultS3Timeout = 60 * 1000 // 60 seconds
func createBoardsConfig(mmconfig mm_model.Config, baseURL string, serverID string) *config.Configuration {
filesS3Config := config.AmazonS3Config{}
if mmconfig.FileSettings.AmazonS3AccessKeyId != nil {
@ -45,6 +47,11 @@ func createBoardsConfig(mmconfig mm_model.Config, baseURL string, serverID strin
if mmconfig.FileSettings.AmazonS3Trace != nil {
filesS3Config.Trace = *mmconfig.FileSettings.AmazonS3Trace
}
if mmconfig.FileSettings.AmazonS3RequestTimeoutMilliseconds != nil && *mmconfig.FileSettings.AmazonS3RequestTimeoutMilliseconds > 0 {
filesS3Config.Timeout = *mmconfig.FileSettings.AmazonS3RequestTimeoutMilliseconds
} else {
filesS3Config.Timeout = defaultS3Timeout
}
enableTelemetry := false
if mmconfig.LogSettings.EnableDiagnostics != nil {

View file

@ -94,6 +94,7 @@ func New(params Params) (*Server, error) {
filesBackendSettings.AmazonS3SignV2 = params.Cfg.FilesS3Config.SignV2
filesBackendSettings.AmazonS3SSE = params.Cfg.FilesS3Config.SSE
filesBackendSettings.AmazonS3Trace = params.Cfg.FilesS3Config.Trace
filesBackendSettings.AmazonS3RequestTimeoutMilliseconds = params.Cfg.FilesS3Config.Timeout
filesBackend, appErr := filestore.NewFileBackend(filesBackendSettings)
if appErr != nil {

View file

@ -22,6 +22,7 @@ type AmazonS3Config struct {
SignV2 bool
SSE bool
Trace bool
Timeout int64
}
// Configuration is the app configuration stored in a json file.