From 651dd33b29b7b8b296cc5a12479684fa836867b1 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Thu, 31 Aug 2017 01:54:16 +0800 Subject: set to default value with config is missing (#7320) --- utils/config.go | 11 ++++++----- utils/file.go | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'utils') diff --git a/utils/config.go b/utils/config.go index 14f827983..0ef1a9330 100644 --- a/utils/config.go +++ b/utils/config.go @@ -20,9 +20,10 @@ import ( "github.com/fsnotify/fsnotify" "github.com/spf13/viper" + "net/http" + "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" - "net/http" ) const ( @@ -376,7 +377,7 @@ func LoadConfig(fileName string) { configureLog(&config.LogSettings) - if config.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + if *config.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { dir := config.FileSettings.Directory if len(dir) > 0 && dir[len(dir)-1:] != "/" { config.FileSettings.Directory += "/" @@ -491,7 +492,7 @@ func getClientConfig(c *model.Config) map[string]string { props["DefaultClientLocale"] = *c.LocalizationSettings.DefaultClientLocale props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales - props["SQLDriverName"] = c.SqlSettings.DriverName + props["SQLDriverName"] = *c.SqlSettings.DriverName props["EnableCustomEmoji"] = strconv.FormatBool(*c.ServiceSettings.EnableCustomEmoji) props["EnableEmojiPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableEmojiPicker) @@ -657,8 +658,8 @@ func Desanitize(cfg *model.Config) { cfg.GitLabSettings.Secret = Cfg.GitLabSettings.Secret } - if cfg.SqlSettings.DataSource == model.FAKE_SETTING { - cfg.SqlSettings.DataSource = Cfg.SqlSettings.DataSource + if *cfg.SqlSettings.DataSource == model.FAKE_SETTING { + *cfg.SqlSettings.DataSource = *Cfg.SqlSettings.DataSource } if cfg.SqlSettings.AtRestEncryptKey == model.FAKE_SETTING { cfg.SqlSettings.AtRestEncryptKey = Cfg.SqlSettings.AtRestEncryptKey diff --git a/utils/file.go b/utils/file.go index efed1e954..0ba132b09 100644 --- a/utils/file.go +++ b/utils/file.go @@ -37,7 +37,7 @@ func s3New(endpoint, accessKey, secretKey string, secure bool, signV2 bool, regi } func TestFileConnection() *model.AppError { - if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := Cfg.FileSettings.AmazonS3Endpoint accessKey := Cfg.FileSettings.AmazonS3AccessKeyId secretKey := Cfg.FileSettings.AmazonS3SecretAccessKey @@ -65,7 +65,7 @@ func TestFileConnection() *model.AppError { } } l4g.Info("Connection to S3 or minio is good. Bucket exists.") - } else if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { f := []byte("testingwrite") if err := writeFileLocally(f, Cfg.FileSettings.Directory+TEST_FILE_PATH); err != nil { return model.NewAppError("TestFileConnection", "Don't have permissions to write to local path specified or other error.", nil, err.Error(), http.StatusInternalServerError) @@ -80,7 +80,7 @@ func TestFileConnection() *model.AppError { } func ReadFile(path string) ([]byte, *model.AppError) { - if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := Cfg.FileSettings.AmazonS3Endpoint accessKey := Cfg.FileSettings.AmazonS3AccessKeyId secretKey := Cfg.FileSettings.AmazonS3SecretAccessKey @@ -102,7 +102,7 @@ func ReadFile(path string) ([]byte, *model.AppError) { } else { return f, nil } - } else if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if f, err := ioutil.ReadFile(Cfg.FileSettings.Directory + path); err != nil { return nil, model.NewLocAppError("ReadFile", "api.file.read_file.reading_local.app_error", nil, err.Error()) } else { @@ -114,7 +114,7 @@ func ReadFile(path string) ([]byte, *model.AppError) { } func MoveFile(oldPath, newPath string) *model.AppError { - if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := Cfg.FileSettings.AmazonS3Endpoint accessKey := Cfg.FileSettings.AmazonS3AccessKeyId secretKey := Cfg.FileSettings.AmazonS3SecretAccessKey @@ -142,7 +142,7 @@ func MoveFile(oldPath, newPath string) *model.AppError { if err = s3Clnt.RemoveObject(bucket, oldPath); err != nil { return model.NewLocAppError("moveFile", "api.file.move_file.delete_from_s3.app_error", nil, err.Error()) } - } else if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if err := os.MkdirAll(filepath.Dir(Cfg.FileSettings.Directory+newPath), 0774); err != nil { return model.NewLocAppError("moveFile", "api.file.move_file.rename.app_error", nil, err.Error()) } @@ -158,7 +158,7 @@ func MoveFile(oldPath, newPath string) *model.AppError { } func WriteFile(f []byte, path string) *model.AppError { - if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := Cfg.FileSettings.AmazonS3Endpoint accessKey := Cfg.FileSettings.AmazonS3AccessKeyId secretKey := Cfg.FileSettings.AmazonS3SecretAccessKey @@ -186,7 +186,7 @@ func WriteFile(f []byte, path string) *model.AppError { if err != nil { return model.NewLocAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error()) } - } else if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if err := writeFileLocally(f, Cfg.FileSettings.Directory+path); err != nil { return err } @@ -211,7 +211,7 @@ func writeFileLocally(f []byte, path string) *model.AppError { } func RemoveFile(path string) *model.AppError { - if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := Cfg.FileSettings.AmazonS3Endpoint accessKey := Cfg.FileSettings.AmazonS3AccessKeyId secretKey := Cfg.FileSettings.AmazonS3SecretAccessKey @@ -228,7 +228,7 @@ func RemoveFile(path string) *model.AppError { if err := s3Clnt.RemoveObject(bucket, path); err != nil { return model.NewLocAppError("RemoveFile", "utils.file.remove_file.s3.app_error", nil, err.Error()) } - } else if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if err := os.Remove(Cfg.FileSettings.Directory + path); err != nil { return model.NewLocAppError("RemoveFile", "utils.file.remove_file.local.app_error", nil, err.Error()) } @@ -260,7 +260,7 @@ func getPathsFromObjectInfos(in <-chan s3.ObjectInfo) <-chan string { } func RemoveDirectory(path string) *model.AppError { - if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := Cfg.FileSettings.AmazonS3Endpoint accessKey := Cfg.FileSettings.AmazonS3AccessKeyId secretKey := Cfg.FileSettings.AmazonS3SecretAccessKey @@ -284,7 +284,7 @@ func RemoveDirectory(path string) *model.AppError { } close(doneCh) - } else if Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if err := os.RemoveAll(Cfg.FileSettings.Directory + path); err != nil { return model.NewLocAppError("RemoveDirectory", "utils.file.remove_directory.local.app_error", nil, err.Error()) } -- cgit v1.2.3-1-g7c22