[MM-14400] Programmatically generate default.json (#10551)

* create/update config.json using go generate

* added default config generator
added config-reset to Jenkins and make package, updated defaults to consider 'isNew' flag

* corrections after code review

* fixed Config.isValid to handle empty encryption keys

* fixed Config.isValid to handle empty encryption keys

* fixed Config.isValid to handle empty encryption keys

* isUpdate now only checks for nil

* Addressed review comments, added unit testing for default config generator

* err shadowing

* license

* provide output file for config generator via ENV variable, since go generate doesn't support arguments and we need two output paths (config-reset and package)

* cleanup

* proper defaults for PushNotificationServer and SendPushNotifications

* corrected generating defaults for TrustedProxyIPHeader to be consistent with default.json in master

* Check for empty SiteURL as well as nil

* corrected SiteURL settings and checking

* crazy typos fixed

* corrected tests to newly expected values

* relaxed the checks

* fixed formatting
Этот коммит содержится в:
Eli Yukelzon
2019-06-06 20:57:01 +03:00
коммит произвёл Jesse Hallam
родитель 978ee13262
Коммит 6a42ad2af5
16 изменённых файлов: 197 добавлений и 497 удалений

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

@@ -0,0 +1,22 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package generator
import (
"encoding/json"
"os"
"github.com/mattermost/mattermost-server/model"
)
func GenerateDefaultConfig(outputFile *os.File) error {
defaultCfg := &model.Config{}
defaultCfg.SetDefaults()
if data, err := json.MarshalIndent(defaultCfg, "", " "); err != nil {
return err
} else if _, err := outputFile.Write(data); err != nil {
return err
}
return nil
}

34
config/config_generator/main.go Обычный файл
Просмотреть файл

@@ -0,0 +1,34 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package main
import (
"fmt"
"os"
"github.com/mattermost/mattermost-server/config/config_generator/generator"
)
func main() {
outputFile := os.Getenv("OUTPUT_CONFIG")
if outputFile == "" {
fmt.Println("Output file name is missing. Please set OUTPUT_CONFIG env variable to absolute path")
os.Exit(2)
}
if _, err := os.Stat(outputFile); !os.IsNotExist(err) {
_, _ = fmt.Fprintf(os.Stderr, "File %s already exists. Not overwriting!\n", outputFile)
os.Exit(2)
}
if file, err := os.Create(outputFile); err == nil {
err = generator.GenerateDefaultConfig(file)
_ = file.Close()
if err != nil {
panic(err)
}
} else {
panic(err)
}
}