From 8d680cf64ec7fb6c8b242b8048989d0f0550cb68 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Wed, 6 Sep 2017 03:42:18 +0800 Subject: [PLT-7475] Add S3 region to system console and add S3 validation (#7373) * add S3 region to system console and add S3 validation * update translation message * add bool as return value to Validate* functions * update Validate* functions to be pure --- app/admin.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'app/admin.go') diff --git a/app/admin.go b/app/admin.go index 609e37c96..531163046 100644 --- a/app/admin.go +++ b/app/admin.go @@ -11,13 +11,14 @@ import ( "runtime/debug" + "net/http" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/jobs" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" - "net/http" ) func GetLogs(page, perPage int) ([]string, *model.AppError) { @@ -153,6 +154,34 @@ func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.A return err } + if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if !utils.ValidateAmazonS3Endpoint(*cfg.FileSettings.AmazonS3Endpoint) { + *cfg.FileSettings.AmazonS3Endpoint = model.FILE_SETTINGS_DEFAULT_AMAZON_S3_ENDPOINT + l4g.Warn(utils.T("utils.config.set_amazon_endpoint"), model.FILE_SETTINGS_DEFAULT_AMAZON_S3_ENDPOINT) + } + + if !utils.ValidateAmazonS3Region(*cfg.FileSettings.AmazonS3Region) { + *cfg.FileSettings.AmazonS3Region = model.FILE_SETTINGS_DEFAULT_AMAZON_S3_REGION + l4g.Warn(utils.T("utils.config.set_amazon_region"), model.FILE_SETTINGS_DEFAULT_AMAZON_S3_REGION) + } + + _, bucketLocation, err := utils.ValidateAmazonS3Bucket(cfg) + if err != nil { + return err + } + + for endpoint, region := range utils.AWS_S3_ENDPOINT_MAP { + if bucketLocation == *cfg.FileSettings.AmazonS3Region { + *cfg.FileSettings.AmazonS3Endpoint = endpoint + l4g.Warn(utils.T("utils.config.set_amazon_endpoint"), endpoint) + + *cfg.FileSettings.AmazonS3Region = region + l4g.Warn(utils.T("utils.config.set_amazon_region"), region) + break + } + } + } + if *utils.Cfg.ClusterSettings.Enable && *utils.Cfg.ClusterSettings.ReadOnlyConfig { return model.NewAppError("saveConfig", "ent.cluster.save_config.error", nil, "", http.StatusForbidden) } -- cgit v1.2.3-1-g7c22