set to default value with config is missing (#7320)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
4c1f467442
Коммит
651dd33b29
116
model/config.go
116
model/config.go
@@ -72,17 +72,22 @@ const (
|
||||
|
||||
SITENAME_MAX_LENGTH = 30
|
||||
|
||||
SERVICE_SETTINGS_DEFAULT_SITE_URL = ""
|
||||
SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE = ""
|
||||
SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE = ""
|
||||
SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT = 300
|
||||
SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT = 300
|
||||
SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM = ""
|
||||
SERVICE_SETTINGS_DEFAULT_SITE_URL = ""
|
||||
SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE = ""
|
||||
SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE = ""
|
||||
SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT = 300
|
||||
SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT = 300
|
||||
SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS = 10
|
||||
SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM = ""
|
||||
SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS = ":8065"
|
||||
|
||||
TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM = 50
|
||||
TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT = ""
|
||||
TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT = ""
|
||||
TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT = 300
|
||||
|
||||
SQL_SETTINGS_DEFAULT_DATA_SOURCE = "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
|
||||
|
||||
EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION = ""
|
||||
|
||||
SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK = "https://about.mattermost.com/default-terms/"
|
||||
@@ -136,7 +141,7 @@ const (
|
||||
type ServiceSettings struct {
|
||||
SiteURL *string
|
||||
LicenseFileLocation *string
|
||||
ListenAddress string
|
||||
ListenAddress *string
|
||||
ConnectionSecurity *string
|
||||
TLSCertFile *string
|
||||
TLSKeyFile *string
|
||||
@@ -145,7 +150,7 @@ type ServiceSettings struct {
|
||||
Forward80To443 *bool
|
||||
ReadTimeout *int
|
||||
WriteTimeout *int
|
||||
MaximumLoginAttempts int
|
||||
MaximumLoginAttempts *int
|
||||
GoroutineHealthThreshold *int
|
||||
GoogleDeveloperKey string
|
||||
EnableOAuthServiceProvider bool
|
||||
@@ -219,12 +224,12 @@ type SSOSettings struct {
|
||||
}
|
||||
|
||||
type SqlSettings struct {
|
||||
DriverName string
|
||||
DataSource string
|
||||
DriverName *string
|
||||
DataSource *string
|
||||
DataSourceReplicas []string
|
||||
DataSourceSearchReplicas []string
|
||||
MaxIdleConns int
|
||||
MaxOpenConns int
|
||||
MaxIdleConns *int
|
||||
MaxOpenConns *int
|
||||
Trace bool
|
||||
AtRestEncryptKey string
|
||||
QueryTimeout *int
|
||||
@@ -254,7 +259,7 @@ type FileSettings struct {
|
||||
EnableMobileUpload *bool
|
||||
EnableMobileDownload *bool
|
||||
MaxFileSize *int64
|
||||
DriverName string
|
||||
DriverName *string
|
||||
Directory string
|
||||
EnablePublicLink bool
|
||||
PublicLinkSalt *string
|
||||
@@ -297,9 +302,9 @@ type EmailSettings struct {
|
||||
|
||||
type RateLimitSettings struct {
|
||||
Enable *bool
|
||||
PerSec int
|
||||
PerSec *int
|
||||
MaxBurst *int
|
||||
MemoryStoreSize int
|
||||
MemoryStoreSize *int
|
||||
VaryByRemoteAddr bool
|
||||
VaryByHeader string
|
||||
}
|
||||
@@ -328,7 +333,7 @@ type AnnouncementSettings struct {
|
||||
|
||||
type TeamSettings struct {
|
||||
SiteName string
|
||||
MaxUsersPerTeam int
|
||||
MaxUsersPerTeam *int
|
||||
EnableTeamCreation bool
|
||||
EnableUserCreation bool
|
||||
EnableOpenServer *bool
|
||||
@@ -545,15 +550,40 @@ func ConfigFromJson(data io.Reader) *Config {
|
||||
|
||||
func (o *Config) SetDefaults() {
|
||||
|
||||
if o.SqlSettings.DriverName == nil {
|
||||
o.SqlSettings.DriverName = new(string)
|
||||
*o.SqlSettings.DriverName = DATABASE_DRIVER_MYSQL
|
||||
}
|
||||
|
||||
if o.SqlSettings.DataSource == nil {
|
||||
o.SqlSettings.DataSource = new(string)
|
||||
*o.SqlSettings.DataSource = SQL_SETTINGS_DEFAULT_DATA_SOURCE
|
||||
}
|
||||
|
||||
if len(o.SqlSettings.AtRestEncryptKey) == 0 {
|
||||
o.SqlSettings.AtRestEncryptKey = NewRandomString(32)
|
||||
}
|
||||
|
||||
if o.SqlSettings.MaxIdleConns == nil {
|
||||
o.SqlSettings.MaxIdleConns = new(int)
|
||||
*o.SqlSettings.MaxIdleConns = 20
|
||||
}
|
||||
|
||||
if o.SqlSettings.MaxOpenConns == nil {
|
||||
o.SqlSettings.MaxOpenConns = new(int)
|
||||
*o.SqlSettings.MaxOpenConns = 300
|
||||
}
|
||||
|
||||
if o.SqlSettings.QueryTimeout == nil {
|
||||
o.SqlSettings.QueryTimeout = new(int)
|
||||
*o.SqlSettings.QueryTimeout = 30
|
||||
}
|
||||
|
||||
if o.FileSettings.DriverName == nil {
|
||||
o.FileSettings.DriverName = new(string)
|
||||
*o.FileSettings.DriverName = IMAGE_DRIVER_LOCAL
|
||||
}
|
||||
|
||||
if o.FileSettings.AmazonS3Endpoint == "" {
|
||||
// Defaults to "s3.amazonaws.com"
|
||||
o.FileSettings.AmazonS3Endpoint = "s3.amazonaws.com"
|
||||
@@ -619,6 +649,12 @@ func (o *Config) SetDefaults() {
|
||||
|
||||
if o.ServiceSettings.LicenseFileLocation == nil {
|
||||
o.ServiceSettings.LicenseFileLocation = new(string)
|
||||
*o.ServiceSettings.LicenseFileLocation = ""
|
||||
}
|
||||
|
||||
if o.ServiceSettings.ListenAddress == nil {
|
||||
o.ServiceSettings.ListenAddress = new(string)
|
||||
*o.ServiceSettings.ListenAddress = SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS
|
||||
}
|
||||
|
||||
if o.ServiceSettings.EnableAPIv3 == nil {
|
||||
@@ -690,6 +726,11 @@ func (o *Config) SetDefaults() {
|
||||
*o.PasswordSettings.Symbol = false
|
||||
}
|
||||
|
||||
if o.TeamSettings.MaxUsersPerTeam == nil {
|
||||
o.TeamSettings.MaxUsersPerTeam = new(int)
|
||||
*o.TeamSettings.MaxUsersPerTeam = TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM
|
||||
}
|
||||
|
||||
if o.TeamSettings.EnableCustomBrand == nil {
|
||||
o.TeamSettings.EnableCustomBrand = new(bool)
|
||||
*o.TeamSettings.EnableCustomBrand = false
|
||||
@@ -1316,9 +1357,9 @@ func (o *Config) SetDefaults() {
|
||||
*o.RateLimitSettings.Enable = false
|
||||
}
|
||||
|
||||
if o.ServiceSettings.GoroutineHealthThreshold == nil {
|
||||
o.ServiceSettings.GoroutineHealthThreshold = new(int)
|
||||
*o.ServiceSettings.GoroutineHealthThreshold = -1
|
||||
if o.RateLimitSettings.PerSec == nil {
|
||||
o.RateLimitSettings.PerSec = new(int)
|
||||
*o.RateLimitSettings.PerSec = 10
|
||||
}
|
||||
|
||||
if o.RateLimitSettings.MaxBurst == nil {
|
||||
@@ -1326,6 +1367,16 @@ func (o *Config) SetDefaults() {
|
||||
*o.RateLimitSettings.MaxBurst = 100
|
||||
}
|
||||
|
||||
if o.RateLimitSettings.MemoryStoreSize == nil {
|
||||
o.RateLimitSettings.MemoryStoreSize = new(int)
|
||||
*o.RateLimitSettings.MemoryStoreSize = 10000
|
||||
}
|
||||
|
||||
if o.ServiceSettings.GoroutineHealthThreshold == nil {
|
||||
o.ServiceSettings.GoroutineHealthThreshold = new(int)
|
||||
*o.ServiceSettings.GoroutineHealthThreshold = -1
|
||||
}
|
||||
|
||||
if o.ServiceSettings.ConnectionSecurity == nil {
|
||||
o.ServiceSettings.ConnectionSecurity = new(string)
|
||||
*o.ServiceSettings.ConnectionSecurity = ""
|
||||
@@ -1361,6 +1412,11 @@ func (o *Config) SetDefaults() {
|
||||
*o.ServiceSettings.WriteTimeout = SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT
|
||||
}
|
||||
|
||||
if o.ServiceSettings.MaximumLoginAttempts == nil {
|
||||
o.ServiceSettings.MaximumLoginAttempts = new(int)
|
||||
*o.ServiceSettings.MaximumLoginAttempts = SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS
|
||||
}
|
||||
|
||||
if o.ServiceSettings.Forward80To443 == nil {
|
||||
o.ServiceSettings.Forward80To443 = new(bool)
|
||||
*o.ServiceSettings.Forward80To443 = false
|
||||
@@ -1475,7 +1531,7 @@ func (o *Config) SetDefaults() {
|
||||
|
||||
func (o *Config) IsValid() *AppError {
|
||||
|
||||
if o.ServiceSettings.MaximumLoginAttempts <= 0 {
|
||||
if *o.ServiceSettings.MaximumLoginAttempts <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1485,7 +1541,7 @@ func (o *Config) IsValid() *AppError {
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.ServiceSettings.ListenAddress) == 0 {
|
||||
if len(*o.ServiceSettings.ListenAddress) == 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1497,7 +1553,7 @@ func (o *Config) IsValid() *AppError {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "")
|
||||
}
|
||||
|
||||
if o.TeamSettings.MaxUsersPerTeam <= 0 {
|
||||
if *o.TeamSettings.MaxUsersPerTeam <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1521,11 +1577,11 @@ func (o *Config) IsValid() *AppError {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "")
|
||||
}
|
||||
|
||||
if !(o.SqlSettings.DriverName == DATABASE_DRIVER_MYSQL || o.SqlSettings.DriverName == DATABASE_DRIVER_POSTGRES) {
|
||||
if !(*o.SqlSettings.DriverName == DATABASE_DRIVER_MYSQL || *o.SqlSettings.DriverName == DATABASE_DRIVER_POSTGRES) {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_driver.app_error", nil, "")
|
||||
}
|
||||
|
||||
if o.SqlSettings.MaxIdleConns <= 0 {
|
||||
if *o.SqlSettings.MaxIdleConns <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1533,11 +1589,11 @@ func (o *Config) IsValid() *AppError {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.sql_query_timeout.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.SqlSettings.DataSource) == 0 {
|
||||
if len(*o.SqlSettings.DataSource) == 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "")
|
||||
}
|
||||
|
||||
if o.SqlSettings.MaxOpenConns <= 0 {
|
||||
if *o.SqlSettings.MaxOpenConns <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1545,7 +1601,7 @@ func (o *Config) IsValid() *AppError {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "")
|
||||
}
|
||||
|
||||
if !(o.FileSettings.DriverName == IMAGE_DRIVER_LOCAL || o.FileSettings.DriverName == IMAGE_DRIVER_S3) {
|
||||
if !(*o.FileSettings.DriverName == IMAGE_DRIVER_LOCAL || *o.FileSettings.DriverName == IMAGE_DRIVER_S3) {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1573,11 +1629,11 @@ func (o *Config) IsValid() *AppError {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.email_notification_contents_type.app_error", nil, "")
|
||||
}
|
||||
|
||||
if o.RateLimitSettings.MemoryStoreSize <= 0 {
|
||||
if *o.RateLimitSettings.MemoryStoreSize <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "")
|
||||
}
|
||||
|
||||
if o.RateLimitSettings.PerSec <= 0 {
|
||||
if *o.RateLimitSettings.PerSec <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -1737,7 +1793,7 @@ func (o *Config) Sanitize() {
|
||||
o.GitLabSettings.Secret = FAKE_SETTING
|
||||
}
|
||||
|
||||
o.SqlSettings.DataSource = FAKE_SETTING
|
||||
*o.SqlSettings.DataSource = FAKE_SETTING
|
||||
o.SqlSettings.AtRestEncryptKey = FAKE_SETTING
|
||||
|
||||
for i := range o.SqlSettings.DataSourceReplicas {
|
||||
|
||||
Ссылка в новой задаче
Block a user