[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
Этот коммит содержится в:
Saturnino Abril
2017-09-06 03:42:18 +08:00
коммит произвёл GitHub
родитель 7405f66036
Коммит 8d680cf64e
10 изменённых файлов: 207 добавлений и 38 удалений

Просмотреть файл

@@ -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)
}