github.com/demisto/mattermost-server@v4.9.0-rc3+incompatible/model/config.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"encoding/json"
     8  	"io"
     9  	"net/http"
    10  	"net/url"
    11  	"strings"
    12  	"time"
    13  )
    14  
    15  const (
    16  	CONN_SECURITY_NONE     = ""
    17  	CONN_SECURITY_PLAIN    = "PLAIN"
    18  	CONN_SECURITY_TLS      = "TLS"
    19  	CONN_SECURITY_STARTTLS = "STARTTLS"
    20  
    21  	IMAGE_DRIVER_LOCAL = "local"
    22  	IMAGE_DRIVER_S3    = "amazons3"
    23  
    24  	DATABASE_DRIVER_MYSQL    = "mysql"
    25  	DATABASE_DRIVER_POSTGRES = "postgres"
    26  
    27  	MINIO_ACCESS_KEY = "minioaccesskey"
    28  	MINIO_SECRET_KEY = "miniosecretkey"
    29  	MINIO_BUCKET     = "mattermost-test"
    30  
    31  	PASSWORD_MAXIMUM_LENGTH = 64
    32  	PASSWORD_MINIMUM_LENGTH = 5
    33  
    34  	SERVICE_GITLAB    = "gitlab"
    35  	SERVICE_GOOGLE    = "google"
    36  	SERVICE_OFFICE365 = "office365"
    37  
    38  	GENERIC_NO_CHANNEL_NOTIFICATION = "generic_no_channel"
    39  	GENERIC_NOTIFICATION            = "generic"
    40  	FULL_NOTIFICATION               = "full"
    41  
    42  	DIRECT_MESSAGE_ANY  = "any"
    43  	DIRECT_MESSAGE_TEAM = "team"
    44  
    45  	SHOW_USERNAME          = "username"
    46  	SHOW_NICKNAME_FULLNAME = "nickname_full_name"
    47  	SHOW_FULLNAME          = "full_name"
    48  
    49  	PERMISSIONS_ALL           = "all"
    50  	PERMISSIONS_CHANNEL_ADMIN = "channel_admin"
    51  	PERMISSIONS_TEAM_ADMIN    = "team_admin"
    52  	PERMISSIONS_SYSTEM_ADMIN  = "system_admin"
    53  
    54  	FAKE_SETTING = "********************************"
    55  
    56  	RESTRICT_EMOJI_CREATION_ALL          = "all"
    57  	RESTRICT_EMOJI_CREATION_ADMIN        = "admin"
    58  	RESTRICT_EMOJI_CREATION_SYSTEM_ADMIN = "system_admin"
    59  
    60  	PERMISSIONS_DELETE_POST_ALL          = "all"
    61  	PERMISSIONS_DELETE_POST_TEAM_ADMIN   = "team_admin"
    62  	PERMISSIONS_DELETE_POST_SYSTEM_ADMIN = "system_admin"
    63  
    64  	ALLOW_EDIT_POST_ALWAYS     = "always"
    65  	ALLOW_EDIT_POST_NEVER      = "never"
    66  	ALLOW_EDIT_POST_TIME_LIMIT = "time_limit"
    67  
    68  	GROUP_UNREAD_CHANNELS_DISABLED    = "disabled"
    69  	GROUP_UNREAD_CHANNELS_DEFAULT_ON  = "default_on"
    70  	GROUP_UNREAD_CHANNELS_DEFAULT_OFF = "default_off"
    71  
    72  	EMAIL_BATCHING_BUFFER_SIZE = 256
    73  	EMAIL_BATCHING_INTERVAL    = 30
    74  
    75  	EMAIL_NOTIFICATION_CONTENTS_FULL    = "full"
    76  	EMAIL_NOTIFICATION_CONTENTS_GENERIC = "generic"
    77  
    78  	SITENAME_MAX_LENGTH = 30
    79  
    80  	SERVICE_SETTINGS_DEFAULT_SITE_URL           = ""
    81  	SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE      = ""
    82  	SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE       = ""
    83  	SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT       = 300
    84  	SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT      = 300
    85  	SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS = 10
    86  	SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM    = ""
    87  	SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS = ":8065"
    88  
    89  	TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM       = 50
    90  	TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT        = ""
    91  	TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT  = ""
    92  	TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT = 300
    93  
    94  	SQL_SETTINGS_DEFAULT_DATA_SOURCE = "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
    95  
    96  	EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION = ""
    97  
    98  	SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK = "https://about.mattermost.com/default-terms/"
    99  	SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK   = "https://about.mattermost.com/default-privacy-policy/"
   100  	SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK            = "https://about.mattermost.com/default-about/"
   101  	SUPPORT_SETTINGS_DEFAULT_HELP_LINK             = "https://about.mattermost.com/default-help/"
   102  	SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK = "https://about.mattermost.com/default-report-a-problem/"
   103  	SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL         = "feedback@mattermost.com"
   104  
   105  	LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE = ""
   106  	LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE  = ""
   107  	LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE      = ""
   108  	LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE   = ""
   109  	LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE   = ""
   110  	LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE         = ""
   111  	LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE   = ""
   112  	LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME     = ""
   113  
   114  	SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE = ""
   115  	SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE  = ""
   116  	SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE      = ""
   117  	SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE   = ""
   118  	SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE   = ""
   119  	SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE     = ""
   120  	SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE   = ""
   121  
   122  	NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK         = "https://about.mattermost.com/downloads/"
   123  	NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK = "https://about.mattermost.com/mattermost-android-app/"
   124  	NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK     = "https://about.mattermost.com/mattermost-ios-app/"
   125  
   126  	WEBRTC_SETTINGS_DEFAULT_STUN_URI = ""
   127  	WEBRTC_SETTINGS_DEFAULT_TURN_URI = ""
   128  
   129  	ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS = 2500
   130  
   131  	ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR      = "#f2a93b"
   132  	ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR = "#333333"
   133  
   134  	TEAM_SETTINGS_DEFAULT_TEAM_TEXT = "default"
   135  
   136  	ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL                    = ""
   137  	ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME                          = ""
   138  	ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD                          = ""
   139  	ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS               = 1
   140  	ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS                 = 1
   141  	ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS        = 365
   142  	ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME   = "03:00"
   143  	ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX                      = ""
   144  	ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE          = 1
   145  	ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS = 3600
   146  	ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS           = 30
   147  
   148  	DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS  = 365
   149  	DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS     = 365
   150  	DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME = "02:00"
   151  
   152  	PLUGIN_SETTINGS_DEFAULT_DIRECTORY        = "./plugins"
   153  	PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY = "./client/plugins"
   154  
   155  	TIMEZONE_SETTINGS_DEFAULT_SUPPORTED_TIMEZONES_PATH = "timezones.json"
   156  
   157  	COMPLIANCE_EXPORT_TYPE_ACTIANCE    = "actiance"
   158  	COMPLIANCE_EXPORT_TYPE_GLOBALRELAY = "globalrelay"
   159  	GLOBALRELAY_CUSTOMER_TYPE_A9       = "A9"
   160  	GLOBALRELAY_CUSTOMER_TYPE_A10      = "A10"
   161  )
   162  
   163  type ServiceSettings struct {
   164  	SiteURL                                           *string
   165  	WebsocketURL                                      *string
   166  	LicenseFileLocation                               *string
   167  	ListenAddress                                     *string
   168  	ConnectionSecurity                                *string
   169  	TLSCertFile                                       *string
   170  	TLSKeyFile                                        *string
   171  	UseLetsEncrypt                                    *bool
   172  	LetsEncryptCertificateCacheFile                   *string
   173  	Forward80To443                                    *bool
   174  	ReadTimeout                                       *int
   175  	WriteTimeout                                      *int
   176  	MaximumLoginAttempts                              *int
   177  	GoroutineHealthThreshold                          *int
   178  	GoogleDeveloperKey                                string
   179  	EnableOAuthServiceProvider                        bool
   180  	EnableIncomingWebhooks                            bool
   181  	EnableOutgoingWebhooks                            bool
   182  	EnableCommands                                    *bool
   183  	EnableOnlyAdminIntegrations                       *bool
   184  	EnablePostUsernameOverride                        bool
   185  	EnablePostIconOverride                            bool
   186  	EnableAPIv3                                       *bool
   187  	EnableLinkPreviews                                *bool
   188  	EnableTesting                                     bool
   189  	EnableDeveloper                                   *bool
   190  	EnableSecurityFixAlert                            *bool
   191  	EnableInsecureOutgoingConnections                 *bool
   192  	AllowedUntrustedInternalConnections               *string
   193  	EnableMultifactorAuthentication                   *bool
   194  	EnforceMultifactorAuthentication                  *bool
   195  	EnableUserAccessTokens                            *bool
   196  	AllowCorsFrom                                     *string
   197  	AllowCookiesForSubdomains                         *bool
   198  	SessionLengthWebInDays                            *int
   199  	SessionLengthMobileInDays                         *int
   200  	SessionLengthSSOInDays                            *int
   201  	SessionCacheInMinutes                             *int
   202  	SessionIdleTimeoutInMinutes                       *int
   203  	WebsocketSecurePort                               *int
   204  	WebsocketPort                                     *int
   205  	WebserverMode                                     *string
   206  	EnableCustomEmoji                                 *bool
   207  	EnableEmojiPicker                                 *bool
   208  	RestrictCustomEmojiCreation                       *string
   209  	RestrictPostDelete                                *string
   210  	AllowEditPost                                     *string
   211  	PostEditTimeLimit                                 *int
   212  	TimeBetweenUserTypingUpdatesMilliseconds          *int64
   213  	EnablePostSearch                                  *bool
   214  	EnableUserTypingMessages                          *bool
   215  	EnableChannelViewedMessages                       *bool
   216  	EnableUserStatuses                                *bool
   217  	ExperimentalEnableAuthenticationTransfer          *bool
   218  	ClusterLogTimeoutMilliseconds                     *int
   219  	CloseUnusedDirectMessages                         *bool
   220  	EnablePreviewFeatures                             *bool
   221  	EnableTutorial                                    *bool
   222  	ExperimentalEnableDefaultChannelLeaveJoinMessages *bool
   223  	ExperimentalGroupUnreadChannels                   *string
   224  	ImageProxyType                                    *string
   225  	ImageProxyURL                                     *string
   226  	ImageProxyOptions                                 *string
   227  }
   228  
   229  func (s *ServiceSettings) SetDefaults() {
   230  	if s.SiteURL == nil {
   231  		s.SiteURL = NewString(SERVICE_SETTINGS_DEFAULT_SITE_URL)
   232  	}
   233  
   234  	if s.WebsocketURL == nil {
   235  		s.WebsocketURL = NewString("")
   236  	}
   237  
   238  	if s.LicenseFileLocation == nil {
   239  		s.LicenseFileLocation = NewString("")
   240  	}
   241  
   242  	if s.ListenAddress == nil {
   243  		s.ListenAddress = NewString(SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS)
   244  	}
   245  
   246  	if s.EnableAPIv3 == nil {
   247  		s.EnableAPIv3 = NewBool(true)
   248  	}
   249  
   250  	if s.EnableLinkPreviews == nil {
   251  		s.EnableLinkPreviews = NewBool(false)
   252  	}
   253  
   254  	if s.EnableDeveloper == nil {
   255  		s.EnableDeveloper = NewBool(false)
   256  	}
   257  
   258  	if s.EnableSecurityFixAlert == nil {
   259  		s.EnableSecurityFixAlert = NewBool(true)
   260  	}
   261  
   262  	if s.EnableInsecureOutgoingConnections == nil {
   263  		s.EnableInsecureOutgoingConnections = NewBool(false)
   264  	}
   265  
   266  	if s.AllowedUntrustedInternalConnections == nil {
   267  		s.AllowedUntrustedInternalConnections = NewString("")
   268  	}
   269  
   270  	if s.EnableMultifactorAuthentication == nil {
   271  		s.EnableMultifactorAuthentication = NewBool(false)
   272  	}
   273  
   274  	if s.EnforceMultifactorAuthentication == nil {
   275  		s.EnforceMultifactorAuthentication = NewBool(false)
   276  	}
   277  
   278  	if s.EnableUserAccessTokens == nil {
   279  		s.EnableUserAccessTokens = NewBool(false)
   280  	}
   281  
   282  	if s.GoroutineHealthThreshold == nil {
   283  		s.GoroutineHealthThreshold = NewInt(-1)
   284  	}
   285  
   286  	if s.ConnectionSecurity == nil {
   287  		s.ConnectionSecurity = NewString("")
   288  	}
   289  
   290  	if s.TLSKeyFile == nil {
   291  		s.TLSKeyFile = NewString(SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE)
   292  	}
   293  
   294  	if s.TLSCertFile == nil {
   295  		s.TLSCertFile = NewString(SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE)
   296  	}
   297  
   298  	if s.UseLetsEncrypt == nil {
   299  		s.UseLetsEncrypt = NewBool(false)
   300  	}
   301  
   302  	if s.LetsEncryptCertificateCacheFile == nil {
   303  		s.LetsEncryptCertificateCacheFile = NewString("./config/letsencrypt.cache")
   304  	}
   305  
   306  	if s.ReadTimeout == nil {
   307  		s.ReadTimeout = NewInt(SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT)
   308  	}
   309  
   310  	if s.WriteTimeout == nil {
   311  		s.WriteTimeout = NewInt(SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT)
   312  	}
   313  
   314  	if s.MaximumLoginAttempts == nil {
   315  		s.MaximumLoginAttempts = NewInt(SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS)
   316  	}
   317  
   318  	if s.Forward80To443 == nil {
   319  		s.Forward80To443 = NewBool(false)
   320  	}
   321  
   322  	if s.TimeBetweenUserTypingUpdatesMilliseconds == nil {
   323  		s.TimeBetweenUserTypingUpdatesMilliseconds = NewInt64(5000)
   324  	}
   325  
   326  	if s.EnablePostSearch == nil {
   327  		s.EnablePostSearch = NewBool(true)
   328  	}
   329  
   330  	if s.EnableUserTypingMessages == nil {
   331  		s.EnableUserTypingMessages = NewBool(true)
   332  	}
   333  
   334  	if s.EnableChannelViewedMessages == nil {
   335  		s.EnableChannelViewedMessages = NewBool(true)
   336  	}
   337  
   338  	if s.EnableUserStatuses == nil {
   339  		s.EnableUserStatuses = NewBool(true)
   340  	}
   341  
   342  	if s.ClusterLogTimeoutMilliseconds == nil {
   343  		s.ClusterLogTimeoutMilliseconds = NewInt(2000)
   344  	}
   345  
   346  	if s.CloseUnusedDirectMessages == nil {
   347  		s.CloseUnusedDirectMessages = NewBool(false)
   348  	}
   349  
   350  	if s.EnableTutorial == nil {
   351  		s.EnableTutorial = NewBool(true)
   352  	}
   353  
   354  	if s.SessionLengthWebInDays == nil {
   355  		s.SessionLengthWebInDays = NewInt(30)
   356  	}
   357  
   358  	if s.SessionLengthMobileInDays == nil {
   359  		s.SessionLengthMobileInDays = NewInt(30)
   360  	}
   361  
   362  	if s.SessionLengthSSOInDays == nil {
   363  		s.SessionLengthSSOInDays = NewInt(30)
   364  	}
   365  
   366  	if s.SessionCacheInMinutes == nil {
   367  		s.SessionCacheInMinutes = NewInt(10)
   368  	}
   369  
   370  	if s.SessionIdleTimeoutInMinutes == nil {
   371  		s.SessionIdleTimeoutInMinutes = NewInt(0)
   372  	}
   373  
   374  	if s.EnableCommands == nil {
   375  		s.EnableCommands = NewBool(false)
   376  	}
   377  
   378  	if s.EnableOnlyAdminIntegrations == nil {
   379  		s.EnableOnlyAdminIntegrations = NewBool(true)
   380  	}
   381  
   382  	if s.WebsocketPort == nil {
   383  		s.WebsocketPort = NewInt(80)
   384  	}
   385  
   386  	if s.WebsocketSecurePort == nil {
   387  		s.WebsocketSecurePort = NewInt(443)
   388  	}
   389  
   390  	if s.AllowCorsFrom == nil {
   391  		s.AllowCorsFrom = NewString(SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM)
   392  	}
   393  
   394  	if s.AllowCookiesForSubdomains == nil {
   395  		s.AllowCookiesForSubdomains = NewBool(false)
   396  	}
   397  
   398  	if s.WebserverMode == nil {
   399  		s.WebserverMode = NewString("gzip")
   400  	} else if *s.WebserverMode == "regular" {
   401  		*s.WebserverMode = "gzip"
   402  	}
   403  
   404  	if s.EnableCustomEmoji == nil {
   405  		s.EnableCustomEmoji = NewBool(false)
   406  	}
   407  
   408  	if s.EnableEmojiPicker == nil {
   409  		s.EnableEmojiPicker = NewBool(true)
   410  	}
   411  
   412  	if s.RestrictCustomEmojiCreation == nil {
   413  		s.RestrictCustomEmojiCreation = NewString(RESTRICT_EMOJI_CREATION_ALL)
   414  	}
   415  
   416  	if s.RestrictPostDelete == nil {
   417  		s.RestrictPostDelete = NewString(PERMISSIONS_DELETE_POST_ALL)
   418  	}
   419  
   420  	if s.AllowEditPost == nil {
   421  		s.AllowEditPost = NewString(ALLOW_EDIT_POST_ALWAYS)
   422  	}
   423  
   424  	if s.ExperimentalEnableAuthenticationTransfer == nil {
   425  		s.ExperimentalEnableAuthenticationTransfer = NewBool(true)
   426  	}
   427  
   428  	if s.PostEditTimeLimit == nil {
   429  		s.PostEditTimeLimit = NewInt(-1)
   430  	}
   431  
   432  	if s.EnablePreviewFeatures == nil {
   433  		s.EnablePreviewFeatures = NewBool(true)
   434  	}
   435  
   436  	if s.ExperimentalEnableDefaultChannelLeaveJoinMessages == nil {
   437  		s.ExperimentalEnableDefaultChannelLeaveJoinMessages = NewBool(true)
   438  	}
   439  
   440  	if s.ExperimentalGroupUnreadChannels == nil {
   441  		s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DISABLED)
   442  	} else if *s.ExperimentalGroupUnreadChannels == "0" {
   443  		s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DISABLED)
   444  	} else if *s.ExperimentalGroupUnreadChannels == "1" {
   445  		s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DEFAULT_ON)
   446  	}
   447  
   448  	if s.ImageProxyType == nil {
   449  		s.ImageProxyType = NewString("")
   450  	}
   451  
   452  	if s.ImageProxyURL == nil {
   453  		s.ImageProxyURL = NewString("")
   454  	}
   455  
   456  	if s.ImageProxyOptions == nil {
   457  		s.ImageProxyOptions = NewString("")
   458  	}
   459  }
   460  
   461  type ClusterSettings struct {
   462  	Enable                *bool
   463  	ClusterName           *string
   464  	OverrideHostname      *string
   465  	UseIpAddress          *bool
   466  	UseExperimentalGossip *bool
   467  	ReadOnlyConfig        *bool
   468  	GossipPort            *int
   469  	StreamingPort         *int
   470  }
   471  
   472  func (s *ClusterSettings) SetDefaults() {
   473  	if s.Enable == nil {
   474  		s.Enable = NewBool(false)
   475  	}
   476  
   477  	if s.ClusterName == nil {
   478  		s.ClusterName = NewString("")
   479  	}
   480  
   481  	if s.OverrideHostname == nil {
   482  		s.OverrideHostname = NewString("")
   483  	}
   484  
   485  	if s.UseIpAddress == nil {
   486  		s.UseIpAddress = NewBool(true)
   487  	}
   488  
   489  	if s.UseExperimentalGossip == nil {
   490  		s.UseExperimentalGossip = NewBool(false)
   491  	}
   492  
   493  	if s.ReadOnlyConfig == nil {
   494  		s.ReadOnlyConfig = NewBool(true)
   495  	}
   496  
   497  	if s.GossipPort == nil {
   498  		s.GossipPort = NewInt(8074)
   499  	}
   500  
   501  	if s.StreamingPort == nil {
   502  		s.StreamingPort = NewInt(8075)
   503  	}
   504  }
   505  
   506  type MetricsSettings struct {
   507  	Enable           *bool
   508  	BlockProfileRate *int
   509  	ListenAddress    *string
   510  }
   511  
   512  func (s *MetricsSettings) SetDefaults() {
   513  	if s.ListenAddress == nil {
   514  		s.ListenAddress = NewString(":8067")
   515  	}
   516  
   517  	if s.Enable == nil {
   518  		s.Enable = NewBool(false)
   519  	}
   520  
   521  	if s.BlockProfileRate == nil {
   522  		s.BlockProfileRate = NewInt(0)
   523  	}
   524  }
   525  
   526  type AnalyticsSettings struct {
   527  	MaxUsersForStatistics *int
   528  }
   529  
   530  func (s *AnalyticsSettings) SetDefaults() {
   531  	if s.MaxUsersForStatistics == nil {
   532  		s.MaxUsersForStatistics = NewInt(ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS)
   533  	}
   534  }
   535  
   536  type SSOSettings struct {
   537  	Enable          bool
   538  	Secret          string
   539  	Id              string
   540  	Scope           string
   541  	AuthEndpoint    string
   542  	TokenEndpoint   string
   543  	UserApiEndpoint string
   544  }
   545  
   546  type SqlSettings struct {
   547  	DriverName               *string
   548  	DataSource               *string
   549  	DataSourceReplicas       []string
   550  	DataSourceSearchReplicas []string
   551  	MaxIdleConns             *int
   552  	MaxOpenConns             *int
   553  	Trace                    bool
   554  	AtRestEncryptKey         string
   555  	QueryTimeout             *int
   556  }
   557  
   558  func (s *SqlSettings) SetDefaults() {
   559  	if s.DriverName == nil {
   560  		s.DriverName = NewString(DATABASE_DRIVER_MYSQL)
   561  	}
   562  
   563  	if s.DataSource == nil {
   564  		s.DataSource = NewString(SQL_SETTINGS_DEFAULT_DATA_SOURCE)
   565  	}
   566  
   567  	if len(s.AtRestEncryptKey) == 0 {
   568  		s.AtRestEncryptKey = NewRandomString(32)
   569  	}
   570  
   571  	if s.MaxIdleConns == nil {
   572  		s.MaxIdleConns = NewInt(20)
   573  	}
   574  
   575  	if s.MaxOpenConns == nil {
   576  		s.MaxOpenConns = NewInt(300)
   577  	}
   578  
   579  	if s.QueryTimeout == nil {
   580  		s.QueryTimeout = NewInt(30)
   581  	}
   582  }
   583  
   584  type LogSettings struct {
   585  	EnableConsole          bool
   586  	ConsoleLevel           string
   587  	EnableFile             bool
   588  	FileLevel              string
   589  	FileFormat             string
   590  	FileLocation           string
   591  	EnableWebhookDebugging bool
   592  	EnableDiagnostics      *bool
   593  }
   594  
   595  func (s *LogSettings) SetDefaults() {
   596  	if s.EnableDiagnostics == nil {
   597  		s.EnableDiagnostics = NewBool(true)
   598  	}
   599  }
   600  
   601  type PasswordSettings struct {
   602  	MinimumLength *int
   603  	Lowercase     *bool
   604  	Number        *bool
   605  	Uppercase     *bool
   606  	Symbol        *bool
   607  }
   608  
   609  func (s *PasswordSettings) SetDefaults() {
   610  	if s.MinimumLength == nil {
   611  		s.MinimumLength = NewInt(PASSWORD_MINIMUM_LENGTH)
   612  	}
   613  
   614  	if s.Lowercase == nil {
   615  		s.Lowercase = NewBool(false)
   616  	}
   617  
   618  	if s.Number == nil {
   619  		s.Number = NewBool(false)
   620  	}
   621  
   622  	if s.Uppercase == nil {
   623  		s.Uppercase = NewBool(false)
   624  	}
   625  
   626  	if s.Symbol == nil {
   627  		s.Symbol = NewBool(false)
   628  	}
   629  }
   630  
   631  type FileSettings struct {
   632  	EnableFileAttachments   *bool
   633  	EnableMobileUpload      *bool
   634  	EnableMobileDownload    *bool
   635  	MaxFileSize             *int64
   636  	DriverName              *string
   637  	Directory               string
   638  	EnablePublicLink        bool
   639  	PublicLinkSalt          *string
   640  	InitialFont             string
   641  	AmazonS3AccessKeyId     string
   642  	AmazonS3SecretAccessKey string
   643  	AmazonS3Bucket          string
   644  	AmazonS3Region          string
   645  	AmazonS3Endpoint        string
   646  	AmazonS3SSL             *bool
   647  	AmazonS3SignV2          *bool
   648  	AmazonS3SSE             *bool
   649  	AmazonS3Trace           *bool
   650  }
   651  
   652  func (s *FileSettings) SetDefaults() {
   653  	if s.DriverName == nil {
   654  		s.DriverName = NewString(IMAGE_DRIVER_LOCAL)
   655  	}
   656  
   657  	if s.AmazonS3Endpoint == "" {
   658  		// Defaults to "s3.amazonaws.com"
   659  		s.AmazonS3Endpoint = "s3.amazonaws.com"
   660  	}
   661  
   662  	if s.AmazonS3SSL == nil {
   663  		s.AmazonS3SSL = NewBool(true) // Secure by default.
   664  	}
   665  
   666  	if s.AmazonS3SignV2 == nil {
   667  		s.AmazonS3SignV2 = new(bool)
   668  		// Signature v2 is not enabled by default.
   669  	}
   670  
   671  	if s.AmazonS3SSE == nil {
   672  		s.AmazonS3SSE = NewBool(false) // Not Encrypted by default.
   673  	}
   674  
   675  	if s.AmazonS3Trace == nil {
   676  		s.AmazonS3Trace = NewBool(false)
   677  	}
   678  
   679  	if s.EnableFileAttachments == nil {
   680  		s.EnableFileAttachments = NewBool(true)
   681  	}
   682  
   683  	if s.EnableMobileUpload == nil {
   684  		s.EnableMobileUpload = NewBool(true)
   685  	}
   686  
   687  	if s.EnableMobileDownload == nil {
   688  		s.EnableMobileDownload = NewBool(true)
   689  	}
   690  
   691  	if s.MaxFileSize == nil {
   692  		s.MaxFileSize = NewInt64(52428800) // 50 MB
   693  	}
   694  
   695  	if s.PublicLinkSalt == nil || len(*s.PublicLinkSalt) == 0 {
   696  		s.PublicLinkSalt = NewString(NewRandomString(32))
   697  	}
   698  
   699  	if s.InitialFont == "" {
   700  		// Defaults to "luximbi.ttf"
   701  		s.InitialFont = "luximbi.ttf"
   702  	}
   703  
   704  	if s.Directory == "" {
   705  		s.Directory = "./data/"
   706  	}
   707  }
   708  
   709  type EmailSettings struct {
   710  	EnableSignUpWithEmail             bool
   711  	EnableSignInWithEmail             *bool
   712  	EnableSignInWithUsername          *bool
   713  	SendEmailNotifications            bool
   714  	UseChannelInEmailNotifications    *bool
   715  	RequireEmailVerification          bool
   716  	FeedbackName                      string
   717  	FeedbackEmail                     string
   718  	FeedbackOrganization              *string
   719  	EnableSMTPAuth                    *bool
   720  	SMTPUsername                      string
   721  	SMTPPassword                      string
   722  	SMTPServer                        string
   723  	SMTPPort                          string
   724  	ConnectionSecurity                string
   725  	InviteSalt                        string
   726  	SendPushNotifications             *bool
   727  	PushNotificationServer            *string
   728  	PushNotificationContents          *string
   729  	EnableEmailBatching               *bool
   730  	EmailBatchingBufferSize           *int
   731  	EmailBatchingInterval             *int
   732  	SkipServerCertificateVerification *bool
   733  	EmailNotificationContentsType     *string
   734  	LoginButtonColor                  *string
   735  	LoginButtonBorderColor            *string
   736  	LoginButtonTextColor              *string
   737  }
   738  
   739  func (s *EmailSettings) SetDefaults() {
   740  	if len(s.InviteSalt) == 0 {
   741  		s.InviteSalt = NewRandomString(32)
   742  	}
   743  
   744  	if s.EnableSignInWithEmail == nil {
   745  		s.EnableSignInWithEmail = NewBool(s.EnableSignUpWithEmail)
   746  	}
   747  
   748  	if s.EnableSignInWithUsername == nil {
   749  		s.EnableSignInWithUsername = NewBool(false)
   750  	}
   751  
   752  	if s.UseChannelInEmailNotifications == nil {
   753  		s.UseChannelInEmailNotifications = NewBool(false)
   754  	}
   755  
   756  	if s.SendPushNotifications == nil {
   757  		s.SendPushNotifications = NewBool(false)
   758  	}
   759  
   760  	if s.PushNotificationServer == nil {
   761  		s.PushNotificationServer = NewString("")
   762  	}
   763  
   764  	if s.PushNotificationContents == nil {
   765  		s.PushNotificationContents = NewString(GENERIC_NOTIFICATION)
   766  	}
   767  
   768  	if s.FeedbackOrganization == nil {
   769  		s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION)
   770  	}
   771  
   772  	if s.EnableEmailBatching == nil {
   773  		s.EnableEmailBatching = NewBool(false)
   774  	}
   775  
   776  	if s.EmailBatchingBufferSize == nil {
   777  		s.EmailBatchingBufferSize = NewInt(EMAIL_BATCHING_BUFFER_SIZE)
   778  	}
   779  
   780  	if s.EmailBatchingInterval == nil {
   781  		s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL)
   782  	}
   783  
   784  	if s.EnableSMTPAuth == nil {
   785  		s.EnableSMTPAuth = new(bool)
   786  		if s.ConnectionSecurity == CONN_SECURITY_NONE {
   787  			*s.EnableSMTPAuth = false
   788  		} else {
   789  			*s.EnableSMTPAuth = true
   790  		}
   791  	}
   792  
   793  	if s.ConnectionSecurity == CONN_SECURITY_PLAIN {
   794  		s.ConnectionSecurity = CONN_SECURITY_NONE
   795  	}
   796  
   797  	if s.SkipServerCertificateVerification == nil {
   798  		s.SkipServerCertificateVerification = NewBool(false)
   799  	}
   800  
   801  	if s.EmailNotificationContentsType == nil {
   802  		s.EmailNotificationContentsType = NewString(EMAIL_NOTIFICATION_CONTENTS_FULL)
   803  	}
   804  
   805  	if s.LoginButtonColor == nil {
   806  		s.LoginButtonColor = NewString("#0000")
   807  	}
   808  
   809  	if s.LoginButtonBorderColor == nil {
   810  		s.LoginButtonBorderColor = NewString("#2389D7")
   811  	}
   812  
   813  	if s.LoginButtonTextColor == nil {
   814  		s.LoginButtonTextColor = NewString("#2389D7")
   815  	}
   816  }
   817  
   818  type RateLimitSettings struct {
   819  	Enable           *bool
   820  	PerSec           *int
   821  	MaxBurst         *int
   822  	MemoryStoreSize  *int
   823  	VaryByRemoteAddr *bool
   824  	VaryByUser       *bool
   825  	VaryByHeader     string
   826  }
   827  
   828  func (s *RateLimitSettings) SetDefaults() {
   829  	if s.Enable == nil {
   830  		s.Enable = NewBool(false)
   831  	}
   832  
   833  	if s.PerSec == nil {
   834  		s.PerSec = NewInt(10)
   835  	}
   836  
   837  	if s.MaxBurst == nil {
   838  		s.MaxBurst = NewInt(100)
   839  	}
   840  
   841  	if s.MemoryStoreSize == nil {
   842  		s.MemoryStoreSize = NewInt(10000)
   843  	}
   844  
   845  	if s.VaryByRemoteAddr == nil {
   846  		s.VaryByRemoteAddr = NewBool(true)
   847  	}
   848  
   849  	if s.VaryByUser == nil {
   850  		s.VaryByUser = NewBool(false)
   851  	}
   852  }
   853  
   854  type PrivacySettings struct {
   855  	ShowEmailAddress bool
   856  	ShowFullName     bool
   857  }
   858  
   859  type SupportSettings struct {
   860  	TermsOfServiceLink *string
   861  	PrivacyPolicyLink  *string
   862  	AboutLink          *string
   863  	HelpLink           *string
   864  	ReportAProblemLink *string
   865  	SupportEmail       *string
   866  }
   867  
   868  func (s *SupportSettings) SetDefaults() {
   869  	if !IsSafeLink(s.TermsOfServiceLink) {
   870  		*s.TermsOfServiceLink = SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK
   871  	}
   872  
   873  	if s.TermsOfServiceLink == nil {
   874  		s.TermsOfServiceLink = NewString(SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK)
   875  	}
   876  
   877  	if !IsSafeLink(s.PrivacyPolicyLink) {
   878  		*s.PrivacyPolicyLink = ""
   879  	}
   880  
   881  	if s.PrivacyPolicyLink == nil {
   882  		s.PrivacyPolicyLink = NewString(SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK)
   883  	}
   884  
   885  	if !IsSafeLink(s.AboutLink) {
   886  		*s.AboutLink = ""
   887  	}
   888  
   889  	if s.AboutLink == nil {
   890  		s.AboutLink = NewString(SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK)
   891  	}
   892  
   893  	if !IsSafeLink(s.HelpLink) {
   894  		*s.HelpLink = ""
   895  	}
   896  
   897  	if s.HelpLink == nil {
   898  		s.HelpLink = NewString(SUPPORT_SETTINGS_DEFAULT_HELP_LINK)
   899  	}
   900  
   901  	if !IsSafeLink(s.ReportAProblemLink) {
   902  		*s.ReportAProblemLink = ""
   903  	}
   904  
   905  	if s.ReportAProblemLink == nil {
   906  		s.ReportAProblemLink = NewString(SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK)
   907  	}
   908  
   909  	if s.SupportEmail == nil {
   910  		s.SupportEmail = NewString(SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL)
   911  	}
   912  }
   913  
   914  type AnnouncementSettings struct {
   915  	EnableBanner         *bool
   916  	BannerText           *string
   917  	BannerColor          *string
   918  	BannerTextColor      *string
   919  	AllowBannerDismissal *bool
   920  }
   921  
   922  func (s *AnnouncementSettings) SetDefaults() {
   923  	if s.EnableBanner == nil {
   924  		s.EnableBanner = NewBool(false)
   925  	}
   926  
   927  	if s.BannerText == nil {
   928  		s.BannerText = NewString("")
   929  	}
   930  
   931  	if s.BannerColor == nil {
   932  		s.BannerColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR)
   933  	}
   934  
   935  	if s.BannerTextColor == nil {
   936  		s.BannerTextColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR)
   937  	}
   938  
   939  	if s.AllowBannerDismissal == nil {
   940  		s.AllowBannerDismissal = NewBool(true)
   941  	}
   942  }
   943  
   944  type ThemeSettings struct {
   945  	EnableThemeSelection *bool
   946  	DefaultTheme         *string
   947  	AllowCustomThemes    *bool
   948  	AllowedThemes        []string
   949  }
   950  
   951  func (s *ThemeSettings) SetDefaults() {
   952  	if s.EnableThemeSelection == nil {
   953  		s.EnableThemeSelection = NewBool(true)
   954  	}
   955  
   956  	if s.DefaultTheme == nil {
   957  		s.DefaultTheme = NewString(TEAM_SETTINGS_DEFAULT_TEAM_TEXT)
   958  	}
   959  
   960  	if s.AllowCustomThemes == nil {
   961  		s.AllowCustomThemes = NewBool(true)
   962  	}
   963  
   964  	if s.AllowedThemes == nil {
   965  		s.AllowedThemes = []string{}
   966  	}
   967  }
   968  
   969  type TeamSettings struct {
   970  	SiteName                            string
   971  	MaxUsersPerTeam                     *int
   972  	EnableTeamCreation                  *bool
   973  	EnableUserCreation                  bool
   974  	EnableOpenServer                    *bool
   975  	RestrictCreationToDomains           string
   976  	EnableCustomBrand                   *bool
   977  	CustomBrandText                     *string
   978  	CustomDescriptionText               *string
   979  	RestrictDirectMessage               *string
   980  	RestrictTeamInvite                  *string
   981  	RestrictPublicChannelManagement     *string
   982  	RestrictPrivateChannelManagement    *string
   983  	RestrictPublicChannelCreation       *string
   984  	RestrictPrivateChannelCreation      *string
   985  	RestrictPublicChannelDeletion       *string
   986  	RestrictPrivateChannelDeletion      *string
   987  	RestrictPrivateChannelManageMembers *string
   988  	EnableXToLeaveChannelsFromLHS       *bool
   989  	UserStatusAwayTimeout               *int64
   990  	MaxChannelsPerTeam                  *int64
   991  	MaxNotificationsPerChannel          *int64
   992  	EnableConfirmNotificationsToChannel *bool
   993  	TeammateNameDisplay                 *string
   994  	ExperimentalTownSquareIsReadOnly    *bool
   995  	ExperimentalPrimaryTeam             *string
   996  }
   997  
   998  func (s *TeamSettings) SetDefaults() {
   999  	if s.MaxUsersPerTeam == nil {
  1000  		s.MaxUsersPerTeam = NewInt(TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM)
  1001  	}
  1002  
  1003  	if s.EnableCustomBrand == nil {
  1004  		s.EnableCustomBrand = NewBool(false)
  1005  	}
  1006  
  1007  	if s.CustomBrandText == nil {
  1008  		s.CustomBrandText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT)
  1009  	}
  1010  
  1011  	if s.CustomDescriptionText == nil {
  1012  		s.CustomDescriptionText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT)
  1013  	}
  1014  
  1015  	if s.EnableOpenServer == nil {
  1016  		s.EnableOpenServer = NewBool(false)
  1017  	}
  1018  
  1019  	if s.RestrictDirectMessage == nil {
  1020  		s.RestrictDirectMessage = NewString(DIRECT_MESSAGE_ANY)
  1021  	}
  1022  
  1023  	if s.RestrictTeamInvite == nil {
  1024  		s.RestrictTeamInvite = NewString(PERMISSIONS_ALL)
  1025  	}
  1026  
  1027  	if s.RestrictPublicChannelManagement == nil {
  1028  		s.RestrictPublicChannelManagement = NewString(PERMISSIONS_ALL)
  1029  	}
  1030  
  1031  	if s.RestrictPrivateChannelManagement == nil {
  1032  		s.RestrictPrivateChannelManagement = NewString(PERMISSIONS_ALL)
  1033  	}
  1034  
  1035  	if s.RestrictPublicChannelCreation == nil {
  1036  		s.RestrictPublicChannelCreation = new(string)
  1037  		// If this setting does not exist, assume migration from <3.6, so use management setting as default.
  1038  		if *s.RestrictPublicChannelManagement == PERMISSIONS_CHANNEL_ADMIN {
  1039  			*s.RestrictPublicChannelCreation = PERMISSIONS_TEAM_ADMIN
  1040  		} else {
  1041  			*s.RestrictPublicChannelCreation = *s.RestrictPublicChannelManagement
  1042  		}
  1043  	}
  1044  
  1045  	if s.RestrictPrivateChannelCreation == nil {
  1046  		// If this setting does not exist, assume migration from <3.6, so use management setting as default.
  1047  		if *s.RestrictPrivateChannelManagement == PERMISSIONS_CHANNEL_ADMIN {
  1048  			s.RestrictPrivateChannelCreation = NewString(PERMISSIONS_TEAM_ADMIN)
  1049  		} else {
  1050  			s.RestrictPrivateChannelCreation = NewString(*s.RestrictPrivateChannelManagement)
  1051  		}
  1052  	}
  1053  
  1054  	if s.RestrictPublicChannelDeletion == nil {
  1055  		// If this setting does not exist, assume migration from <3.6, so use management setting as default.
  1056  		s.RestrictPublicChannelDeletion = NewString(*s.RestrictPublicChannelManagement)
  1057  	}
  1058  
  1059  	if s.RestrictPrivateChannelDeletion == nil {
  1060  		// If this setting does not exist, assume migration from <3.6, so use management setting as default.
  1061  		s.RestrictPrivateChannelDeletion = NewString(*s.RestrictPrivateChannelManagement)
  1062  	}
  1063  
  1064  	if s.RestrictPrivateChannelManageMembers == nil {
  1065  		s.RestrictPrivateChannelManageMembers = NewString(PERMISSIONS_ALL)
  1066  	}
  1067  
  1068  	if s.EnableXToLeaveChannelsFromLHS == nil {
  1069  		s.EnableXToLeaveChannelsFromLHS = NewBool(false)
  1070  	}
  1071  
  1072  	if s.UserStatusAwayTimeout == nil {
  1073  		s.UserStatusAwayTimeout = NewInt64(TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT)
  1074  	}
  1075  
  1076  	if s.MaxChannelsPerTeam == nil {
  1077  		s.MaxChannelsPerTeam = NewInt64(2000)
  1078  	}
  1079  
  1080  	if s.MaxNotificationsPerChannel == nil {
  1081  		s.MaxNotificationsPerChannel = NewInt64(1000)
  1082  	}
  1083  
  1084  	if s.EnableConfirmNotificationsToChannel == nil {
  1085  		s.EnableConfirmNotificationsToChannel = NewBool(true)
  1086  	}
  1087  
  1088  	if s.ExperimentalTownSquareIsReadOnly == nil {
  1089  		s.ExperimentalTownSquareIsReadOnly = NewBool(false)
  1090  	}
  1091  
  1092  	if s.ExperimentalPrimaryTeam == nil {
  1093  		s.ExperimentalPrimaryTeam = NewString("")
  1094  	}
  1095  
  1096  	if s.EnableTeamCreation == nil {
  1097  		s.EnableTeamCreation = NewBool(true)
  1098  	}
  1099  }
  1100  
  1101  type ClientRequirements struct {
  1102  	AndroidLatestVersion string
  1103  	AndroidMinVersion    string
  1104  	DesktopLatestVersion string
  1105  	DesktopMinVersion    string
  1106  	IosLatestVersion     string
  1107  	IosMinVersion        string
  1108  }
  1109  
  1110  type LdapSettings struct {
  1111  	// Basic
  1112  	Enable             *bool
  1113  	EnableSync         *bool
  1114  	LdapServer         *string
  1115  	LdapPort           *int
  1116  	ConnectionSecurity *string
  1117  	BaseDN             *string
  1118  	BindUsername       *string
  1119  	BindPassword       *string
  1120  
  1121  	// Filtering
  1122  	UserFilter *string
  1123  
  1124  	// User Mapping
  1125  	FirstNameAttribute *string
  1126  	LastNameAttribute  *string
  1127  	EmailAttribute     *string
  1128  	UsernameAttribute  *string
  1129  	NicknameAttribute  *string
  1130  	IdAttribute        *string
  1131  	PositionAttribute  *string
  1132  
  1133  	// Synchronization
  1134  	SyncIntervalMinutes *int
  1135  
  1136  	// Advanced
  1137  	SkipCertificateVerification *bool
  1138  	QueryTimeout                *int
  1139  	MaxPageSize                 *int
  1140  
  1141  	// Customization
  1142  	LoginFieldName *string
  1143  
  1144  	LoginButtonColor       *string
  1145  	LoginButtonBorderColor *string
  1146  	LoginButtonTextColor   *string
  1147  }
  1148  
  1149  func (s *LdapSettings) SetDefaults() {
  1150  	if s.Enable == nil {
  1151  		s.Enable = NewBool(false)
  1152  	}
  1153  
  1154  	// When unset should default to LDAP Enabled
  1155  	if s.EnableSync == nil {
  1156  		s.EnableSync = NewBool(*s.Enable)
  1157  	}
  1158  
  1159  	if s.LdapServer == nil {
  1160  		s.LdapServer = NewString("")
  1161  	}
  1162  
  1163  	if s.LdapPort == nil {
  1164  		s.LdapPort = NewInt(389)
  1165  	}
  1166  
  1167  	if s.ConnectionSecurity == nil {
  1168  		s.ConnectionSecurity = NewString("")
  1169  	}
  1170  
  1171  	if s.BaseDN == nil {
  1172  		s.BaseDN = NewString("")
  1173  	}
  1174  
  1175  	if s.BindUsername == nil {
  1176  		s.BindUsername = NewString("")
  1177  	}
  1178  
  1179  	if s.BindPassword == nil {
  1180  		s.BindPassword = NewString("")
  1181  	}
  1182  
  1183  	if s.UserFilter == nil {
  1184  		s.UserFilter = NewString("")
  1185  	}
  1186  
  1187  	if s.FirstNameAttribute == nil {
  1188  		s.FirstNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE)
  1189  	}
  1190  
  1191  	if s.LastNameAttribute == nil {
  1192  		s.LastNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE)
  1193  	}
  1194  
  1195  	if s.EmailAttribute == nil {
  1196  		s.EmailAttribute = NewString(LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE)
  1197  	}
  1198  
  1199  	if s.UsernameAttribute == nil {
  1200  		s.UsernameAttribute = NewString(LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE)
  1201  	}
  1202  
  1203  	if s.NicknameAttribute == nil {
  1204  		s.NicknameAttribute = NewString(LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE)
  1205  	}
  1206  
  1207  	if s.IdAttribute == nil {
  1208  		s.IdAttribute = NewString(LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE)
  1209  	}
  1210  
  1211  	if s.PositionAttribute == nil {
  1212  		s.PositionAttribute = NewString(LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE)
  1213  	}
  1214  
  1215  	if s.SyncIntervalMinutes == nil {
  1216  		s.SyncIntervalMinutes = NewInt(60)
  1217  	}
  1218  
  1219  	if s.SkipCertificateVerification == nil {
  1220  		s.SkipCertificateVerification = NewBool(false)
  1221  	}
  1222  
  1223  	if s.QueryTimeout == nil {
  1224  		s.QueryTimeout = NewInt(60)
  1225  	}
  1226  
  1227  	if s.MaxPageSize == nil {
  1228  		s.MaxPageSize = NewInt(0)
  1229  	}
  1230  
  1231  	if s.LoginFieldName == nil {
  1232  		s.LoginFieldName = NewString(LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME)
  1233  	}
  1234  
  1235  	if s.LoginButtonColor == nil {
  1236  		s.LoginButtonColor = NewString("#0000")
  1237  	}
  1238  
  1239  	if s.LoginButtonBorderColor == nil {
  1240  		s.LoginButtonBorderColor = NewString("#2389D7")
  1241  	}
  1242  
  1243  	if s.LoginButtonTextColor == nil {
  1244  		s.LoginButtonTextColor = NewString("#2389D7")
  1245  	}
  1246  }
  1247  
  1248  type ComplianceSettings struct {
  1249  	Enable      *bool
  1250  	Directory   *string
  1251  	EnableDaily *bool
  1252  }
  1253  
  1254  func (s *ComplianceSettings) SetDefaults() {
  1255  	if s.Enable == nil {
  1256  		s.Enable = NewBool(false)
  1257  	}
  1258  
  1259  	if s.Directory == nil {
  1260  		s.Directory = NewString("./data/")
  1261  	}
  1262  
  1263  	if s.EnableDaily == nil {
  1264  		s.EnableDaily = NewBool(false)
  1265  	}
  1266  }
  1267  
  1268  type LocalizationSettings struct {
  1269  	DefaultServerLocale *string
  1270  	DefaultClientLocale *string
  1271  	AvailableLocales    *string
  1272  }
  1273  
  1274  func (s *LocalizationSettings) SetDefaults() {
  1275  	if s.DefaultServerLocale == nil {
  1276  		s.DefaultServerLocale = NewString(DEFAULT_LOCALE)
  1277  	}
  1278  
  1279  	if s.DefaultClientLocale == nil {
  1280  		s.DefaultClientLocale = NewString(DEFAULT_LOCALE)
  1281  	}
  1282  
  1283  	if s.AvailableLocales == nil {
  1284  		s.AvailableLocales = NewString("")
  1285  	}
  1286  }
  1287  
  1288  type SamlSettings struct {
  1289  	// Basic
  1290  	Enable             *bool
  1291  	EnableSyncWithLdap *bool
  1292  
  1293  	Verify  *bool
  1294  	Encrypt *bool
  1295  
  1296  	IdpUrl                      *string
  1297  	IdpDescriptorUrl            *string
  1298  	AssertionConsumerServiceURL *string
  1299  
  1300  	ScopingIDPProviderId *string
  1301  	ScopingIDPName       *string
  1302  
  1303  	IdpCertificateFile    *string
  1304  	PublicCertificateFile *string
  1305  	PrivateKeyFile        *string
  1306  
  1307  	// User Mapping
  1308  	FirstNameAttribute *string
  1309  	LastNameAttribute  *string
  1310  	EmailAttribute     *string
  1311  	UsernameAttribute  *string
  1312  	NicknameAttribute  *string
  1313  	LocaleAttribute    *string
  1314  	PositionAttribute  *string
  1315  
  1316  	LoginButtonText *string
  1317  
  1318  	LoginButtonColor       *string
  1319  	LoginButtonBorderColor *string
  1320  	LoginButtonTextColor   *string
  1321  }
  1322  
  1323  func (s *SamlSettings) SetDefaults() {
  1324  	if s.Enable == nil {
  1325  		s.Enable = NewBool(false)
  1326  	}
  1327  
  1328  	if s.EnableSyncWithLdap == nil {
  1329  		s.EnableSyncWithLdap = NewBool(false)
  1330  	}
  1331  
  1332  	if s.Verify == nil {
  1333  		s.Verify = NewBool(true)
  1334  	}
  1335  
  1336  	if s.Encrypt == nil {
  1337  		s.Encrypt = NewBool(true)
  1338  	}
  1339  
  1340  	if s.IdpUrl == nil {
  1341  		s.IdpUrl = NewString("")
  1342  	}
  1343  
  1344  	if s.IdpDescriptorUrl == nil {
  1345  		s.IdpDescriptorUrl = NewString("")
  1346  	}
  1347  
  1348  	if s.IdpCertificateFile == nil {
  1349  		s.IdpCertificateFile = NewString("")
  1350  	}
  1351  
  1352  	if s.PublicCertificateFile == nil {
  1353  		s.PublicCertificateFile = NewString("")
  1354  	}
  1355  
  1356  	if s.PrivateKeyFile == nil {
  1357  		s.PrivateKeyFile = NewString("")
  1358  	}
  1359  
  1360  	if s.AssertionConsumerServiceURL == nil {
  1361  		s.AssertionConsumerServiceURL = NewString("")
  1362  	}
  1363  
  1364  	if s.ScopingIDPProviderId == nil {
  1365  		s.ScopingIDPProviderId = NewString("")
  1366  	}
  1367  
  1368  	if s.ScopingIDPName == nil {
  1369  		s.ScopingIDPName = NewString("")
  1370  	}
  1371  
  1372  	if s.LoginButtonText == nil || *s.LoginButtonText == "" {
  1373  		s.LoginButtonText = NewString(USER_AUTH_SERVICE_SAML_TEXT)
  1374  	}
  1375  
  1376  	if s.FirstNameAttribute == nil {
  1377  		s.FirstNameAttribute = NewString(SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE)
  1378  	}
  1379  
  1380  	if s.LastNameAttribute == nil {
  1381  		s.LastNameAttribute = NewString(SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE)
  1382  	}
  1383  
  1384  	if s.EmailAttribute == nil {
  1385  		s.EmailAttribute = NewString(SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE)
  1386  	}
  1387  
  1388  	if s.UsernameAttribute == nil {
  1389  		s.UsernameAttribute = NewString(SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE)
  1390  	}
  1391  
  1392  	if s.NicknameAttribute == nil {
  1393  		s.NicknameAttribute = NewString(SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE)
  1394  	}
  1395  
  1396  	if s.PositionAttribute == nil {
  1397  		s.PositionAttribute = NewString(SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE)
  1398  	}
  1399  
  1400  	if s.LocaleAttribute == nil {
  1401  		s.LocaleAttribute = NewString(SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE)
  1402  	}
  1403  
  1404  	if s.LoginButtonColor == nil {
  1405  		s.LoginButtonColor = NewString("#34a28b")
  1406  	}
  1407  
  1408  	if s.LoginButtonBorderColor == nil {
  1409  		s.LoginButtonBorderColor = NewString("#2389D7")
  1410  	}
  1411  
  1412  	if s.LoginButtonTextColor == nil {
  1413  		s.LoginButtonTextColor = NewString("#ffffff")
  1414  	}
  1415  }
  1416  
  1417  type NativeAppSettings struct {
  1418  	AppDownloadLink        *string
  1419  	AndroidAppDownloadLink *string
  1420  	IosAppDownloadLink     *string
  1421  }
  1422  
  1423  func (s *NativeAppSettings) SetDefaults() {
  1424  	if s.AppDownloadLink == nil {
  1425  		s.AppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK)
  1426  	}
  1427  
  1428  	if s.AndroidAppDownloadLink == nil {
  1429  		s.AndroidAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK)
  1430  	}
  1431  
  1432  	if s.IosAppDownloadLink == nil {
  1433  		s.IosAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK)
  1434  	}
  1435  }
  1436  
  1437  type WebrtcSettings struct {
  1438  	Enable              *bool
  1439  	GatewayWebsocketUrl *string
  1440  	GatewayAdminUrl     *string
  1441  	GatewayAdminSecret  *string
  1442  	StunURI             *string
  1443  	TurnURI             *string
  1444  	TurnUsername        *string
  1445  	TurnSharedKey       *string
  1446  }
  1447  
  1448  func (s *WebrtcSettings) SetDefaults() {
  1449  	if s.Enable == nil {
  1450  		s.Enable = NewBool(false)
  1451  	}
  1452  
  1453  	if s.GatewayWebsocketUrl == nil {
  1454  		s.GatewayWebsocketUrl = NewString("")
  1455  	}
  1456  
  1457  	if s.GatewayAdminUrl == nil {
  1458  		s.GatewayAdminUrl = NewString("")
  1459  	}
  1460  
  1461  	if s.GatewayAdminSecret == nil {
  1462  		s.GatewayAdminSecret = NewString("")
  1463  	}
  1464  
  1465  	if s.StunURI == nil {
  1466  		s.StunURI = NewString(WEBRTC_SETTINGS_DEFAULT_STUN_URI)
  1467  	}
  1468  
  1469  	if s.TurnURI == nil {
  1470  		s.TurnURI = NewString(WEBRTC_SETTINGS_DEFAULT_TURN_URI)
  1471  	}
  1472  
  1473  	if s.TurnUsername == nil {
  1474  		s.TurnUsername = NewString("")
  1475  	}
  1476  
  1477  	if s.TurnSharedKey == nil {
  1478  		s.TurnSharedKey = NewString("")
  1479  	}
  1480  }
  1481  
  1482  type ElasticsearchSettings struct {
  1483  	ConnectionUrl                 *string
  1484  	Username                      *string
  1485  	Password                      *string
  1486  	EnableIndexing                *bool
  1487  	EnableSearching               *bool
  1488  	Sniff                         *bool
  1489  	PostIndexReplicas             *int
  1490  	PostIndexShards               *int
  1491  	AggregatePostsAfterDays       *int
  1492  	PostsAggregatorJobStartTime   *string
  1493  	IndexPrefix                   *string
  1494  	LiveIndexingBatchSize         *int
  1495  	BulkIndexingTimeWindowSeconds *int
  1496  	RequestTimeoutSeconds         *int
  1497  }
  1498  
  1499  func (s *ElasticsearchSettings) SetDefaults() {
  1500  	if s.ConnectionUrl == nil {
  1501  		s.ConnectionUrl = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL)
  1502  	}
  1503  
  1504  	if s.Username == nil {
  1505  		s.Username = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME)
  1506  	}
  1507  
  1508  	if s.Password == nil {
  1509  		s.Password = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD)
  1510  	}
  1511  
  1512  	if s.EnableIndexing == nil {
  1513  		s.EnableIndexing = NewBool(false)
  1514  	}
  1515  
  1516  	if s.EnableSearching == nil {
  1517  		s.EnableSearching = NewBool(false)
  1518  	}
  1519  
  1520  	if s.Sniff == nil {
  1521  		s.Sniff = NewBool(true)
  1522  	}
  1523  
  1524  	if s.PostIndexReplicas == nil {
  1525  		s.PostIndexReplicas = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS)
  1526  	}
  1527  
  1528  	if s.PostIndexShards == nil {
  1529  		s.PostIndexShards = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS)
  1530  	}
  1531  
  1532  	if s.AggregatePostsAfterDays == nil {
  1533  		s.AggregatePostsAfterDays = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS)
  1534  	}
  1535  
  1536  	if s.PostsAggregatorJobStartTime == nil {
  1537  		s.PostsAggregatorJobStartTime = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME)
  1538  	}
  1539  
  1540  	if s.IndexPrefix == nil {
  1541  		s.IndexPrefix = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX)
  1542  	}
  1543  
  1544  	if s.LiveIndexingBatchSize == nil {
  1545  		s.LiveIndexingBatchSize = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE)
  1546  	}
  1547  
  1548  	if s.BulkIndexingTimeWindowSeconds == nil {
  1549  		s.BulkIndexingTimeWindowSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS)
  1550  	}
  1551  
  1552  	if s.RequestTimeoutSeconds == nil {
  1553  		s.RequestTimeoutSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS)
  1554  	}
  1555  }
  1556  
  1557  type DataRetentionSettings struct {
  1558  	EnableMessageDeletion *bool
  1559  	EnableFileDeletion    *bool
  1560  	MessageRetentionDays  *int
  1561  	FileRetentionDays     *int
  1562  	DeletionJobStartTime  *string
  1563  }
  1564  
  1565  func (s *DataRetentionSettings) SetDefaults() {
  1566  	if s.EnableMessageDeletion == nil {
  1567  		s.EnableMessageDeletion = NewBool(false)
  1568  	}
  1569  
  1570  	if s.EnableFileDeletion == nil {
  1571  		s.EnableFileDeletion = NewBool(false)
  1572  	}
  1573  
  1574  	if s.MessageRetentionDays == nil {
  1575  		s.MessageRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS)
  1576  	}
  1577  
  1578  	if s.FileRetentionDays == nil {
  1579  		s.FileRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS)
  1580  	}
  1581  
  1582  	if s.DeletionJobStartTime == nil {
  1583  		s.DeletionJobStartTime = NewString(DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME)
  1584  	}
  1585  }
  1586  
  1587  type JobSettings struct {
  1588  	RunJobs      *bool
  1589  	RunScheduler *bool
  1590  }
  1591  
  1592  func (s *JobSettings) SetDefaults() {
  1593  	if s.RunJobs == nil {
  1594  		s.RunJobs = NewBool(true)
  1595  	}
  1596  
  1597  	if s.RunScheduler == nil {
  1598  		s.RunScheduler = NewBool(true)
  1599  	}
  1600  }
  1601  
  1602  type PluginState struct {
  1603  	Enable bool
  1604  }
  1605  
  1606  type PluginSettings struct {
  1607  	Enable          *bool
  1608  	EnableUploads   *bool
  1609  	Directory       *string
  1610  	ClientDirectory *string
  1611  	Plugins         map[string]interface{}
  1612  	PluginStates    map[string]*PluginState
  1613  }
  1614  
  1615  func (s *PluginSettings) SetDefaults() {
  1616  	if s.Enable == nil {
  1617  		s.Enable = NewBool(true)
  1618  	}
  1619  
  1620  	if s.EnableUploads == nil {
  1621  		s.EnableUploads = NewBool(false)
  1622  	}
  1623  
  1624  	if s.Directory == nil {
  1625  		s.Directory = NewString(PLUGIN_SETTINGS_DEFAULT_DIRECTORY)
  1626  	}
  1627  
  1628  	if *s.Directory == "" {
  1629  		*s.Directory = PLUGIN_SETTINGS_DEFAULT_DIRECTORY
  1630  	}
  1631  
  1632  	if s.ClientDirectory == nil {
  1633  		s.ClientDirectory = NewString(PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY)
  1634  	}
  1635  
  1636  	if *s.ClientDirectory == "" {
  1637  		*s.ClientDirectory = PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY
  1638  	}
  1639  
  1640  	if s.Plugins == nil {
  1641  		s.Plugins = make(map[string]interface{})
  1642  	}
  1643  
  1644  	if s.PluginStates == nil {
  1645  		s.PluginStates = make(map[string]*PluginState)
  1646  	}
  1647  }
  1648  
  1649  type GlobalRelayMessageExportSettings struct {
  1650  	CustomerType *string // must be either A9 or A10, dictates SMTP server url
  1651  	SmtpUsername *string
  1652  	SmtpPassword *string
  1653  	EmailAddress *string // the address to send messages to
  1654  }
  1655  
  1656  func (s *GlobalRelayMessageExportSettings) SetDefaults() {
  1657  	if s.CustomerType == nil {
  1658  		s.CustomerType = NewString(GLOBALRELAY_CUSTOMER_TYPE_A9)
  1659  	}
  1660  	if s.SmtpUsername == nil {
  1661  		s.SmtpUsername = NewString("")
  1662  	}
  1663  	if s.SmtpPassword == nil {
  1664  		s.SmtpPassword = NewString("")
  1665  	}
  1666  	if s.EmailAddress == nil {
  1667  		s.EmailAddress = NewString("")
  1668  	}
  1669  }
  1670  
  1671  type MessageExportSettings struct {
  1672  	EnableExport        *bool
  1673  	ExportFormat        *string
  1674  	DailyRunTime        *string
  1675  	ExportFromTimestamp *int64
  1676  	BatchSize           *int
  1677  
  1678  	// formatter-specific settings - these are only expected to be non-nil if ExportFormat is set to the associated format
  1679  	GlobalRelaySettings *GlobalRelayMessageExportSettings
  1680  }
  1681  
  1682  func (s *MessageExportSettings) SetDefaults() {
  1683  	if s.EnableExport == nil {
  1684  		s.EnableExport = NewBool(false)
  1685  	}
  1686  
  1687  	if s.ExportFormat == nil {
  1688  		s.ExportFormat = NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE)
  1689  	}
  1690  
  1691  	if s.DailyRunTime == nil {
  1692  		s.DailyRunTime = NewString("01:00")
  1693  	}
  1694  
  1695  	if s.ExportFromTimestamp == nil {
  1696  		s.ExportFromTimestamp = NewInt64(0)
  1697  	}
  1698  
  1699  	if s.EnableExport != nil && *s.EnableExport && *s.ExportFromTimestamp == int64(0) {
  1700  		// when the feature is enabled via the System Console, use the current timestamp as the start time for future exports
  1701  		s.ExportFromTimestamp = NewInt64(GetMillis())
  1702  	} else if s.EnableExport != nil && !*s.EnableExport {
  1703  		// when the feature is disabled, reset the timestamp so that the timestamp will be set if the feature is re-enabled
  1704  		s.ExportFromTimestamp = NewInt64(0)
  1705  	}
  1706  
  1707  	if s.BatchSize == nil {
  1708  		s.BatchSize = NewInt(10000)
  1709  	}
  1710  
  1711  	if s.GlobalRelaySettings == nil {
  1712  		s.GlobalRelaySettings = &GlobalRelayMessageExportSettings{}
  1713  		s.GlobalRelaySettings.SetDefaults()
  1714  	}
  1715  }
  1716  
  1717  type DisplaySettings struct {
  1718  	ExperimentalTimezone *bool
  1719  }
  1720  
  1721  func (s *DisplaySettings) SetDefaults() {
  1722  	if s.ExperimentalTimezone == nil {
  1723  		s.ExperimentalTimezone = NewBool(false)
  1724  	}
  1725  }
  1726  
  1727  type TimezoneSettings struct {
  1728  	SupportedTimezonesPath *string
  1729  }
  1730  
  1731  func (s *TimezoneSettings) SetDefaults() {
  1732  	if s.SupportedTimezonesPath == nil {
  1733  		s.SupportedTimezonesPath = NewString(TIMEZONE_SETTINGS_DEFAULT_SUPPORTED_TIMEZONES_PATH)
  1734  	}
  1735  }
  1736  
  1737  type ConfigFunc func() *Config
  1738  
  1739  type Config struct {
  1740  	ServiceSettings       ServiceSettings
  1741  	TeamSettings          TeamSettings
  1742  	ClientRequirements    ClientRequirements
  1743  	SqlSettings           SqlSettings
  1744  	LogSettings           LogSettings
  1745  	PasswordSettings      PasswordSettings
  1746  	FileSettings          FileSettings
  1747  	EmailSettings         EmailSettings
  1748  	RateLimitSettings     RateLimitSettings
  1749  	PrivacySettings       PrivacySettings
  1750  	SupportSettings       SupportSettings
  1751  	AnnouncementSettings  AnnouncementSettings
  1752  	ThemeSettings         ThemeSettings
  1753  	GitLabSettings        SSOSettings
  1754  	GoogleSettings        SSOSettings
  1755  	Office365Settings     SSOSettings
  1756  	LdapSettings          LdapSettings
  1757  	ComplianceSettings    ComplianceSettings
  1758  	LocalizationSettings  LocalizationSettings
  1759  	SamlSettings          SamlSettings
  1760  	NativeAppSettings     NativeAppSettings
  1761  	ClusterSettings       ClusterSettings
  1762  	MetricsSettings       MetricsSettings
  1763  	AnalyticsSettings     AnalyticsSettings
  1764  	WebrtcSettings        WebrtcSettings
  1765  	ElasticsearchSettings ElasticsearchSettings
  1766  	DataRetentionSettings DataRetentionSettings
  1767  	MessageExportSettings MessageExportSettings
  1768  	JobSettings           JobSettings
  1769  	PluginSettings        PluginSettings
  1770  	DisplaySettings       DisplaySettings
  1771  	TimezoneSettings      TimezoneSettings
  1772  }
  1773  
  1774  func (o *Config) Clone() *Config {
  1775  	var ret Config
  1776  	if err := json.Unmarshal([]byte(o.ToJson()), &ret); err != nil {
  1777  		panic(err)
  1778  	}
  1779  	return &ret
  1780  }
  1781  
  1782  func (o *Config) ToJson() string {
  1783  	b, _ := json.Marshal(o)
  1784  	return string(b)
  1785  }
  1786  
  1787  func (o *Config) GetSSOService(service string) *SSOSettings {
  1788  	switch service {
  1789  	case SERVICE_GITLAB:
  1790  		return &o.GitLabSettings
  1791  	case SERVICE_GOOGLE:
  1792  		return &o.GoogleSettings
  1793  	case SERVICE_OFFICE365:
  1794  		return &o.Office365Settings
  1795  	}
  1796  
  1797  	return nil
  1798  }
  1799  
  1800  func ConfigFromJson(data io.Reader) *Config {
  1801  	var o *Config
  1802  	json.NewDecoder(data).Decode(&o)
  1803  	return o
  1804  }
  1805  
  1806  func (o *Config) SetDefaults() {
  1807  	o.LdapSettings.SetDefaults()
  1808  	o.SamlSettings.SetDefaults()
  1809  
  1810  	if o.TeamSettings.TeammateNameDisplay == nil {
  1811  		o.TeamSettings.TeammateNameDisplay = NewString(SHOW_USERNAME)
  1812  
  1813  		if *o.SamlSettings.Enable || *o.LdapSettings.Enable {
  1814  			*o.TeamSettings.TeammateNameDisplay = SHOW_FULLNAME
  1815  		}
  1816  	}
  1817  
  1818  	o.SqlSettings.SetDefaults()
  1819  	o.FileSettings.SetDefaults()
  1820  	o.EmailSettings.SetDefaults()
  1821  	o.ServiceSettings.SetDefaults()
  1822  	o.PasswordSettings.SetDefaults()
  1823  	o.TeamSettings.SetDefaults()
  1824  	o.MetricsSettings.SetDefaults()
  1825  	o.SupportSettings.SetDefaults()
  1826  	o.AnnouncementSettings.SetDefaults()
  1827  	o.ThemeSettings.SetDefaults()
  1828  	o.ClusterSettings.SetDefaults()
  1829  	o.PluginSettings.SetDefaults()
  1830  	o.AnalyticsSettings.SetDefaults()
  1831  	o.ComplianceSettings.SetDefaults()
  1832  	o.LocalizationSettings.SetDefaults()
  1833  	o.ElasticsearchSettings.SetDefaults()
  1834  	o.NativeAppSettings.SetDefaults()
  1835  	o.DataRetentionSettings.SetDefaults()
  1836  	o.RateLimitSettings.SetDefaults()
  1837  	o.LogSettings.SetDefaults()
  1838  	o.JobSettings.SetDefaults()
  1839  	o.WebrtcSettings.SetDefaults()
  1840  	o.MessageExportSettings.SetDefaults()
  1841  	o.TimezoneSettings.SetDefaults()
  1842  	o.DisplaySettings.SetDefaults()
  1843  }
  1844  
  1845  func (o *Config) IsValid() *AppError {
  1846  	if len(*o.ServiceSettings.SiteURL) == 0 && *o.EmailSettings.EnableEmailBatching {
  1847  		return NewAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "", http.StatusBadRequest)
  1848  	}
  1849  
  1850  	if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching {
  1851  		return NewAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "", http.StatusBadRequest)
  1852  	}
  1853  
  1854  	if len(*o.ServiceSettings.SiteURL) == 0 && *o.ServiceSettings.AllowCookiesForSubdomains {
  1855  		return NewAppError("Config.IsValid", "Allowing cookies for subdomains requires SiteURL to be set.", nil, "", http.StatusBadRequest)
  1856  	}
  1857  
  1858  	if err := o.TeamSettings.isValid(); err != nil {
  1859  		return err
  1860  	}
  1861  
  1862  	if err := o.SqlSettings.isValid(); err != nil {
  1863  		return err
  1864  	}
  1865  
  1866  	if err := o.FileSettings.isValid(); err != nil {
  1867  		return err
  1868  	}
  1869  
  1870  	if err := o.EmailSettings.isValid(); err != nil {
  1871  		return err
  1872  	}
  1873  
  1874  	if err := o.LdapSettings.isValid(); err != nil {
  1875  		return err
  1876  	}
  1877  
  1878  	if err := o.SamlSettings.isValid(); err != nil {
  1879  		return err
  1880  	}
  1881  
  1882  	if *o.PasswordSettings.MinimumLength < PASSWORD_MINIMUM_LENGTH || *o.PasswordSettings.MinimumLength > PASSWORD_MAXIMUM_LENGTH {
  1883  		return NewAppError("Config.IsValid", "model.config.is_valid.password_length.app_error", map[string]interface{}{"MinLength": PASSWORD_MINIMUM_LENGTH, "MaxLength": PASSWORD_MAXIMUM_LENGTH}, "", http.StatusBadRequest)
  1884  	}
  1885  
  1886  	if err := o.RateLimitSettings.isValid(); err != nil {
  1887  		return err
  1888  	}
  1889  
  1890  	if err := o.WebrtcSettings.isValid(); err != nil {
  1891  		return err
  1892  	}
  1893  
  1894  	if err := o.ServiceSettings.isValid(); err != nil {
  1895  		return err
  1896  	}
  1897  
  1898  	if err := o.ElasticsearchSettings.isValid(); err != nil {
  1899  		return err
  1900  	}
  1901  
  1902  	if err := o.DataRetentionSettings.isValid(); err != nil {
  1903  		return err
  1904  	}
  1905  
  1906  	if err := o.LocalizationSettings.isValid(); err != nil {
  1907  		return err
  1908  	}
  1909  
  1910  	if err := o.MessageExportSettings.isValid(o.FileSettings); err != nil {
  1911  		return err
  1912  	}
  1913  
  1914  	return nil
  1915  }
  1916  
  1917  func (ts *TeamSettings) isValid() *AppError {
  1918  	if *ts.MaxUsersPerTeam <= 0 {
  1919  		return NewAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "", http.StatusBadRequest)
  1920  	}
  1921  
  1922  	if *ts.MaxChannelsPerTeam <= 0 {
  1923  		return NewAppError("Config.IsValid", "model.config.is_valid.max_channels.app_error", nil, "", http.StatusBadRequest)
  1924  	}
  1925  
  1926  	if *ts.MaxNotificationsPerChannel <= 0 {
  1927  		return NewAppError("Config.IsValid", "model.config.is_valid.max_notify_per_channel.app_error", nil, "", http.StatusBadRequest)
  1928  	}
  1929  
  1930  	if !(*ts.RestrictDirectMessage == DIRECT_MESSAGE_ANY || *ts.RestrictDirectMessage == DIRECT_MESSAGE_TEAM) {
  1931  		return NewAppError("Config.IsValid", "model.config.is_valid.restrict_direct_message.app_error", nil, "", http.StatusBadRequest)
  1932  	}
  1933  
  1934  	if !(*ts.TeammateNameDisplay == SHOW_FULLNAME || *ts.TeammateNameDisplay == SHOW_NICKNAME_FULLNAME || *ts.TeammateNameDisplay == SHOW_USERNAME) {
  1935  		return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest)
  1936  	}
  1937  
  1938  	if len(ts.SiteName) > SITENAME_MAX_LENGTH {
  1939  		return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest)
  1940  	}
  1941  
  1942  	return nil
  1943  }
  1944  
  1945  func (ss *SqlSettings) isValid() *AppError {
  1946  	if len(ss.AtRestEncryptKey) < 32 {
  1947  		return NewAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "", http.StatusBadRequest)
  1948  	}
  1949  
  1950  	if !(*ss.DriverName == DATABASE_DRIVER_MYSQL || *ss.DriverName == DATABASE_DRIVER_POSTGRES) {
  1951  		return NewAppError("Config.IsValid", "model.config.is_valid.sql_driver.app_error", nil, "", http.StatusBadRequest)
  1952  	}
  1953  
  1954  	if *ss.MaxIdleConns <= 0 {
  1955  		return NewAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "", http.StatusBadRequest)
  1956  	}
  1957  
  1958  	if *ss.QueryTimeout <= 0 {
  1959  		return NewAppError("Config.IsValid", "model.config.is_valid.sql_query_timeout.app_error", nil, "", http.StatusBadRequest)
  1960  	}
  1961  
  1962  	if len(*ss.DataSource) == 0 {
  1963  		return NewAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "", http.StatusBadRequest)
  1964  	}
  1965  
  1966  	if *ss.MaxOpenConns <= 0 {
  1967  		return NewAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "", http.StatusBadRequest)
  1968  	}
  1969  
  1970  	return nil
  1971  }
  1972  
  1973  func (fs *FileSettings) isValid() *AppError {
  1974  	if *fs.MaxFileSize <= 0 {
  1975  		return NewAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "", http.StatusBadRequest)
  1976  	}
  1977  
  1978  	if !(*fs.DriverName == IMAGE_DRIVER_LOCAL || *fs.DriverName == IMAGE_DRIVER_S3) {
  1979  		return NewAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "", http.StatusBadRequest)
  1980  	}
  1981  
  1982  	if len(*fs.PublicLinkSalt) < 32 {
  1983  		return NewAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "", http.StatusBadRequest)
  1984  	}
  1985  
  1986  	return nil
  1987  }
  1988  
  1989  func (es *EmailSettings) isValid() *AppError {
  1990  	if !(es.ConnectionSecurity == CONN_SECURITY_NONE || es.ConnectionSecurity == CONN_SECURITY_TLS || es.ConnectionSecurity == CONN_SECURITY_STARTTLS || es.ConnectionSecurity == CONN_SECURITY_PLAIN) {
  1991  		return NewAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "", http.StatusBadRequest)
  1992  	}
  1993  
  1994  	if len(es.InviteSalt) < 32 {
  1995  		return NewAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "", http.StatusBadRequest)
  1996  	}
  1997  
  1998  	if *es.EmailBatchingBufferSize <= 0 {
  1999  		return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_buffer_size.app_error", nil, "", http.StatusBadRequest)
  2000  	}
  2001  
  2002  	if *es.EmailBatchingInterval < 30 {
  2003  		return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_interval.app_error", nil, "", http.StatusBadRequest)
  2004  	}
  2005  
  2006  	if !(*es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_FULL || *es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_GENERIC) {
  2007  		return NewAppError("Config.IsValid", "model.config.is_valid.email_notification_contents_type.app_error", nil, "", http.StatusBadRequest)
  2008  	}
  2009  
  2010  	return nil
  2011  }
  2012  
  2013  func (rls *RateLimitSettings) isValid() *AppError {
  2014  	if *rls.MemoryStoreSize <= 0 {
  2015  		return NewAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "", http.StatusBadRequest)
  2016  	}
  2017  
  2018  	if *rls.PerSec <= 0 {
  2019  		return NewAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "", http.StatusBadRequest)
  2020  	}
  2021  
  2022  	if *rls.MaxBurst <= 0 {
  2023  		return NewAppError("Config.IsValid", "model.config.is_valid.max_burst.app_error", nil, "", http.StatusBadRequest)
  2024  	}
  2025  
  2026  	return nil
  2027  }
  2028  
  2029  func (ls *LdapSettings) isValid() *AppError {
  2030  	if !(*ls.ConnectionSecurity == CONN_SECURITY_NONE || *ls.ConnectionSecurity == CONN_SECURITY_TLS || *ls.ConnectionSecurity == CONN_SECURITY_STARTTLS) {
  2031  		return NewAppError("Config.IsValid", "model.config.is_valid.ldap_security.app_error", nil, "", http.StatusBadRequest)
  2032  	}
  2033  
  2034  	if *ls.SyncIntervalMinutes <= 0 {
  2035  		return NewAppError("Config.IsValid", "model.config.is_valid.ldap_sync_interval.app_error", nil, "", http.StatusBadRequest)
  2036  	}
  2037  
  2038  	if *ls.MaxPageSize < 0 {
  2039  		return NewAppError("Config.IsValid", "model.config.is_valid.ldap_max_page_size.app_error", nil, "", http.StatusBadRequest)
  2040  	}
  2041  
  2042  	if *ls.Enable {
  2043  		if *ls.LdapServer == "" {
  2044  			return NewAppError("Config.IsValid", "model.config.is_valid.ldap_server", nil, "", http.StatusBadRequest)
  2045  		}
  2046  
  2047  		if *ls.BaseDN == "" {
  2048  			return NewAppError("Config.IsValid", "model.config.is_valid.ldap_basedn", nil, "", http.StatusBadRequest)
  2049  		}
  2050  
  2051  		if *ls.EmailAttribute == "" {
  2052  			return NewAppError("Config.IsValid", "model.config.is_valid.ldap_email", nil, "", http.StatusBadRequest)
  2053  		}
  2054  
  2055  		if *ls.UsernameAttribute == "" {
  2056  			return NewAppError("Config.IsValid", "model.config.is_valid.ldap_username", nil, "", http.StatusBadRequest)
  2057  		}
  2058  
  2059  		if *ls.IdAttribute == "" {
  2060  			return NewAppError("Config.IsValid", "model.config.is_valid.ldap_id", nil, "", http.StatusBadRequest)
  2061  		}
  2062  	}
  2063  
  2064  	return nil
  2065  }
  2066  
  2067  func (ss *SamlSettings) isValid() *AppError {
  2068  	if *ss.Enable {
  2069  		if len(*ss.IdpUrl) == 0 || !IsValidHttpUrl(*ss.IdpUrl) {
  2070  			return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "", http.StatusBadRequest)
  2071  		}
  2072  
  2073  		if len(*ss.IdpDescriptorUrl) == 0 || !IsValidHttpUrl(*ss.IdpDescriptorUrl) {
  2074  			return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_descriptor_url.app_error", nil, "", http.StatusBadRequest)
  2075  		}
  2076  
  2077  		if len(*ss.IdpCertificateFile) == 0 {
  2078  			return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_cert.app_error", nil, "", http.StatusBadRequest)
  2079  		}
  2080  
  2081  		if len(*ss.EmailAttribute) == 0 {
  2082  			return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest)
  2083  		}
  2084  
  2085  		if len(*ss.UsernameAttribute) == 0 {
  2086  			return NewAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "", http.StatusBadRequest)
  2087  		}
  2088  
  2089  		if *ss.Verify {
  2090  			if len(*ss.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*ss.AssertionConsumerServiceURL) {
  2091  				return NewAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "", http.StatusBadRequest)
  2092  			}
  2093  		}
  2094  
  2095  		if *ss.Encrypt {
  2096  			if len(*ss.PrivateKeyFile) == 0 {
  2097  				return NewAppError("Config.IsValid", "model.config.is_valid.saml_private_key.app_error", nil, "", http.StatusBadRequest)
  2098  			}
  2099  
  2100  			if len(*ss.PublicCertificateFile) == 0 {
  2101  				return NewAppError("Config.IsValid", "model.config.is_valid.saml_public_cert.app_error", nil, "", http.StatusBadRequest)
  2102  			}
  2103  		}
  2104  
  2105  		if len(*ss.EmailAttribute) == 0 {
  2106  			return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest)
  2107  		}
  2108  	}
  2109  
  2110  	return nil
  2111  }
  2112  
  2113  func (ws *WebrtcSettings) isValid() *AppError {
  2114  	if *ws.Enable {
  2115  		if len(*ws.GatewayWebsocketUrl) == 0 || !IsValidWebsocketUrl(*ws.GatewayWebsocketUrl) {
  2116  			return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_ws_url.app_error", nil, "", http.StatusBadRequest)
  2117  		} else if len(*ws.GatewayAdminUrl) == 0 || !IsValidHttpUrl(*ws.GatewayAdminUrl) {
  2118  			return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_url.app_error", nil, "", http.StatusBadRequest)
  2119  		} else if len(*ws.GatewayAdminSecret) == 0 {
  2120  			return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_secret.app_error", nil, "", http.StatusBadRequest)
  2121  		} else if len(*ws.StunURI) != 0 && !IsValidTurnOrStunServer(*ws.StunURI) {
  2122  			return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_stun_uri.app_error", nil, "", http.StatusBadRequest)
  2123  		} else if len(*ws.TurnURI) != 0 {
  2124  			if !IsValidTurnOrStunServer(*ws.TurnURI) {
  2125  				return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_uri.app_error", nil, "", http.StatusBadRequest)
  2126  			}
  2127  			if len(*ws.TurnUsername) == 0 {
  2128  				return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_username.app_error", nil, "", http.StatusBadRequest)
  2129  			} else if len(*ws.TurnSharedKey) == 0 {
  2130  				return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_shared_key.app_error", nil, "", http.StatusBadRequest)
  2131  			}
  2132  		}
  2133  	}
  2134  
  2135  	return nil
  2136  }
  2137  
  2138  func (ss *ServiceSettings) isValid() *AppError {
  2139  	if !(*ss.ConnectionSecurity == CONN_SECURITY_NONE || *ss.ConnectionSecurity == CONN_SECURITY_TLS) {
  2140  		return NewAppError("Config.IsValid", "model.config.is_valid.webserver_security.app_error", nil, "", http.StatusBadRequest)
  2141  	}
  2142  
  2143  	if *ss.ReadTimeout <= 0 {
  2144  		return NewAppError("Config.IsValid", "model.config.is_valid.read_timeout.app_error", nil, "", http.StatusBadRequest)
  2145  	}
  2146  
  2147  	if *ss.WriteTimeout <= 0 {
  2148  		return NewAppError("Config.IsValid", "model.config.is_valid.write_timeout.app_error", nil, "", http.StatusBadRequest)
  2149  	}
  2150  
  2151  	if *ss.TimeBetweenUserTypingUpdatesMilliseconds < 1000 {
  2152  		return NewAppError("Config.IsValid", "model.config.is_valid.time_between_user_typing.app_error", nil, "", http.StatusBadRequest)
  2153  	}
  2154  
  2155  	if *ss.MaximumLoginAttempts <= 0 {
  2156  		return NewAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "", http.StatusBadRequest)
  2157  	}
  2158  
  2159  	if len(*ss.SiteURL) != 0 {
  2160  		if _, err := url.ParseRequestURI(*ss.SiteURL); err != nil {
  2161  			return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest)
  2162  		}
  2163  	}
  2164  
  2165  	if len(*ss.WebsocketURL) != 0 {
  2166  		if _, err := url.ParseRequestURI(*ss.WebsocketURL); err != nil {
  2167  			return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, "", http.StatusBadRequest)
  2168  		}
  2169  	}
  2170  
  2171  	if len(*ss.ListenAddress) == 0 {
  2172  		return NewAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "", http.StatusBadRequest)
  2173  	}
  2174  
  2175  	if *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED &&
  2176  		*ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_ON &&
  2177  		*ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_OFF {
  2178  		return NewAppError("Config.IsValid", "model.config.is_valid.group_unread_channels.app_error", nil, "", http.StatusBadRequest)
  2179  	}
  2180  
  2181  	switch *ss.ImageProxyType {
  2182  	case "":
  2183  	case "atmos/camo":
  2184  		if *ss.ImageProxyOptions == "" {
  2185  			return NewAppError("Config.IsValid", "model.config.is_valid.atmos_camo_image_proxy_options.app_error", nil, "", http.StatusBadRequest)
  2186  		}
  2187  	default:
  2188  		return NewAppError("Config.IsValid", "model.config.is_valid.image_proxy_type.app_error", nil, "", http.StatusBadRequest)
  2189  	}
  2190  
  2191  	return nil
  2192  }
  2193  
  2194  func (ess *ElasticsearchSettings) isValid() *AppError {
  2195  	if *ess.EnableIndexing {
  2196  		if len(*ess.ConnectionUrl) == 0 {
  2197  			return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.connection_url.app_error", nil, "", http.StatusBadRequest)
  2198  		}
  2199  	}
  2200  
  2201  	if *ess.EnableSearching && !*ess.EnableIndexing {
  2202  		return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.enable_searching.app_error", nil, "", http.StatusBadRequest)
  2203  	}
  2204  
  2205  	if *ess.AggregatePostsAfterDays < 1 {
  2206  		return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.aggregate_posts_after_days.app_error", nil, "", http.StatusBadRequest)
  2207  	}
  2208  
  2209  	if _, err := time.Parse("15:04", *ess.PostsAggregatorJobStartTime); err != nil {
  2210  		return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.posts_aggregator_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest)
  2211  	}
  2212  
  2213  	if *ess.LiveIndexingBatchSize < 1 {
  2214  		return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.live_indexing_batch_size.app_error", nil, "", http.StatusBadRequest)
  2215  	}
  2216  
  2217  	if *ess.BulkIndexingTimeWindowSeconds < 1 {
  2218  		return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.bulk_indexing_time_window_seconds.app_error", nil, "", http.StatusBadRequest)
  2219  	}
  2220  
  2221  	if *ess.RequestTimeoutSeconds < 1 {
  2222  		return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.request_timeout_seconds.app_error", nil, "", http.StatusBadRequest)
  2223  	}
  2224  
  2225  	return nil
  2226  }
  2227  
  2228  func (drs *DataRetentionSettings) isValid() *AppError {
  2229  	if *drs.MessageRetentionDays <= 0 {
  2230  		return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.message_retention_days_too_low.app_error", nil, "", http.StatusBadRequest)
  2231  	}
  2232  
  2233  	if *drs.FileRetentionDays <= 0 {
  2234  		return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.file_retention_days_too_low.app_error", nil, "", http.StatusBadRequest)
  2235  	}
  2236  
  2237  	if _, err := time.Parse("15:04", *drs.DeletionJobStartTime); err != nil {
  2238  		return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.deletion_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest)
  2239  	}
  2240  
  2241  	return nil
  2242  }
  2243  
  2244  func (ls *LocalizationSettings) isValid() *AppError {
  2245  	if len(*ls.AvailableLocales) > 0 {
  2246  		if !strings.Contains(*ls.AvailableLocales, *ls.DefaultClientLocale) {
  2247  			return NewAppError("Config.IsValid", "model.config.is_valid.localization.available_locales.app_error", nil, "", http.StatusBadRequest)
  2248  		}
  2249  	}
  2250  
  2251  	return nil
  2252  }
  2253  
  2254  func (mes *MessageExportSettings) isValid(fs FileSettings) *AppError {
  2255  	if mes.EnableExport == nil {
  2256  		return NewAppError("Config.IsValid", "model.config.is_valid.message_export.enable.app_error", nil, "", http.StatusBadRequest)
  2257  	}
  2258  	if *mes.EnableExport {
  2259  		if mes.ExportFromTimestamp == nil || *mes.ExportFromTimestamp < 0 || *mes.ExportFromTimestamp > GetMillis() {
  2260  			return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_from.app_error", nil, "", http.StatusBadRequest)
  2261  		} else if mes.DailyRunTime == nil {
  2262  			return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, "", http.StatusBadRequest)
  2263  		} else if _, err := time.Parse("15:04", *mes.DailyRunTime); err != nil {
  2264  			return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, err.Error(), http.StatusBadRequest)
  2265  		} else if mes.BatchSize == nil || *mes.BatchSize < 0 {
  2266  			return NewAppError("Config.IsValid", "model.config.is_valid.message_export.batch_size.app_error", nil, "", http.StatusBadRequest)
  2267  		} else if mes.ExportFormat == nil || (*mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_ACTIANCE && *mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_GLOBALRELAY) {
  2268  			return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_type.app_error", nil, "", http.StatusBadRequest)
  2269  		}
  2270  
  2271  		if *mes.ExportFormat == COMPLIANCE_EXPORT_TYPE_GLOBALRELAY {
  2272  			if mes.GlobalRelaySettings == nil {
  2273  				return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.config_missing.app_error", nil, "", http.StatusBadRequest)
  2274  			} else if mes.GlobalRelaySettings.CustomerType == nil || (*mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A9 && *mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A10) {
  2275  				return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.customer_type.app_error", nil, "", http.StatusBadRequest)
  2276  			} else if mes.GlobalRelaySettings.EmailAddress == nil || !strings.Contains(*mes.GlobalRelaySettings.EmailAddress, "@") {
  2277  				// validating email addresses is hard - just make sure it contains an '@' sign
  2278  				// see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
  2279  				return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.email_address.app_error", nil, "", http.StatusBadRequest)
  2280  			} else if mes.GlobalRelaySettings.SmtpUsername == nil || *mes.GlobalRelaySettings.SmtpUsername == "" {
  2281  				return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_username.app_error", nil, "", http.StatusBadRequest)
  2282  			} else if mes.GlobalRelaySettings.SmtpPassword == nil || *mes.GlobalRelaySettings.SmtpPassword == "" {
  2283  				return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_password.app_error", nil, "", http.StatusBadRequest)
  2284  			}
  2285  		}
  2286  	}
  2287  	return nil
  2288  }
  2289  
  2290  func (o *Config) GetSanitizeOptions() map[string]bool {
  2291  	options := map[string]bool{}
  2292  	options["fullname"] = o.PrivacySettings.ShowFullName
  2293  	options["email"] = o.PrivacySettings.ShowEmailAddress
  2294  
  2295  	return options
  2296  }
  2297  
  2298  func (o *Config) Sanitize() {
  2299  	if o.LdapSettings.BindPassword != nil && len(*o.LdapSettings.BindPassword) > 0 {
  2300  		*o.LdapSettings.BindPassword = FAKE_SETTING
  2301  	}
  2302  
  2303  	*o.FileSettings.PublicLinkSalt = FAKE_SETTING
  2304  	if len(o.FileSettings.AmazonS3SecretAccessKey) > 0 {
  2305  		o.FileSettings.AmazonS3SecretAccessKey = FAKE_SETTING
  2306  	}
  2307  
  2308  	o.EmailSettings.InviteSalt = FAKE_SETTING
  2309  	if len(o.EmailSettings.SMTPPassword) > 0 {
  2310  		o.EmailSettings.SMTPPassword = FAKE_SETTING
  2311  	}
  2312  
  2313  	if len(o.GitLabSettings.Secret) > 0 {
  2314  		o.GitLabSettings.Secret = FAKE_SETTING
  2315  	}
  2316  
  2317  	*o.SqlSettings.DataSource = FAKE_SETTING
  2318  	o.SqlSettings.AtRestEncryptKey = FAKE_SETTING
  2319  
  2320  	for i := range o.SqlSettings.DataSourceReplicas {
  2321  		o.SqlSettings.DataSourceReplicas[i] = FAKE_SETTING
  2322  	}
  2323  
  2324  	for i := range o.SqlSettings.DataSourceSearchReplicas {
  2325  		o.SqlSettings.DataSourceSearchReplicas[i] = FAKE_SETTING
  2326  	}
  2327  
  2328  	*o.ElasticsearchSettings.Password = FAKE_SETTING
  2329  }