diff options
author | Wim <wim@42.be> | 2018-02-09 00:11:04 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-02-09 00:11:04 +0100 |
commit | 5aab158c0b0db64b6136fe2fdaca8b8e9e3bd811 (patch) | |
tree | 09bcb3f02f968867c2ca84db1f28594dd0afb967 /vendor/github.com/mattermost/platform/model/config.go | |
parent | 1d33e60e36fa7b0e361990ac347ee8d620d67dcc (diff) | |
download | matterbridge-msglm-5aab158c0b0db64b6136fe2fdaca8b8e9e3bd811.tar.gz matterbridge-msglm-5aab158c0b0db64b6136fe2fdaca8b8e9e3bd811.tar.bz2 matterbridge-msglm-5aab158c0b0db64b6136fe2fdaca8b8e9e3bd811.zip |
Update vendor (github.com/mattermost)
Diffstat (limited to 'vendor/github.com/mattermost/platform/model/config.go')
-rw-r--r-- | vendor/github.com/mattermost/platform/model/config.go | 2364 |
1 files changed, 1362 insertions, 1002 deletions
diff --git a/vendor/github.com/mattermost/platform/model/config.go b/vendor/github.com/mattermost/platform/model/config.go index 1717d61a..fb34d1a0 100644 --- a/vendor/github.com/mattermost/platform/model/config.go +++ b/vendor/github.com/mattermost/platform/model/config.go @@ -8,6 +8,8 @@ import ( "io" "net/http" "net/url" + "strings" + "time" ) const ( @@ -22,6 +24,10 @@ const ( DATABASE_DRIVER_MYSQL = "mysql" DATABASE_DRIVER_POSTGRES = "postgres" + MINIO_ACCESS_KEY = "minioaccesskey" + MINIO_SECRET_KEY = "miniosecretkey" + MINIO_BUCKET = "mattermost-test" + PASSWORD_MAXIMUM_LENGTH = 64 PASSWORD_MINIMUM_LENGTH = 5 @@ -71,17 +77,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/" @@ -123,17 +134,32 @@ const ( ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR = "#f2a93b" ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR = "#333333" - ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL = "" - ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME = "" - ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD = "" - ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS = 1 - ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS = 1 + TEAM_SETTINGS_DEFAULT_TEAM_TEXT = "default" + + ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL = "" + ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME = "" + ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD = "" + ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS = 1 + ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS = 1 + ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS = 365 + ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME = "03:00" + ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX = "" + ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE = 1 + ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS = 3600 + ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS = 30 + + DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS = 365 + DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS = 365 + DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME = "02:00" + + PLUGIN_SETTINGS_DEFAULT_DIRECTORY = "./plugins" + PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY = "./client/plugins" ) type ServiceSettings struct { SiteURL *string LicenseFileLocation *string - ListenAddress string + ListenAddress *string ConnectionSecurity *string TLSCertFile *string TLSKeyFile *string @@ -142,7 +168,7 @@ type ServiceSettings struct { Forward80To443 *bool ReadTimeout *int WriteTimeout *int - MaximumLoginAttempts int + MaximumLoginAttempts *int GoroutineHealthThreshold *int GoogleDeveloperKey string EnableOAuthServiceProvider bool @@ -158,6 +184,7 @@ type ServiceSettings struct { EnableDeveloper *bool EnableSecurityFixAlert *bool EnableInsecureOutgoingConnections *bool + AllowedUntrustedInternalConnections *string EnableMultifactorAuthentication *bool EnforceMultifactorAuthentication *bool EnableUserAccessTokens *bool @@ -166,6 +193,7 @@ type ServiceSettings struct { SessionLengthMobileInDays *int SessionLengthSSOInDays *int SessionCacheInMinutes *int + SessionIdleTimeoutInMinutes *int WebsocketSecurePort *int WebsocketPort *int WebserverMode *string @@ -180,7 +208,211 @@ type ServiceSettings struct { EnableUserTypingMessages *bool EnableChannelViewedMessages *bool EnableUserStatuses *bool + ExperimentalEnableAuthenticationTransfer *bool ClusterLogTimeoutMilliseconds *int + CloseUnusedDirectMessages *bool + EnablePreviewFeatures *bool + EnableTutorial *bool +} + +func (s *ServiceSettings) SetDefaults() { + if s.SiteURL == nil { + s.SiteURL = NewString(SERVICE_SETTINGS_DEFAULT_SITE_URL) + } + + if s.LicenseFileLocation == nil { + s.LicenseFileLocation = NewString("") + } + + if s.ListenAddress == nil { + s.ListenAddress = NewString(SERVICE_SETTINGS_DEFAULT_LISTEN_AND_ADDRESS) + } + + if s.EnableAPIv3 == nil { + s.EnableAPIv3 = NewBool(true) + } + + if s.EnableLinkPreviews == nil { + s.EnableLinkPreviews = NewBool(false) + } + + if s.EnableDeveloper == nil { + s.EnableDeveloper = NewBool(false) + } + + if s.EnableSecurityFixAlert == nil { + s.EnableSecurityFixAlert = NewBool(true) + } + + if s.EnableInsecureOutgoingConnections == nil { + s.EnableInsecureOutgoingConnections = NewBool(false) + } + + if s.AllowedUntrustedInternalConnections == nil { + s.AllowedUntrustedInternalConnections = new(string) + } + + if s.EnableMultifactorAuthentication == nil { + s.EnableMultifactorAuthentication = NewBool(false) + } + + if s.EnforceMultifactorAuthentication == nil { + s.EnforceMultifactorAuthentication = NewBool(false) + } + + if s.EnableUserAccessTokens == nil { + s.EnableUserAccessTokens = NewBool(false) + } + + if s.GoroutineHealthThreshold == nil { + s.GoroutineHealthThreshold = NewInt(-1) + } + + if s.ConnectionSecurity == nil { + s.ConnectionSecurity = NewString("") + } + + if s.TLSKeyFile == nil { + s.TLSKeyFile = NewString(SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE) + } + + if s.TLSCertFile == nil { + s.TLSCertFile = NewString(SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE) + } + + if s.UseLetsEncrypt == nil { + s.UseLetsEncrypt = NewBool(false) + } + + if s.LetsEncryptCertificateCacheFile == nil { + s.LetsEncryptCertificateCacheFile = NewString("./config/letsencrypt.cache") + } + + if s.ReadTimeout == nil { + s.ReadTimeout = NewInt(SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT) + } + + if s.WriteTimeout == nil { + s.WriteTimeout = NewInt(SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT) + } + + if s.MaximumLoginAttempts == nil { + s.MaximumLoginAttempts = NewInt(SERVICE_SETTINGS_DEFAULT_MAX_LOGIN_ATTEMPTS) + } + + if s.Forward80To443 == nil { + s.Forward80To443 = NewBool(false) + } + + if s.TimeBetweenUserTypingUpdatesMilliseconds == nil { + s.TimeBetweenUserTypingUpdatesMilliseconds = NewInt64(5000) + } + + if s.EnablePostSearch == nil { + s.EnablePostSearch = NewBool(true) + } + + if s.EnableUserTypingMessages == nil { + s.EnableUserTypingMessages = NewBool(true) + } + + if s.EnableChannelViewedMessages == nil { + s.EnableChannelViewedMessages = NewBool(true) + } + + if s.EnableUserStatuses == nil { + s.EnableUserStatuses = NewBool(true) + } + + if s.ClusterLogTimeoutMilliseconds == nil { + s.ClusterLogTimeoutMilliseconds = NewInt(2000) + } + + if s.CloseUnusedDirectMessages == nil { + s.CloseUnusedDirectMessages = NewBool(false) + } + + if s.EnableTutorial == nil { + s.EnableTutorial = NewBool(true) + } + + if s.SessionLengthWebInDays == nil { + s.SessionLengthWebInDays = NewInt(30) + } + + if s.SessionLengthMobileInDays == nil { + s.SessionLengthMobileInDays = NewInt(30) + } + + if s.SessionLengthSSOInDays == nil { + s.SessionLengthSSOInDays = NewInt(30) + } + + if s.SessionCacheInMinutes == nil { + s.SessionCacheInMinutes = NewInt(10) + } + + if s.SessionIdleTimeoutInMinutes == nil { + s.SessionIdleTimeoutInMinutes = NewInt(0) + } + + if s.EnableCommands == nil { + s.EnableCommands = NewBool(false) + } + + if s.EnableOnlyAdminIntegrations == nil { + s.EnableOnlyAdminIntegrations = NewBool(true) + } + + if s.WebsocketPort == nil { + s.WebsocketPort = NewInt(80) + } + + if s.WebsocketSecurePort == nil { + s.WebsocketSecurePort = NewInt(443) + } + + if s.AllowCorsFrom == nil { + s.AllowCorsFrom = NewString(SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM) + } + + if s.WebserverMode == nil { + s.WebserverMode = NewString("gzip") + } else if *s.WebserverMode == "regular" { + *s.WebserverMode = "gzip" + } + + if s.EnableCustomEmoji == nil { + s.EnableCustomEmoji = NewBool(false) + } + + if s.EnableEmojiPicker == nil { + s.EnableEmojiPicker = NewBool(true) + } + + if s.RestrictCustomEmojiCreation == nil { + s.RestrictCustomEmojiCreation = NewString(RESTRICT_EMOJI_CREATION_ALL) + } + + if s.RestrictPostDelete == nil { + s.RestrictPostDelete = NewString(PERMISSIONS_DELETE_POST_ALL) + } + + if s.AllowEditPost == nil { + s.AllowEditPost = NewString(ALLOW_EDIT_POST_ALWAYS) + } + + if s.ExperimentalEnableAuthenticationTransfer == nil { + s.ExperimentalEnableAuthenticationTransfer = NewBool(true) + } + + if s.PostEditTimeLimit == nil { + s.PostEditTimeLimit = NewInt(300) + } + + if s.EnablePreviewFeatures == nil { + s.EnablePreviewFeatures = NewBool(true) + } } type ClusterSettings struct { @@ -194,16 +426,70 @@ type ClusterSettings struct { StreamingPort *int } +func (s *ClusterSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(false) + } + + if s.ClusterName == nil { + s.ClusterName = NewString("") + } + + if s.OverrideHostname == nil { + s.OverrideHostname = NewString("") + } + + if s.UseIpAddress == nil { + s.UseIpAddress = NewBool(true) + } + + if s.UseExperimentalGossip == nil { + s.UseExperimentalGossip = NewBool(false) + } + + if s.ReadOnlyConfig == nil { + s.ReadOnlyConfig = NewBool(true) + } + + if s.GossipPort == nil { + s.GossipPort = NewInt(8074) + } + + if s.StreamingPort == nil { + s.StreamingPort = NewInt(8075) + } +} + type MetricsSettings struct { Enable *bool BlockProfileRate *int ListenAddress *string } +func (s *MetricsSettings) SetDefaults() { + if s.ListenAddress == nil { + s.ListenAddress = NewString(":8067") + } + + if s.Enable == nil { + s.Enable = NewBool(false) + } + + if s.BlockProfileRate == nil { + s.BlockProfileRate = NewInt(0) + } +} + type AnalyticsSettings struct { MaxUsersForStatistics *int } +func (s *AnalyticsSettings) SetDefaults() { + if s.MaxUsersForStatistics == nil { + s.MaxUsersForStatistics = NewInt(ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS) + } +} + type SSOSettings struct { Enable bool Secret string @@ -215,17 +501,43 @@ 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 } +func (s *SqlSettings) SetDefaults() { + if s.DriverName == nil { + s.DriverName = NewString(DATABASE_DRIVER_MYSQL) + } + + if s.DataSource == nil { + s.DataSource = NewString(SQL_SETTINGS_DEFAULT_DATA_SOURCE) + } + + if len(s.AtRestEncryptKey) == 0 { + s.AtRestEncryptKey = NewRandomString(32) + } + + if s.MaxIdleConns == nil { + s.MaxIdleConns = NewInt(20) + } + + if s.MaxOpenConns == nil { + s.MaxOpenConns = NewInt(300) + } + + if s.QueryTimeout == nil { + s.QueryTimeout = NewInt(30) + } +} + type LogSettings struct { EnableConsole bool ConsoleLevel string @@ -237,6 +549,12 @@ type LogSettings struct { EnableDiagnostics *bool } +func (s *LogSettings) SetDefaults() { + if s.EnableDiagnostics == nil { + s.EnableDiagnostics = NewBool(true) + } +} + type PasswordSettings struct { MinimumLength *int Lowercase *bool @@ -245,12 +563,34 @@ type PasswordSettings struct { Symbol *bool } +func (s *PasswordSettings) SetDefaults() { + if s.MinimumLength == nil { + s.MinimumLength = NewInt(PASSWORD_MINIMUM_LENGTH) + } + + if s.Lowercase == nil { + s.Lowercase = NewBool(false) + } + + if s.Number == nil { + s.Number = NewBool(false) + } + + if s.Uppercase == nil { + s.Uppercase = NewBool(false) + } + + if s.Symbol == nil { + s.Symbol = NewBool(false) + } +} + type FileSettings struct { EnableFileAttachments *bool EnableMobileUpload *bool EnableMobileDownload *bool MaxFileSize *int64 - DriverName string + DriverName *string Directory string EnablePublicLink bool PublicLinkSalt *string @@ -263,6 +603,64 @@ type FileSettings struct { AmazonS3SSL *bool AmazonS3SignV2 *bool AmazonS3SSE *bool + AmazonS3Trace *bool +} + +func (s *FileSettings) SetDefaults() { + if s.DriverName == nil { + s.DriverName = NewString(IMAGE_DRIVER_LOCAL) + } + + if s.AmazonS3Endpoint == "" { + // Defaults to "s3.amazonaws.com" + s.AmazonS3Endpoint = "s3.amazonaws.com" + } + + if s.AmazonS3SSL == nil { + s.AmazonS3SSL = NewBool(true) // Secure by default. + } + + if s.AmazonS3SignV2 == nil { + s.AmazonS3SignV2 = new(bool) + // Signature v2 is not enabled by default. + } + + if s.AmazonS3SSE == nil { + s.AmazonS3SSE = NewBool(false) // Not Encrypted by default. + } + + if s.AmazonS3Trace == nil { + s.AmazonS3Trace = NewBool(false) + } + + if s.EnableFileAttachments == nil { + s.EnableFileAttachments = NewBool(true) + } + + if s.EnableMobileUpload == nil { + s.EnableMobileUpload = NewBool(true) + } + + if s.EnableMobileDownload == nil { + s.EnableMobileDownload = NewBool(true) + } + + if s.MaxFileSize == nil { + s.MaxFileSize = NewInt64(52428800) // 50 MB + } + + if s.PublicLinkSalt == nil || len(*s.PublicLinkSalt) == 0 { + s.PublicLinkSalt = NewString(NewRandomString(32)) + } + + if s.InitialFont == "" { + // Defaults to "luximbi.ttf" + s.InitialFont = "luximbi.ttf" + } + + if s.Directory == "" { + s.Directory = "./data/" + } } type EmailSettings struct { @@ -270,6 +668,7 @@ type EmailSettings struct { EnableSignInWithEmail *bool EnableSignInWithUsername *bool SendEmailNotifications bool + UseChannelInEmailNotifications *bool RequireEmailVerification bool FeedbackName string FeedbackEmail string @@ -289,1412 +688,1441 @@ type EmailSettings struct { EmailBatchingInterval *int SkipServerCertificateVerification *bool EmailNotificationContentsType *string + LoginButtonColor *string + LoginButtonBorderColor *string + LoginButtonTextColor *string } -type RateLimitSettings struct { - Enable *bool - PerSec int - MaxBurst *int - MemoryStoreSize int - VaryByRemoteAddr bool - VaryByHeader string -} - -type PrivacySettings struct { - ShowEmailAddress bool - ShowFullName bool -} - -type SupportSettings struct { - TermsOfServiceLink *string - PrivacyPolicyLink *string - AboutLink *string - HelpLink *string - ReportAProblemLink *string - AdministratorsGuideLink *string - TroubleshootingForumLink *string - CommercialSupportLink *string - SupportEmail *string -} - -type AnnouncementSettings struct { - EnableBanner *bool - BannerText *string - BannerColor *string - BannerTextColor *string - AllowBannerDismissal *bool -} - -type TeamSettings struct { - SiteName string - MaxUsersPerTeam int - EnableTeamCreation bool - EnableUserCreation bool - EnableOpenServer *bool - RestrictCreationToDomains string - EnableCustomBrand *bool - CustomBrandText *string - CustomDescriptionText *string - RestrictDirectMessage *string - RestrictTeamInvite *string - RestrictPublicChannelManagement *string - RestrictPrivateChannelManagement *string - RestrictPublicChannelCreation *string - RestrictPrivateChannelCreation *string - RestrictPublicChannelDeletion *string - RestrictPrivateChannelDeletion *string - RestrictPrivateChannelManageMembers *string - UserStatusAwayTimeout *int64 - MaxChannelsPerTeam *int64 - MaxNotificationsPerChannel *int64 - TeammateNameDisplay *string -} - -type LdapSettings struct { - // Basic - Enable *bool - LdapServer *string - LdapPort *int - ConnectionSecurity *string - BaseDN *string - BindUsername *string - BindPassword *string - - // Filtering - UserFilter *string - - // User Mapping - FirstNameAttribute *string - LastNameAttribute *string - EmailAttribute *string - UsernameAttribute *string - NicknameAttribute *string - IdAttribute *string - PositionAttribute *string - - // Syncronization - SyncIntervalMinutes *int - - // Advanced - SkipCertificateVerification *bool - QueryTimeout *int - MaxPageSize *int - - // Customization - LoginFieldName *string -} - -type ComplianceSettings struct { - Enable *bool - Directory *string - EnableDaily *bool -} +func (s *EmailSettings) SetDefaults() { + if len(s.InviteSalt) == 0 { + s.InviteSalt = NewRandomString(32) + } -type LocalizationSettings struct { - DefaultServerLocale *string - DefaultClientLocale *string - AvailableLocales *string -} + if s.EnableSignInWithEmail == nil { + s.EnableSignInWithEmail = NewBool(s.EnableSignUpWithEmail) + } -type SamlSettings struct { - // Basic - Enable *bool - Verify *bool - Encrypt *bool + if s.EnableSignInWithUsername == nil { + s.EnableSignInWithUsername = NewBool(false) + } - IdpUrl *string - IdpDescriptorUrl *string - AssertionConsumerServiceURL *string + if s.UseChannelInEmailNotifications == nil { + s.UseChannelInEmailNotifications = NewBool(false) + } - IdpCertificateFile *string - PublicCertificateFile *string - PrivateKeyFile *string + if s.SendPushNotifications == nil { + s.SendPushNotifications = NewBool(false) + } - // User Mapping - FirstNameAttribute *string - LastNameAttribute *string - EmailAttribute *string - UsernameAttribute *string - NicknameAttribute *string - LocaleAttribute *string - PositionAttribute *string + if s.PushNotificationServer == nil { + s.PushNotificationServer = NewString("") + } - LoginButtonText *string -} + if s.PushNotificationContents == nil { + s.PushNotificationContents = NewString(GENERIC_NOTIFICATION) + } -type NativeAppSettings struct { - AppDownloadLink *string - AndroidAppDownloadLink *string - IosAppDownloadLink *string -} + if s.FeedbackOrganization == nil { + s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION) + } -type WebrtcSettings struct { - Enable *bool - GatewayWebsocketUrl *string - GatewayAdminUrl *string - GatewayAdminSecret *string - StunURI *string - TurnURI *string - TurnUsername *string - TurnSharedKey *string -} + if s.EnableEmailBatching == nil { + s.EnableEmailBatching = NewBool(false) + } -type ElasticsearchSettings struct { - ConnectionUrl *string - Username *string - Password *string - EnableIndexing *bool - EnableSearching *bool - Sniff *bool - PostIndexReplicas *int - PostIndexShards *int -} + if s.EmailBatchingBufferSize == nil { + s.EmailBatchingBufferSize = NewInt(EMAIL_BATCHING_BUFFER_SIZE) + } -type DataRetentionSettings struct { - Enable *bool -} + if s.EmailBatchingInterval == nil { + s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL) + } -type JobSettings struct { - RunJobs *bool - RunScheduler *bool -} + if s.EnableSMTPAuth == nil { + s.EnableSMTPAuth = new(bool) + if s.ConnectionSecurity == CONN_SECURITY_NONE { + *s.EnableSMTPAuth = false + } else { + *s.EnableSMTPAuth = true + } + } -type PluginSettings struct { - Plugins map[string]interface{} -} + if s.ConnectionSecurity == CONN_SECURITY_PLAIN { + s.ConnectionSecurity = CONN_SECURITY_NONE + } -type Config struct { - ServiceSettings ServiceSettings - TeamSettings TeamSettings - SqlSettings SqlSettings - LogSettings LogSettings - PasswordSettings PasswordSettings - FileSettings FileSettings - EmailSettings EmailSettings - RateLimitSettings RateLimitSettings - PrivacySettings PrivacySettings - SupportSettings SupportSettings - AnnouncementSettings AnnouncementSettings - GitLabSettings SSOSettings - GoogleSettings SSOSettings - Office365Settings SSOSettings - LdapSettings LdapSettings - ComplianceSettings ComplianceSettings - LocalizationSettings LocalizationSettings - SamlSettings SamlSettings - NativeAppSettings NativeAppSettings - ClusterSettings ClusterSettings - MetricsSettings MetricsSettings - AnalyticsSettings AnalyticsSettings - WebrtcSettings WebrtcSettings - ElasticsearchSettings ElasticsearchSettings - DataRetentionSettings DataRetentionSettings - JobSettings JobSettings - PluginSettings PluginSettings -} + if s.SkipServerCertificateVerification == nil { + s.SkipServerCertificateVerification = NewBool(false) + } -func (o *Config) ToJson() string { - b, err := json.Marshal(o) - if err != nil { - return "" - } else { - return string(b) + if s.EmailNotificationContentsType == nil { + s.EmailNotificationContentsType = NewString(EMAIL_NOTIFICATION_CONTENTS_FULL) } -} -func (o *Config) GetSSOService(service string) *SSOSettings { - switch service { - case SERVICE_GITLAB: - return &o.GitLabSettings - case SERVICE_GOOGLE: - return &o.GoogleSettings - case SERVICE_OFFICE365: - return &o.Office365Settings + if s.LoginButtonColor == nil { + s.LoginButtonColor = NewString("#0000") } - return nil -} + if s.LoginButtonBorderColor == nil { + s.LoginButtonBorderColor = NewString("#2389D7") + } -func ConfigFromJson(data io.Reader) *Config { - decoder := json.NewDecoder(data) - var o Config - err := decoder.Decode(&o) - if err == nil { - return &o - } else { - return nil + if s.LoginButtonTextColor == nil { + s.LoginButtonTextColor = NewString("#2389D7") } } -func (o *Config) SetDefaults() { +type RateLimitSettings struct { + Enable *bool + PerSec *int + MaxBurst *int + MemoryStoreSize *int + VaryByRemoteAddr bool + VaryByHeader string +} - if len(o.SqlSettings.AtRestEncryptKey) == 0 { - o.SqlSettings.AtRestEncryptKey = NewRandomString(32) +func (s *RateLimitSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(false) } - if o.SqlSettings.QueryTimeout == nil { - o.SqlSettings.QueryTimeout = new(int) - *o.SqlSettings.QueryTimeout = 30 + if s.PerSec == nil { + s.PerSec = NewInt(10) } - if o.FileSettings.AmazonS3Endpoint == "" { - // Defaults to "s3.amazonaws.com" - o.FileSettings.AmazonS3Endpoint = "s3.amazonaws.com" + if s.MaxBurst == nil { + s.MaxBurst = NewInt(100) } - if o.FileSettings.AmazonS3SSL == nil { - o.FileSettings.AmazonS3SSL = new(bool) - *o.FileSettings.AmazonS3SSL = true // Secure by default. + if s.MemoryStoreSize == nil { + s.MemoryStoreSize = NewInt(10000) } +} - if o.FileSettings.AmazonS3SignV2 == nil { - o.FileSettings.AmazonS3SignV2 = new(bool) - // Signature v2 is not enabled by default. - } +type PrivacySettings struct { + ShowEmailAddress bool + ShowFullName bool +} - if o.FileSettings.AmazonS3SSE == nil { - o.FileSettings.AmazonS3SSE = new(bool) - *o.FileSettings.AmazonS3SSE = false // Not Encrypted by default. - } +type SupportSettings struct { + TermsOfServiceLink *string + PrivacyPolicyLink *string + AboutLink *string + HelpLink *string + ReportAProblemLink *string + SupportEmail *string +} - if o.FileSettings.EnableFileAttachments == nil { - o.FileSettings.EnableFileAttachments = new(bool) - *o.FileSettings.EnableFileAttachments = true +func (s *SupportSettings) SetDefaults() { + if !IsSafeLink(s.TermsOfServiceLink) { + *s.TermsOfServiceLink = SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK } - if o.FileSettings.EnableMobileUpload == nil { - o.FileSettings.EnableMobileUpload = new(bool) - *o.FileSettings.EnableMobileUpload = true + if s.TermsOfServiceLink == nil { + s.TermsOfServiceLink = NewString(SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK) } - if o.FileSettings.EnableMobileDownload == nil { - o.FileSettings.EnableMobileDownload = new(bool) - *o.FileSettings.EnableMobileDownload = true + if !IsSafeLink(s.PrivacyPolicyLink) { + *s.PrivacyPolicyLink = "" } - if o.FileSettings.MaxFileSize == nil { - o.FileSettings.MaxFileSize = new(int64) - *o.FileSettings.MaxFileSize = 52428800 // 50 MB + if s.PrivacyPolicyLink == nil { + s.PrivacyPolicyLink = NewString(SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK) } - if o.FileSettings.PublicLinkSalt == nil || len(*o.FileSettings.PublicLinkSalt) == 0 { - o.FileSettings.PublicLinkSalt = new(string) - *o.FileSettings.PublicLinkSalt = NewRandomString(32) + if !IsSafeLink(s.AboutLink) { + *s.AboutLink = "" } - if o.FileSettings.InitialFont == "" { - // Defaults to "luximbi.ttf" - o.FileSettings.InitialFont = "luximbi.ttf" + if s.AboutLink == nil { + s.AboutLink = NewString(SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK) } - if o.FileSettings.Directory == "" { - o.FileSettings.Directory = "./data/" + if !IsSafeLink(s.HelpLink) { + *s.HelpLink = "" } - if len(o.EmailSettings.InviteSalt) == 0 { - o.EmailSettings.InviteSalt = NewRandomString(32) + if s.HelpLink == nil { + s.HelpLink = NewString(SUPPORT_SETTINGS_DEFAULT_HELP_LINK) } - if o.ServiceSettings.SiteURL == nil { - o.ServiceSettings.SiteURL = new(string) - *o.ServiceSettings.SiteURL = SERVICE_SETTINGS_DEFAULT_SITE_URL + if !IsSafeLink(s.ReportAProblemLink) { + *s.ReportAProblemLink = "" } - if o.ServiceSettings.LicenseFileLocation == nil { - o.ServiceSettings.LicenseFileLocation = new(string) + if s.ReportAProblemLink == nil { + s.ReportAProblemLink = NewString(SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK) } - if o.ServiceSettings.EnableAPIv3 == nil { - o.ServiceSettings.EnableAPIv3 = new(bool) - *o.ServiceSettings.EnableAPIv3 = true + if s.SupportEmail == nil { + s.SupportEmail = NewString(SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL) } +} - if o.ServiceSettings.EnableLinkPreviews == nil { - o.ServiceSettings.EnableLinkPreviews = new(bool) - *o.ServiceSettings.EnableLinkPreviews = false - } +type AnnouncementSettings struct { + EnableBanner *bool + BannerText *string + BannerColor *string + BannerTextColor *string + AllowBannerDismissal *bool +} - if o.ServiceSettings.EnableDeveloper == nil { - o.ServiceSettings.EnableDeveloper = new(bool) - *o.ServiceSettings.EnableDeveloper = false +func (s *AnnouncementSettings) SetDefaults() { + if s.EnableBanner == nil { + s.EnableBanner = NewBool(false) } - if o.ServiceSettings.EnableSecurityFixAlert == nil { - o.ServiceSettings.EnableSecurityFixAlert = new(bool) - *o.ServiceSettings.EnableSecurityFixAlert = true + if s.BannerText == nil { + s.BannerText = NewString("") } - if o.ServiceSettings.EnableInsecureOutgoingConnections == nil { - o.ServiceSettings.EnableInsecureOutgoingConnections = new(bool) - *o.ServiceSettings.EnableInsecureOutgoingConnections = false + if s.BannerColor == nil { + s.BannerColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR) } - if o.ServiceSettings.EnableMultifactorAuthentication == nil { - o.ServiceSettings.EnableMultifactorAuthentication = new(bool) - *o.ServiceSettings.EnableMultifactorAuthentication = false + if s.BannerTextColor == nil { + s.BannerTextColor = NewString(ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR) } - if o.ServiceSettings.EnforceMultifactorAuthentication == nil { - o.ServiceSettings.EnforceMultifactorAuthentication = new(bool) - *o.ServiceSettings.EnforceMultifactorAuthentication = false + if s.AllowBannerDismissal == nil { + s.AllowBannerDismissal = NewBool(true) } +} - if o.ServiceSettings.EnableUserAccessTokens == nil { - o.ServiceSettings.EnableUserAccessTokens = new(bool) - *o.ServiceSettings.EnableUserAccessTokens = false - } +type ThemeSettings struct { + EnableThemeSelection *bool + DefaultTheme *string + AllowCustomThemes *bool + AllowedThemes []string +} - if o.PasswordSettings.MinimumLength == nil { - o.PasswordSettings.MinimumLength = new(int) - *o.PasswordSettings.MinimumLength = PASSWORD_MINIMUM_LENGTH +func (s *ThemeSettings) SetDefaults() { + if s.EnableThemeSelection == nil { + s.EnableThemeSelection = NewBool(true) } - if o.PasswordSettings.Lowercase == nil { - o.PasswordSettings.Lowercase = new(bool) - *o.PasswordSettings.Lowercase = false + if s.DefaultTheme == nil { + s.DefaultTheme = NewString(TEAM_SETTINGS_DEFAULT_TEAM_TEXT) } - if o.PasswordSettings.Number == nil { - o.PasswordSettings.Number = new(bool) - *o.PasswordSettings.Number = false + if s.AllowCustomThemes == nil { + s.AllowCustomThemes = NewBool(true) } - if o.PasswordSettings.Uppercase == nil { - o.PasswordSettings.Uppercase = new(bool) - *o.PasswordSettings.Uppercase = false + if s.AllowedThemes == nil { + s.AllowedThemes = []string{} } +} + +type TeamSettings struct { + SiteName string + MaxUsersPerTeam *int + EnableTeamCreation bool + EnableUserCreation bool + EnableOpenServer *bool + RestrictCreationToDomains string + EnableCustomBrand *bool + CustomBrandText *string + CustomDescriptionText *string + RestrictDirectMessage *string + RestrictTeamInvite *string + RestrictPublicChannelManagement *string + RestrictPrivateChannelManagement *string + RestrictPublicChannelCreation *string + RestrictPrivateChannelCreation *string + RestrictPublicChannelDeletion *string + RestrictPrivateChannelDeletion *string + RestrictPrivateChannelManageMembers *string + EnableXToLeaveChannelsFromLHS *bool + UserStatusAwayTimeout *int64 + MaxChannelsPerTeam *int64 + MaxNotificationsPerChannel *int64 + EnableConfirmNotificationsToChannel *bool + TeammateNameDisplay *string + ExperimentalTownSquareIsReadOnly *bool + ExperimentalPrimaryTeam *string +} - if o.PasswordSettings.Symbol == nil { - o.PasswordSettings.Symbol = new(bool) - *o.PasswordSettings.Symbol = false +func (s *TeamSettings) SetDefaults() { + if s.MaxUsersPerTeam == nil { + s.MaxUsersPerTeam = NewInt(TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM) } - if o.TeamSettings.EnableCustomBrand == nil { - o.TeamSettings.EnableCustomBrand = new(bool) - *o.TeamSettings.EnableCustomBrand = false + if s.EnableCustomBrand == nil { + s.EnableCustomBrand = NewBool(false) } - if o.TeamSettings.CustomBrandText == nil { - o.TeamSettings.CustomBrandText = new(string) - *o.TeamSettings.CustomBrandText = TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT + if s.CustomBrandText == nil { + s.CustomBrandText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT) } - if o.TeamSettings.CustomDescriptionText == nil { - o.TeamSettings.CustomDescriptionText = new(string) - *o.TeamSettings.CustomDescriptionText = TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT + if s.CustomDescriptionText == nil { + s.CustomDescriptionText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT) } - if o.TeamSettings.EnableOpenServer == nil { - o.TeamSettings.EnableOpenServer = new(bool) - *o.TeamSettings.EnableOpenServer = false + if s.EnableOpenServer == nil { + s.EnableOpenServer = NewBool(false) } - if o.TeamSettings.RestrictDirectMessage == nil { - o.TeamSettings.RestrictDirectMessage = new(string) - *o.TeamSettings.RestrictDirectMessage = DIRECT_MESSAGE_ANY + if s.RestrictDirectMessage == nil { + s.RestrictDirectMessage = NewString(DIRECT_MESSAGE_ANY) } - if o.TeamSettings.RestrictTeamInvite == nil { - o.TeamSettings.RestrictTeamInvite = new(string) - *o.TeamSettings.RestrictTeamInvite = PERMISSIONS_ALL + if s.RestrictTeamInvite == nil { + s.RestrictTeamInvite = NewString(PERMISSIONS_ALL) } - if o.TeamSettings.RestrictPublicChannelManagement == nil { - o.TeamSettings.RestrictPublicChannelManagement = new(string) - *o.TeamSettings.RestrictPublicChannelManagement = PERMISSIONS_ALL + if s.RestrictPublicChannelManagement == nil { + s.RestrictPublicChannelManagement = NewString(PERMISSIONS_ALL) } - if o.TeamSettings.RestrictPrivateChannelManagement == nil { - o.TeamSettings.RestrictPrivateChannelManagement = new(string) - *o.TeamSettings.RestrictPrivateChannelManagement = PERMISSIONS_ALL + if s.RestrictPrivateChannelManagement == nil { + s.RestrictPrivateChannelManagement = NewString(PERMISSIONS_ALL) } - if o.TeamSettings.RestrictPublicChannelCreation == nil { - o.TeamSettings.RestrictPublicChannelCreation = new(string) + if s.RestrictPublicChannelCreation == nil { + s.RestrictPublicChannelCreation = new(string) // If this setting does not exist, assume migration from <3.6, so use management setting as default. - if *o.TeamSettings.RestrictPublicChannelManagement == PERMISSIONS_CHANNEL_ADMIN { - *o.TeamSettings.RestrictPublicChannelCreation = PERMISSIONS_TEAM_ADMIN + if *s.RestrictPublicChannelManagement == PERMISSIONS_CHANNEL_ADMIN { + *s.RestrictPublicChannelCreation = PERMISSIONS_TEAM_ADMIN } else { - *o.TeamSettings.RestrictPublicChannelCreation = *o.TeamSettings.RestrictPublicChannelManagement + *s.RestrictPublicChannelCreation = *s.RestrictPublicChannelManagement } } - if o.TeamSettings.RestrictPrivateChannelCreation == nil { - o.TeamSettings.RestrictPrivateChannelCreation = new(string) + if s.RestrictPrivateChannelCreation == nil { // If this setting does not exist, assume migration from <3.6, so use management setting as default. - if *o.TeamSettings.RestrictPrivateChannelManagement == PERMISSIONS_CHANNEL_ADMIN { - *o.TeamSettings.RestrictPrivateChannelCreation = PERMISSIONS_TEAM_ADMIN + if *s.RestrictPrivateChannelManagement == PERMISSIONS_CHANNEL_ADMIN { + s.RestrictPrivateChannelCreation = NewString(PERMISSIONS_TEAM_ADMIN) } else { - *o.TeamSettings.RestrictPrivateChannelCreation = *o.TeamSettings.RestrictPrivateChannelManagement + s.RestrictPrivateChannelCreation = NewString(*s.RestrictPrivateChannelManagement) } } - if o.TeamSettings.RestrictPublicChannelDeletion == nil { - o.TeamSettings.RestrictPublicChannelDeletion = new(string) + if s.RestrictPublicChannelDeletion == nil { // If this setting does not exist, assume migration from <3.6, so use management setting as default. - *o.TeamSettings.RestrictPublicChannelDeletion = *o.TeamSettings.RestrictPublicChannelManagement + s.RestrictPublicChannelDeletion = NewString(*s.RestrictPublicChannelManagement) } - if o.TeamSettings.RestrictPrivateChannelDeletion == nil { - o.TeamSettings.RestrictPrivateChannelDeletion = new(string) + if s.RestrictPrivateChannelDeletion == nil { // If this setting does not exist, assume migration from <3.6, so use management setting as default. - *o.TeamSettings.RestrictPrivateChannelDeletion = *o.TeamSettings.RestrictPrivateChannelManagement + s.RestrictPrivateChannelDeletion = NewString(*s.RestrictPrivateChannelManagement) } - if o.TeamSettings.RestrictPrivateChannelManageMembers == nil { - o.TeamSettings.RestrictPrivateChannelManageMembers = new(string) - *o.TeamSettings.RestrictPrivateChannelManageMembers = PERMISSIONS_ALL + if s.RestrictPrivateChannelManageMembers == nil { + s.RestrictPrivateChannelManageMembers = NewString(PERMISSIONS_ALL) } - if o.TeamSettings.UserStatusAwayTimeout == nil { - o.TeamSettings.UserStatusAwayTimeout = new(int64) - *o.TeamSettings.UserStatusAwayTimeout = TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT + if s.EnableXToLeaveChannelsFromLHS == nil { + s.EnableXToLeaveChannelsFromLHS = NewBool(false) } - if o.TeamSettings.MaxChannelsPerTeam == nil { - o.TeamSettings.MaxChannelsPerTeam = new(int64) - *o.TeamSettings.MaxChannelsPerTeam = 2000 + if s.UserStatusAwayTimeout == nil { + s.UserStatusAwayTimeout = NewInt64(TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT) } - if o.TeamSettings.MaxNotificationsPerChannel == nil { - o.TeamSettings.MaxNotificationsPerChannel = new(int64) - *o.TeamSettings.MaxNotificationsPerChannel = 1000 + if s.MaxChannelsPerTeam == nil { + s.MaxChannelsPerTeam = NewInt64(2000) } - if o.EmailSettings.EnableSignInWithEmail == nil { - o.EmailSettings.EnableSignInWithEmail = new(bool) - - if o.EmailSettings.EnableSignUpWithEmail == true { - *o.EmailSettings.EnableSignInWithEmail = true - } else { - *o.EmailSettings.EnableSignInWithEmail = false - } + if s.MaxNotificationsPerChannel == nil { + s.MaxNotificationsPerChannel = NewInt64(1000) } - if o.EmailSettings.EnableSignInWithUsername == nil { - o.EmailSettings.EnableSignInWithUsername = new(bool) - *o.EmailSettings.EnableSignInWithUsername = false + if s.EnableConfirmNotificationsToChannel == nil { + s.EnableConfirmNotificationsToChannel = NewBool(true) } - if o.EmailSettings.SendPushNotifications == nil { - o.EmailSettings.SendPushNotifications = new(bool) - *o.EmailSettings.SendPushNotifications = false + if s.ExperimentalTownSquareIsReadOnly == nil { + s.ExperimentalTownSquareIsReadOnly = NewBool(false) } - if o.EmailSettings.PushNotificationServer == nil { - o.EmailSettings.PushNotificationServer = new(string) - *o.EmailSettings.PushNotificationServer = "" + if s.ExperimentalPrimaryTeam == nil { + s.ExperimentalPrimaryTeam = NewString("") } +} - if o.EmailSettings.PushNotificationContents == nil { - o.EmailSettings.PushNotificationContents = new(string) - *o.EmailSettings.PushNotificationContents = GENERIC_NOTIFICATION - } +type ClientRequirements struct { + AndroidLatestVersion string + AndroidMinVersion string + DesktopLatestVersion string + DesktopMinVersion string + IosLatestVersion string + IosMinVersion string +} - if o.EmailSettings.FeedbackOrganization == nil { - o.EmailSettings.FeedbackOrganization = new(string) - *o.EmailSettings.FeedbackOrganization = EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION - } +type LdapSettings struct { + // Basic + Enable *bool + EnableSync *bool + LdapServer *string + LdapPort *int + ConnectionSecurity *string + BaseDN *string + BindUsername *string + BindPassword *string - if o.EmailSettings.EnableEmailBatching == nil { - o.EmailSettings.EnableEmailBatching = new(bool) - *o.EmailSettings.EnableEmailBatching = false - } + // Filtering + UserFilter *string - if o.EmailSettings.EmailBatchingBufferSize == nil { - o.EmailSettings.EmailBatchingBufferSize = new(int) - *o.EmailSettings.EmailBatchingBufferSize = EMAIL_BATCHING_BUFFER_SIZE - } + // User Mapping + FirstNameAttribute *string + LastNameAttribute *string + EmailAttribute *string + UsernameAttribute *string + NicknameAttribute *string + IdAttribute *string + PositionAttribute *string - if o.EmailSettings.EmailBatchingInterval == nil { - o.EmailSettings.EmailBatchingInterval = new(int) - *o.EmailSettings.EmailBatchingInterval = EMAIL_BATCHING_INTERVAL - } + // Syncronization + SyncIntervalMinutes *int - if o.EmailSettings.EnableSMTPAuth == nil { - o.EmailSettings.EnableSMTPAuth = new(bool) - if o.EmailSettings.ConnectionSecurity == CONN_SECURITY_NONE { - *o.EmailSettings.EnableSMTPAuth = false - } else { - *o.EmailSettings.EnableSMTPAuth = true - } - } + // Advanced + SkipCertificateVerification *bool + QueryTimeout *int + MaxPageSize *int - if o.EmailSettings.ConnectionSecurity == CONN_SECURITY_PLAIN { - o.EmailSettings.ConnectionSecurity = CONN_SECURITY_NONE - } + // Customization + LoginFieldName *string - if o.EmailSettings.SkipServerCertificateVerification == nil { - o.EmailSettings.SkipServerCertificateVerification = new(bool) - *o.EmailSettings.SkipServerCertificateVerification = false - } + LoginButtonColor *string + LoginButtonBorderColor *string + LoginButtonTextColor *string +} - if o.EmailSettings.EmailNotificationContentsType == nil { - o.EmailSettings.EmailNotificationContentsType = new(string) - *o.EmailSettings.EmailNotificationContentsType = EMAIL_NOTIFICATION_CONTENTS_FULL +func (s *LdapSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(false) } - if !IsSafeLink(o.SupportSettings.TermsOfServiceLink) { - *o.SupportSettings.TermsOfServiceLink = SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK + // When unset should default to LDAP Enabled + if s.EnableSync == nil { + s.EnableSync = NewBool(*s.Enable) } - if o.SupportSettings.TermsOfServiceLink == nil { - o.SupportSettings.TermsOfServiceLink = new(string) - *o.SupportSettings.TermsOfServiceLink = SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK + if s.LdapServer == nil { + s.LdapServer = NewString("") } - if !IsSafeLink(o.SupportSettings.PrivacyPolicyLink) { - *o.SupportSettings.PrivacyPolicyLink = "" + if s.LdapPort == nil { + s.LdapPort = NewInt(389) } - if o.SupportSettings.PrivacyPolicyLink == nil { - o.SupportSettings.PrivacyPolicyLink = new(string) - *o.SupportSettings.PrivacyPolicyLink = SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK + if s.ConnectionSecurity == nil { + s.ConnectionSecurity = NewString("") } - if !IsSafeLink(o.SupportSettings.AboutLink) { - *o.SupportSettings.AboutLink = "" + if s.BaseDN == nil { + s.BaseDN = NewString("") } - if o.SupportSettings.AboutLink == nil { - o.SupportSettings.AboutLink = new(string) - *o.SupportSettings.AboutLink = SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK + if s.BindUsername == nil { + s.BindUsername = NewString("") } - if !IsSafeLink(o.SupportSettings.HelpLink) { - *o.SupportSettings.HelpLink = "" + if s.BindPassword == nil { + s.BindPassword = NewString("") } - if o.SupportSettings.HelpLink == nil { - o.SupportSettings.HelpLink = new(string) - *o.SupportSettings.HelpLink = SUPPORT_SETTINGS_DEFAULT_HELP_LINK + if s.UserFilter == nil { + s.UserFilter = NewString("") } - if !IsSafeLink(o.SupportSettings.ReportAProblemLink) { - *o.SupportSettings.ReportAProblemLink = "" + if s.FirstNameAttribute == nil { + s.FirstNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE) } - if o.SupportSettings.ReportAProblemLink == nil { - o.SupportSettings.ReportAProblemLink = new(string) - *o.SupportSettings.ReportAProblemLink = SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK + if s.LastNameAttribute == nil { + s.LastNameAttribute = NewString(LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE) } - if !IsSafeLink(o.SupportSettings.AdministratorsGuideLink) { - *o.SupportSettings.AdministratorsGuideLink = "" + if s.EmailAttribute == nil { + s.EmailAttribute = NewString(LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE) } - if o.SupportSettings.AdministratorsGuideLink == nil { - o.SupportSettings.AdministratorsGuideLink = new(string) - *o.SupportSettings.AdministratorsGuideLink = SUPPORT_SETTINGS_DEFAULT_ADMINISTRATORS_GUIDE_LINK + if s.UsernameAttribute == nil { + s.UsernameAttribute = NewString(LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE) } - if !IsSafeLink(o.SupportSettings.TroubleshootingForumLink) { - *o.SupportSettings.TroubleshootingForumLink = "" + if s.NicknameAttribute == nil { + s.NicknameAttribute = NewString(LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE) } - if o.SupportSettings.TroubleshootingForumLink == nil { - o.SupportSettings.TroubleshootingForumLink = new(string) - *o.SupportSettings.TroubleshootingForumLink = SUPPORT_SETTINGS_DEFAULT_TROUBLESHOOTING_FORUM_LINK + if s.IdAttribute == nil { + s.IdAttribute = NewString(LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE) } - if !IsSafeLink(o.SupportSettings.CommercialSupportLink) { - *o.SupportSettings.CommercialSupportLink = "" + if s.PositionAttribute == nil { + s.PositionAttribute = NewString(LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE) } - if o.SupportSettings.CommercialSupportLink == nil { - o.SupportSettings.CommercialSupportLink = new(string) - *o.SupportSettings.CommercialSupportLink = SUPPORT_SETTINGS_DEFAULT_COMMERCIAL_SUPPORT_LINK + if s.SyncIntervalMinutes == nil { + s.SyncIntervalMinutes = NewInt(60) } - if o.SupportSettings.SupportEmail == nil { - o.SupportSettings.SupportEmail = new(string) - *o.SupportSettings.SupportEmail = SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL + if s.SkipCertificateVerification == nil { + s.SkipCertificateVerification = NewBool(false) } - if o.AnnouncementSettings.EnableBanner == nil { - o.AnnouncementSettings.EnableBanner = new(bool) - *o.AnnouncementSettings.EnableBanner = false + if s.QueryTimeout == nil { + s.QueryTimeout = NewInt(60) } - if o.AnnouncementSettings.BannerText == nil { - o.AnnouncementSettings.BannerText = new(string) - *o.AnnouncementSettings.BannerText = "" + if s.MaxPageSize == nil { + s.MaxPageSize = NewInt(0) } - if o.AnnouncementSettings.BannerColor == nil { - o.AnnouncementSettings.BannerColor = new(string) - *o.AnnouncementSettings.BannerColor = ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR + if s.LoginFieldName == nil { + s.LoginFieldName = NewString(LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME) } - if o.AnnouncementSettings.BannerTextColor == nil { - o.AnnouncementSettings.BannerTextColor = new(string) - *o.AnnouncementSettings.BannerTextColor = ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR + if s.LoginButtonColor == nil { + s.LoginButtonColor = NewString("#0000") } - if o.AnnouncementSettings.AllowBannerDismissal == nil { - o.AnnouncementSettings.AllowBannerDismissal = new(bool) - *o.AnnouncementSettings.AllowBannerDismissal = true + if s.LoginButtonBorderColor == nil { + s.LoginButtonBorderColor = NewString("#2389D7") } - if o.LdapSettings.Enable == nil { - o.LdapSettings.Enable = new(bool) - *o.LdapSettings.Enable = false + if s.LoginButtonTextColor == nil { + s.LoginButtonTextColor = NewString("#2389D7") } +} - if o.LdapSettings.LdapServer == nil { - o.LdapSettings.LdapServer = new(string) - *o.LdapSettings.LdapServer = "" - } +type ComplianceSettings struct { + Enable *bool + Directory *string + EnableDaily *bool +} - if o.LdapSettings.LdapPort == nil { - o.LdapSettings.LdapPort = new(int) - *o.LdapSettings.LdapPort = 389 +func (s *ComplianceSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(false) } - if o.LdapSettings.ConnectionSecurity == nil { - o.LdapSettings.ConnectionSecurity = new(string) - *o.LdapSettings.ConnectionSecurity = "" + if s.Directory == nil { + s.Directory = NewString("./data/") } - if o.LdapSettings.BaseDN == nil { - o.LdapSettings.BaseDN = new(string) - *o.LdapSettings.BaseDN = "" + if s.EnableDaily == nil { + s.EnableDaily = NewBool(false) } +} - if o.LdapSettings.BindUsername == nil { - o.LdapSettings.BindUsername = new(string) - *o.LdapSettings.BindUsername = "" - } +type LocalizationSettings struct { + DefaultServerLocale *string + DefaultClientLocale *string + AvailableLocales *string +} - if o.LdapSettings.BindPassword == nil { - o.LdapSettings.BindPassword = new(string) - *o.LdapSettings.BindPassword = "" +func (s *LocalizationSettings) SetDefaults() { + if s.DefaultServerLocale == nil { + s.DefaultServerLocale = NewString(DEFAULT_LOCALE) } - if o.LdapSettings.UserFilter == nil { - o.LdapSettings.UserFilter = new(string) - *o.LdapSettings.UserFilter = "" + if s.DefaultClientLocale == nil { + s.DefaultClientLocale = NewString(DEFAULT_LOCALE) } - if o.LdapSettings.FirstNameAttribute == nil { - o.LdapSettings.FirstNameAttribute = new(string) - *o.LdapSettings.FirstNameAttribute = LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE + if s.AvailableLocales == nil { + s.AvailableLocales = NewString("") } +} - if o.LdapSettings.LastNameAttribute == nil { - o.LdapSettings.LastNameAttribute = new(string) - *o.LdapSettings.LastNameAttribute = LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE - } +type SamlSettings struct { + // Basic + Enable *bool + EnableSyncWithLdap *bool - if o.LdapSettings.EmailAttribute == nil { - o.LdapSettings.EmailAttribute = new(string) - *o.LdapSettings.EmailAttribute = LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE - } + Verify *bool + Encrypt *bool - if o.LdapSettings.UsernameAttribute == nil { - o.LdapSettings.UsernameAttribute = new(string) - *o.LdapSettings.UsernameAttribute = LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE - } + IdpUrl *string + IdpDescriptorUrl *string + AssertionConsumerServiceURL *string - if o.LdapSettings.NicknameAttribute == nil { - o.LdapSettings.NicknameAttribute = new(string) - *o.LdapSettings.NicknameAttribute = LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE - } + IdpCertificateFile *string + PublicCertificateFile *string + PrivateKeyFile *string - if o.LdapSettings.IdAttribute == nil { - o.LdapSettings.IdAttribute = new(string) - *o.LdapSettings.IdAttribute = LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE - } + // User Mapping + FirstNameAttribute *string + LastNameAttribute *string + EmailAttribute *string + UsernameAttribute *string + NicknameAttribute *string + LocaleAttribute *string + PositionAttribute *string - if o.LdapSettings.PositionAttribute == nil { - o.LdapSettings.PositionAttribute = new(string) - *o.LdapSettings.PositionAttribute = LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE - } + LoginButtonText *string - if o.LdapSettings.SyncIntervalMinutes == nil { - o.LdapSettings.SyncIntervalMinutes = new(int) - *o.LdapSettings.SyncIntervalMinutes = 60 - } + LoginButtonColor *string + LoginButtonBorderColor *string + LoginButtonTextColor *string +} - if o.LdapSettings.SkipCertificateVerification == nil { - o.LdapSettings.SkipCertificateVerification = new(bool) - *o.LdapSettings.SkipCertificateVerification = false +func (s *SamlSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(false) } - if o.LdapSettings.QueryTimeout == nil { - o.LdapSettings.QueryTimeout = new(int) - *o.LdapSettings.QueryTimeout = 60 + if s.EnableSyncWithLdap == nil { + s.EnableSyncWithLdap = NewBool(false) } - if o.LdapSettings.MaxPageSize == nil { - o.LdapSettings.MaxPageSize = new(int) - *o.LdapSettings.MaxPageSize = 0 + if s.Verify == nil { + s.Verify = NewBool(true) } - if o.LdapSettings.LoginFieldName == nil { - o.LdapSettings.LoginFieldName = new(string) - *o.LdapSettings.LoginFieldName = LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME + if s.Encrypt == nil { + s.Encrypt = NewBool(true) } - if o.ServiceSettings.SessionLengthWebInDays == nil { - o.ServiceSettings.SessionLengthWebInDays = new(int) - *o.ServiceSettings.SessionLengthWebInDays = 30 + if s.IdpUrl == nil { + s.IdpUrl = NewString("") } - if o.ServiceSettings.SessionLengthMobileInDays == nil { - o.ServiceSettings.SessionLengthMobileInDays = new(int) - *o.ServiceSettings.SessionLengthMobileInDays = 30 + if s.IdpDescriptorUrl == nil { + s.IdpDescriptorUrl = NewString("") } - if o.ServiceSettings.SessionLengthSSOInDays == nil { - o.ServiceSettings.SessionLengthSSOInDays = new(int) - *o.ServiceSettings.SessionLengthSSOInDays = 30 + if s.IdpCertificateFile == nil { + s.IdpCertificateFile = NewString("") } - if o.ServiceSettings.SessionCacheInMinutes == nil { - o.ServiceSettings.SessionCacheInMinutes = new(int) - *o.ServiceSettings.SessionCacheInMinutes = 10 + if s.PublicCertificateFile == nil { + s.PublicCertificateFile = NewString("") } - if o.ServiceSettings.EnableCommands == nil { - o.ServiceSettings.EnableCommands = new(bool) - *o.ServiceSettings.EnableCommands = false + if s.PrivateKeyFile == nil { + s.PrivateKeyFile = NewString("") } - if o.ServiceSettings.EnableOnlyAdminIntegrations == nil { - o.ServiceSettings.EnableOnlyAdminIntegrations = new(bool) - *o.ServiceSettings.EnableOnlyAdminIntegrations = true + if s.AssertionConsumerServiceURL == nil { + s.AssertionConsumerServiceURL = NewString("") } - if o.ServiceSettings.WebsocketPort == nil { - o.ServiceSettings.WebsocketPort = new(int) - *o.ServiceSettings.WebsocketPort = 80 + if s.LoginButtonText == nil || *s.LoginButtonText == "" { + s.LoginButtonText = NewString(USER_AUTH_SERVICE_SAML_TEXT) } - if o.ServiceSettings.WebsocketSecurePort == nil { - o.ServiceSettings.WebsocketSecurePort = new(int) - *o.ServiceSettings.WebsocketSecurePort = 443 + if s.FirstNameAttribute == nil { + s.FirstNameAttribute = NewString(SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE) } - if o.ServiceSettings.AllowCorsFrom == nil { - o.ServiceSettings.AllowCorsFrom = new(string) - *o.ServiceSettings.AllowCorsFrom = SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM + if s.LastNameAttribute == nil { + s.LastNameAttribute = NewString(SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE) } - if o.ServiceSettings.WebserverMode == nil { - o.ServiceSettings.WebserverMode = new(string) - *o.ServiceSettings.WebserverMode = "gzip" - } else if *o.ServiceSettings.WebserverMode == "regular" { - *o.ServiceSettings.WebserverMode = "gzip" + if s.EmailAttribute == nil { + s.EmailAttribute = NewString(SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE) } - if o.ServiceSettings.EnableCustomEmoji == nil { - o.ServiceSettings.EnableCustomEmoji = new(bool) - *o.ServiceSettings.EnableCustomEmoji = false + if s.UsernameAttribute == nil { + s.UsernameAttribute = NewString(SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE) } - if o.ServiceSettings.EnableEmojiPicker == nil { - o.ServiceSettings.EnableEmojiPicker = new(bool) - *o.ServiceSettings.EnableEmojiPicker = true + if s.NicknameAttribute == nil { + s.NicknameAttribute = NewString(SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE) } - if o.ServiceSettings.RestrictCustomEmojiCreation == nil { - o.ServiceSettings.RestrictCustomEmojiCreation = new(string) - *o.ServiceSettings.RestrictCustomEmojiCreation = RESTRICT_EMOJI_CREATION_ALL + if s.PositionAttribute == nil { + s.PositionAttribute = NewString(SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE) } - if o.ServiceSettings.RestrictPostDelete == nil { - o.ServiceSettings.RestrictPostDelete = new(string) - *o.ServiceSettings.RestrictPostDelete = PERMISSIONS_DELETE_POST_ALL + if s.LocaleAttribute == nil { + s.LocaleAttribute = NewString(SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE) } - if o.ServiceSettings.AllowEditPost == nil { - o.ServiceSettings.AllowEditPost = new(string) - *o.ServiceSettings.AllowEditPost = ALLOW_EDIT_POST_ALWAYS + if s.LoginButtonColor == nil { + s.LoginButtonColor = NewString("#34a28b") } - if o.ServiceSettings.PostEditTimeLimit == nil { - o.ServiceSettings.PostEditTimeLimit = new(int) - *o.ServiceSettings.PostEditTimeLimit = 300 + if s.LoginButtonBorderColor == nil { + s.LoginButtonBorderColor = NewString("#2389D7") } - if o.ClusterSettings.Enable == nil { - o.ClusterSettings.Enable = new(bool) - *o.ClusterSettings.Enable = false + if s.LoginButtonTextColor == nil { + s.LoginButtonTextColor = NewString("#ffffff") } +} - if o.ClusterSettings.ClusterName == nil { - o.ClusterSettings.ClusterName = new(string) - *o.ClusterSettings.ClusterName = "" - } +type NativeAppSettings struct { + AppDownloadLink *string + AndroidAppDownloadLink *string + IosAppDownloadLink *string +} - if o.ClusterSettings.OverrideHostname == nil { - o.ClusterSettings.OverrideHostname = new(string) - *o.ClusterSettings.OverrideHostname = "" +func (s *NativeAppSettings) SetDefaults() { + if s.AppDownloadLink == nil { + s.AppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK) } - if o.ClusterSettings.UseIpAddress == nil { - o.ClusterSettings.UseIpAddress = new(bool) - *o.ClusterSettings.UseIpAddress = true + if s.AndroidAppDownloadLink == nil { + s.AndroidAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK) } - if o.ClusterSettings.UseExperimentalGossip == nil { - o.ClusterSettings.UseExperimentalGossip = new(bool) - *o.ClusterSettings.UseExperimentalGossip = false + if s.IosAppDownloadLink == nil { + s.IosAppDownloadLink = NewString(NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK) } +} - if o.ClusterSettings.ReadOnlyConfig == nil { - o.ClusterSettings.ReadOnlyConfig = new(bool) - *o.ClusterSettings.ReadOnlyConfig = true - } +type WebrtcSettings struct { + Enable *bool + GatewayWebsocketUrl *string + GatewayAdminUrl *string + GatewayAdminSecret *string + StunURI *string + TurnURI *string + TurnUsername *string + TurnSharedKey *string +} - if o.ClusterSettings.GossipPort == nil { - o.ClusterSettings.GossipPort = new(int) - *o.ClusterSettings.GossipPort = 8074 +func (s *WebrtcSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(false) } - if o.ClusterSettings.StreamingPort == nil { - o.ClusterSettings.StreamingPort = new(int) - *o.ClusterSettings.StreamingPort = 8075 + if s.GatewayWebsocketUrl == nil { + s.GatewayWebsocketUrl = NewString("") } - if o.MetricsSettings.ListenAddress == nil { - o.MetricsSettings.ListenAddress = new(string) - *o.MetricsSettings.ListenAddress = ":8067" + if s.GatewayAdminUrl == nil { + s.GatewayAdminUrl = NewString("") } - if o.MetricsSettings.Enable == nil { - o.MetricsSettings.Enable = new(bool) - *o.MetricsSettings.Enable = false + if s.GatewayAdminSecret == nil { + s.GatewayAdminSecret = NewString("") } - if o.AnalyticsSettings.MaxUsersForStatistics == nil { - o.AnalyticsSettings.MaxUsersForStatistics = new(int) - *o.AnalyticsSettings.MaxUsersForStatistics = ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS + if s.StunURI == nil { + s.StunURI = NewString(WEBRTC_SETTINGS_DEFAULT_STUN_URI) } - if o.ComplianceSettings.Enable == nil { - o.ComplianceSettings.Enable = new(bool) - *o.ComplianceSettings.Enable = false + if s.TurnURI == nil { + s.TurnURI = NewString(WEBRTC_SETTINGS_DEFAULT_TURN_URI) } - if o.ComplianceSettings.Directory == nil { - o.ComplianceSettings.Directory = new(string) - *o.ComplianceSettings.Directory = "./data/" + if s.TurnUsername == nil { + s.TurnUsername = NewString("") } - if o.ComplianceSettings.EnableDaily == nil { - o.ComplianceSettings.EnableDaily = new(bool) - *o.ComplianceSettings.EnableDaily = false + if s.TurnSharedKey == nil { + s.TurnSharedKey = NewString("") } +} + +type ElasticsearchSettings struct { + ConnectionUrl *string + Username *string + Password *string + EnableIndexing *bool + EnableSearching *bool + Sniff *bool + PostIndexReplicas *int + PostIndexShards *int + AggregatePostsAfterDays *int + PostsAggregatorJobStartTime *string + IndexPrefix *string + LiveIndexingBatchSize *int + BulkIndexingTimeWindowSeconds *int + RequestTimeoutSeconds *int +} - if o.LocalizationSettings.DefaultServerLocale == nil { - o.LocalizationSettings.DefaultServerLocale = new(string) - *o.LocalizationSettings.DefaultServerLocale = DEFAULT_LOCALE +func (s *ElasticsearchSettings) SetDefaults() { + if s.ConnectionUrl == nil { + s.ConnectionUrl = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL) } - if o.LocalizationSettings.DefaultClientLocale == nil { - o.LocalizationSettings.DefaultClientLocale = new(string) - *o.LocalizationSettings.DefaultClientLocale = DEFAULT_LOCALE + if s.Username == nil { + s.Username = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME) } - if o.LocalizationSettings.AvailableLocales == nil { - o.LocalizationSettings.AvailableLocales = new(string) - *o.LocalizationSettings.AvailableLocales = "" + if s.Password == nil { + s.Password = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD) } - if o.LogSettings.EnableDiagnostics == nil { - o.LogSettings.EnableDiagnostics = new(bool) - *o.LogSettings.EnableDiagnostics = true + if s.EnableIndexing == nil { + s.EnableIndexing = NewBool(false) } - if o.SamlSettings.Enable == nil { - o.SamlSettings.Enable = new(bool) - *o.SamlSettings.Enable = false + if s.EnableSearching == nil { + s.EnableSearching = NewBool(false) } - if o.SamlSettings.Verify == nil { - o.SamlSettings.Verify = new(bool) - *o.SamlSettings.Verify = true + if s.Sniff == nil { + s.Sniff = NewBool(true) } - if o.SamlSettings.Encrypt == nil { - o.SamlSettings.Encrypt = new(bool) - *o.SamlSettings.Encrypt = true + if s.PostIndexReplicas == nil { + s.PostIndexReplicas = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS) } - if o.SamlSettings.IdpUrl == nil { - o.SamlSettings.IdpUrl = new(string) - *o.SamlSettings.IdpUrl = "" + if s.PostIndexShards == nil { + s.PostIndexShards = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS) } - if o.SamlSettings.IdpDescriptorUrl == nil { - o.SamlSettings.IdpDescriptorUrl = new(string) - *o.SamlSettings.IdpDescriptorUrl = "" + if s.AggregatePostsAfterDays == nil { + s.AggregatePostsAfterDays = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS) } - if o.SamlSettings.IdpCertificateFile == nil { - o.SamlSettings.IdpCertificateFile = new(string) - *o.SamlSettings.IdpCertificateFile = "" + if s.PostsAggregatorJobStartTime == nil { + s.PostsAggregatorJobStartTime = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_POSTS_AGGREGATOR_JOB_START_TIME) } - if o.SamlSettings.PublicCertificateFile == nil { - o.SamlSettings.PublicCertificateFile = new(string) - *o.SamlSettings.PublicCertificateFile = "" + if s.IndexPrefix == nil { + s.IndexPrefix = NewString(ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX) } - if o.SamlSettings.PrivateKeyFile == nil { - o.SamlSettings.PrivateKeyFile = new(string) - *o.SamlSettings.PrivateKeyFile = "" + if s.LiveIndexingBatchSize == nil { + s.LiveIndexingBatchSize = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_LIVE_INDEXING_BATCH_SIZE) } - if o.SamlSettings.AssertionConsumerServiceURL == nil { - o.SamlSettings.AssertionConsumerServiceURL = new(string) - *o.SamlSettings.AssertionConsumerServiceURL = "" + if s.BulkIndexingTimeWindowSeconds == nil { + s.BulkIndexingTimeWindowSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_BULK_INDEXING_TIME_WINDOW_SECONDS) } - if o.SamlSettings.LoginButtonText == nil || *o.SamlSettings.LoginButtonText == "" { - o.SamlSettings.LoginButtonText = new(string) - *o.SamlSettings.LoginButtonText = USER_AUTH_SERVICE_SAML_TEXT + if s.RequestTimeoutSeconds == nil { + s.RequestTimeoutSeconds = NewInt(ELASTICSEARCH_SETTINGS_DEFAULT_REQUEST_TIMEOUT_SECONDS) } +} + +type DataRetentionSettings struct { + EnableMessageDeletion *bool + EnableFileDeletion *bool + MessageRetentionDays *int + FileRetentionDays *int + DeletionJobStartTime *string +} - if o.SamlSettings.FirstNameAttribute == nil { - o.SamlSettings.FirstNameAttribute = new(string) - *o.SamlSettings.FirstNameAttribute = SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE +func (s *DataRetentionSettings) SetDefaults() { + if s.EnableMessageDeletion == nil { + s.EnableMessageDeletion = NewBool(false) } - if o.SamlSettings.LastNameAttribute == nil { - o.SamlSettings.LastNameAttribute = new(string) - *o.SamlSettings.LastNameAttribute = SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE + if s.EnableFileDeletion == nil { + s.EnableFileDeletion = NewBool(false) } - if o.SamlSettings.EmailAttribute == nil { - o.SamlSettings.EmailAttribute = new(string) - *o.SamlSettings.EmailAttribute = SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE + if s.MessageRetentionDays == nil { + s.MessageRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS) } - if o.SamlSettings.UsernameAttribute == nil { - o.SamlSettings.UsernameAttribute = new(string) - *o.SamlSettings.UsernameAttribute = SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE + if s.FileRetentionDays == nil { + s.FileRetentionDays = NewInt(DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS) } - if o.SamlSettings.NicknameAttribute == nil { - o.SamlSettings.NicknameAttribute = new(string) - *o.SamlSettings.NicknameAttribute = SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE + if s.DeletionJobStartTime == nil { + s.DeletionJobStartTime = NewString(DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME) } +} + +type JobSettings struct { + RunJobs *bool + RunScheduler *bool +} - if o.SamlSettings.PositionAttribute == nil { - o.SamlSettings.PositionAttribute = new(string) - *o.SamlSettings.PositionAttribute = SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE +func (s *JobSettings) SetDefaults() { + if s.RunJobs == nil { + s.RunJobs = NewBool(true) } - if o.SamlSettings.LocaleAttribute == nil { - o.SamlSettings.LocaleAttribute = new(string) - *o.SamlSettings.LocaleAttribute = SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE + if s.RunScheduler == nil { + s.RunScheduler = NewBool(true) } +} - if o.TeamSettings.TeammateNameDisplay == nil { - o.TeamSettings.TeammateNameDisplay = new(string) - *o.TeamSettings.TeammateNameDisplay = SHOW_USERNAME +type PluginState struct { + Enable bool +} - if *o.SamlSettings.Enable || *o.LdapSettings.Enable { - *o.TeamSettings.TeammateNameDisplay = SHOW_FULLNAME - } +type PluginSettings struct { + Enable *bool + EnableUploads *bool + Directory *string + ClientDirectory *string + Plugins map[string]interface{} + PluginStates map[string]*PluginState +} + +func (s *PluginSettings) SetDefaults() { + if s.Enable == nil { + s.Enable = NewBool(true) } - if o.NativeAppSettings.AppDownloadLink == nil { - o.NativeAppSettings.AppDownloadLink = new(string) - *o.NativeAppSettings.AppDownloadLink = NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK + if s.EnableUploads == nil { + s.EnableUploads = NewBool(false) } - if o.NativeAppSettings.AndroidAppDownloadLink == nil { - o.NativeAppSettings.AndroidAppDownloadLink = new(string) - *o.NativeAppSettings.AndroidAppDownloadLink = NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK + if s.Directory == nil { + s.Directory = NewString(PLUGIN_SETTINGS_DEFAULT_DIRECTORY) } - if o.NativeAppSettings.IosAppDownloadLink == nil { - o.NativeAppSettings.IosAppDownloadLink = new(string) - *o.NativeAppSettings.IosAppDownloadLink = NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK + if *s.Directory == "" { + *s.Directory = PLUGIN_SETTINGS_DEFAULT_DIRECTORY } - if o.RateLimitSettings.Enable == nil { - o.RateLimitSettings.Enable = new(bool) - *o.RateLimitSettings.Enable = false + if s.ClientDirectory == nil { + s.ClientDirectory = NewString(PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY) } - if o.ServiceSettings.GoroutineHealthThreshold == nil { - o.ServiceSettings.GoroutineHealthThreshold = new(int) - *o.ServiceSettings.GoroutineHealthThreshold = -1 + if *s.ClientDirectory == "" { + *s.ClientDirectory = PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY } - if o.RateLimitSettings.MaxBurst == nil { - o.RateLimitSettings.MaxBurst = new(int) - *o.RateLimitSettings.MaxBurst = 100 + if s.Plugins == nil { + s.Plugins = make(map[string]interface{}) } - if o.ServiceSettings.ConnectionSecurity == nil { - o.ServiceSettings.ConnectionSecurity = new(string) - *o.ServiceSettings.ConnectionSecurity = "" + if s.PluginStates == nil { + s.PluginStates = make(map[string]*PluginState) } +} + +type MessageExportSettings struct { + EnableExport *bool + DailyRunTime *string + ExportFromTimestamp *int64 + BatchSize *int +} - if o.ServiceSettings.TLSKeyFile == nil { - o.ServiceSettings.TLSKeyFile = new(string) - *o.ServiceSettings.TLSKeyFile = SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE +func (s *MessageExportSettings) SetDefaults() { + if s.EnableExport == nil { + s.EnableExport = NewBool(false) } - if o.ServiceSettings.TLSCertFile == nil { - o.ServiceSettings.TLSCertFile = new(string) - *o.ServiceSettings.TLSCertFile = SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE + if s.DailyRunTime == nil { + s.DailyRunTime = NewString("01:00") } - if o.ServiceSettings.UseLetsEncrypt == nil { - o.ServiceSettings.UseLetsEncrypt = new(bool) - *o.ServiceSettings.UseLetsEncrypt = false + if s.ExportFromTimestamp == nil { + s.ExportFromTimestamp = NewInt64(0) } - if o.ServiceSettings.LetsEncryptCertificateCacheFile == nil { - o.ServiceSettings.LetsEncryptCertificateCacheFile = new(string) - *o.ServiceSettings.LetsEncryptCertificateCacheFile = "./config/letsencrypt.cache" + if s.EnableExport != nil && *s.EnableExport && *s.ExportFromTimestamp == int64(0) { + // when the feature is enabled via the System Console, use the current timestamp as the start time for future exports + s.ExportFromTimestamp = NewInt64(GetMillis()) + } else if s.EnableExport != nil && !*s.EnableExport { + // when the feature is disabled, reset the timestamp so that the timestamp will be set if the feature is re-enabled + s.ExportFromTimestamp = NewInt64(0) } - if o.ServiceSettings.ReadTimeout == nil { - o.ServiceSettings.ReadTimeout = new(int) - *o.ServiceSettings.ReadTimeout = SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT + if s.BatchSize == nil { + s.BatchSize = NewInt(10000) } +} + +type ConfigFunc func() *Config + +type Config struct { + ServiceSettings ServiceSettings + TeamSettings TeamSettings + ClientRequirements ClientRequirements + SqlSettings SqlSettings + LogSettings LogSettings + PasswordSettings PasswordSettings + FileSettings FileSettings + EmailSettings EmailSettings + RateLimitSettings RateLimitSettings + PrivacySettings PrivacySettings + SupportSettings SupportSettings + AnnouncementSettings AnnouncementSettings + ThemeSettings ThemeSettings + GitLabSettings SSOSettings + GoogleSettings SSOSettings + Office365Settings SSOSettings + LdapSettings LdapSettings + ComplianceSettings ComplianceSettings + LocalizationSettings LocalizationSettings + SamlSettings SamlSettings + NativeAppSettings NativeAppSettings + ClusterSettings ClusterSettings + MetricsSettings MetricsSettings + AnalyticsSettings AnalyticsSettings + WebrtcSettings WebrtcSettings + ElasticsearchSettings ElasticsearchSettings + DataRetentionSettings DataRetentionSettings + MessageExportSettings MessageExportSettings + JobSettings JobSettings + PluginSettings PluginSettings +} - if o.ServiceSettings.WriteTimeout == nil { - o.ServiceSettings.WriteTimeout = new(int) - *o.ServiceSettings.WriteTimeout = SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT +func (o *Config) Clone() *Config { + var ret Config + if err := json.Unmarshal([]byte(o.ToJson()), &ret); err != nil { + panic(err) } + return &ret +} - if o.ServiceSettings.Forward80To443 == nil { - o.ServiceSettings.Forward80To443 = new(bool) - *o.ServiceSettings.Forward80To443 = false +func (o *Config) ToJson() string { + b, err := json.Marshal(o) + if err != nil { + return "" + } else { + return string(b) } +} - if o.MetricsSettings.BlockProfileRate == nil { - o.MetricsSettings.BlockProfileRate = new(int) - *o.MetricsSettings.BlockProfileRate = 0 +func (o *Config) GetSSOService(service string) *SSOSettings { + switch service { + case SERVICE_GITLAB: + return &o.GitLabSettings + case SERVICE_GOOGLE: + return &o.GoogleSettings + case SERVICE_OFFICE365: + return &o.Office365Settings } - if o.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds == nil { - o.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds = new(int64) - *o.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds = 5000 + return nil +} + +func ConfigFromJson(data io.Reader) *Config { + decoder := json.NewDecoder(data) + var o Config + err := decoder.Decode(&o) + if err == nil { + return &o + } else { + return nil } +} + +func (o *Config) SetDefaults() { + o.LdapSettings.SetDefaults() + o.SamlSettings.SetDefaults() - if o.ServiceSettings.EnablePostSearch == nil { - o.ServiceSettings.EnablePostSearch = new(bool) - *o.ServiceSettings.EnablePostSearch = true + if o.TeamSettings.TeammateNameDisplay == nil { + o.TeamSettings.TeammateNameDisplay = NewString(SHOW_USERNAME) + + if *o.SamlSettings.Enable || *o.LdapSettings.Enable { + *o.TeamSettings.TeammateNameDisplay = SHOW_FULLNAME + } } - if o.ServiceSettings.EnableUserTypingMessages == nil { - o.ServiceSettings.EnableUserTypingMessages = new(bool) - *o.ServiceSettings.EnableUserTypingMessages = true + o.SqlSettings.SetDefaults() + o.FileSettings.SetDefaults() + o.EmailSettings.SetDefaults() + o.ServiceSettings.SetDefaults() + o.PasswordSettings.SetDefaults() + o.TeamSettings.SetDefaults() + o.MetricsSettings.SetDefaults() + o.SupportSettings.SetDefaults() + o.AnnouncementSettings.SetDefaults() + o.ThemeSettings.SetDefaults() + o.ClusterSettings.SetDefaults() + o.PluginSettings.SetDefaults() + o.AnalyticsSettings.SetDefaults() + o.ComplianceSettings.SetDefaults() + o.LocalizationSettings.SetDefaults() + o.ElasticsearchSettings.SetDefaults() + o.NativeAppSettings.SetDefaults() + o.DataRetentionSettings.SetDefaults() + o.RateLimitSettings.SetDefaults() + o.LogSettings.SetDefaults() + o.JobSettings.SetDefaults() + o.WebrtcSettings.SetDefaults() + o.MessageExportSettings.SetDefaults() +} + +func (o *Config) IsValid() *AppError { + if len(*o.ServiceSettings.SiteURL) == 0 && *o.EmailSettings.EnableEmailBatching { + return NewAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "", http.StatusBadRequest) } - if o.ServiceSettings.EnableChannelViewedMessages == nil { - o.ServiceSettings.EnableChannelViewedMessages = new(bool) - *o.ServiceSettings.EnableChannelViewedMessages = true + if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching { + return NewAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "", http.StatusBadRequest) } - if o.ServiceSettings.EnableUserStatuses == nil { - o.ServiceSettings.EnableUserStatuses = new(bool) - *o.ServiceSettings.EnableUserStatuses = true + if err := o.TeamSettings.isValid(); err != nil { + return err } - if o.ServiceSettings.ClusterLogTimeoutMilliseconds == nil { - o.ServiceSettings.ClusterLogTimeoutMilliseconds = new(int) - *o.ServiceSettings.ClusterLogTimeoutMilliseconds = 2000 + if err := o.SqlSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.ConnectionUrl == nil { - o.ElasticsearchSettings.ConnectionUrl = new(string) - *o.ElasticsearchSettings.ConnectionUrl = ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL + if err := o.FileSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.Username == nil { - o.ElasticsearchSettings.Username = new(string) - *o.ElasticsearchSettings.Username = ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME + if err := o.EmailSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.Password == nil { - o.ElasticsearchSettings.Password = new(string) - *o.ElasticsearchSettings.Password = ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD + if err := o.LdapSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.EnableIndexing == nil { - o.ElasticsearchSettings.EnableIndexing = new(bool) - *o.ElasticsearchSettings.EnableIndexing = false + if err := o.SamlSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.EnableSearching == nil { - o.ElasticsearchSettings.EnableSearching = new(bool) - *o.ElasticsearchSettings.EnableSearching = false + if *o.PasswordSettings.MinimumLength < PASSWORD_MINIMUM_LENGTH || *o.PasswordSettings.MinimumLength > PASSWORD_MAXIMUM_LENGTH { + 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) } - if o.ElasticsearchSettings.Sniff == nil { - o.ElasticsearchSettings.Sniff = new(bool) - *o.ElasticsearchSettings.Sniff = true + if err := o.RateLimitSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.PostIndexReplicas == nil { - o.ElasticsearchSettings.PostIndexReplicas = new(int) - *o.ElasticsearchSettings.PostIndexReplicas = ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS + if err := o.WebrtcSettings.isValid(); err != nil { + return err } - if o.ElasticsearchSettings.PostIndexShards == nil { - o.ElasticsearchSettings.PostIndexShards = new(int) - *o.ElasticsearchSettings.PostIndexShards = ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS + if err := o.ServiceSettings.isValid(); err != nil { + return err } - if o.DataRetentionSettings.Enable == nil { - o.DataRetentionSettings.Enable = new(bool) - *o.DataRetentionSettings.Enable = false + if err := o.ElasticsearchSettings.isValid(); err != nil { + return err } - if o.JobSettings.RunJobs == nil { - o.JobSettings.RunJobs = new(bool) - *o.JobSettings.RunJobs = true + if err := o.DataRetentionSettings.isValid(); err != nil { + return err } - if o.JobSettings.RunScheduler == nil { - o.JobSettings.RunScheduler = new(bool) - *o.JobSettings.RunScheduler = true + if err := o.LocalizationSettings.isValid(); err != nil { + return err } - if o.PluginSettings.Plugins == nil { - o.PluginSettings.Plugins = make(map[string]interface{}) + if err := o.MessageExportSettings.isValid(o.FileSettings); err != nil { + return err } - o.defaultWebrtcSettings() + return nil } -func (o *Config) IsValid() *AppError { - - if o.ServiceSettings.MaximumLoginAttempts <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "") +func (ts *TeamSettings) isValid() *AppError { + if *ts.MaxUsersPerTeam <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "", http.StatusBadRequest) } - if len(*o.ServiceSettings.SiteURL) != 0 { - if _, err := url.ParseRequestURI(*o.ServiceSettings.SiteURL); err != nil { - return NewLocAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "") - } + if *ts.MaxChannelsPerTeam <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.max_channels.app_error", nil, "", http.StatusBadRequest) } - if len(o.ServiceSettings.ListenAddress) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "") + if *ts.MaxNotificationsPerChannel <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.max_notify_per_channel.app_error", nil, "", http.StatusBadRequest) } - if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching { - return NewLocAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "") + if !(*ts.RestrictDirectMessage == DIRECT_MESSAGE_ANY || *ts.RestrictDirectMessage == DIRECT_MESSAGE_TEAM) { + return NewAppError("Config.IsValid", "model.config.is_valid.restrict_direct_message.app_error", nil, "", http.StatusBadRequest) } - if len(*o.ServiceSettings.SiteURL) == 0 && *o.EmailSettings.EnableEmailBatching { - return NewLocAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "") + if !(*ts.TeammateNameDisplay == SHOW_FULLNAME || *ts.TeammateNameDisplay == SHOW_NICKNAME_FULLNAME || *ts.TeammateNameDisplay == SHOW_USERNAME) { + return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest) } - if o.TeamSettings.MaxUsersPerTeam <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "") + if len(ts.SiteName) > SITENAME_MAX_LENGTH { + return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest) } - if *o.TeamSettings.MaxChannelsPerTeam <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.max_channels.app_error", nil, "") - } + return nil +} - if *o.TeamSettings.MaxNotificationsPerChannel <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.max_notify_per_channel.app_error", nil, "") +func (ss *SqlSettings) isValid() *AppError { + if len(ss.AtRestEncryptKey) < 32 { + return NewAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "", http.StatusBadRequest) } - if !(*o.TeamSettings.RestrictDirectMessage == DIRECT_MESSAGE_ANY || *o.TeamSettings.RestrictDirectMessage == DIRECT_MESSAGE_TEAM) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.restrict_direct_message.app_error", nil, "") + if !(*ss.DriverName == DATABASE_DRIVER_MYSQL || *ss.DriverName == DATABASE_DRIVER_POSTGRES) { + return NewAppError("Config.IsValid", "model.config.is_valid.sql_driver.app_error", nil, "", http.StatusBadRequest) } - if !(*o.TeamSettings.TeammateNameDisplay == SHOW_FULLNAME || *o.TeamSettings.TeammateNameDisplay == SHOW_NICKNAME_FULLNAME || *o.TeamSettings.TeammateNameDisplay == SHOW_USERNAME) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "") + if *ss.MaxIdleConns <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "", http.StatusBadRequest) } - if len(o.SqlSettings.AtRestEncryptKey) < 32 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "") + if *ss.QueryTimeout <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.sql_query_timeout.app_error", nil, "", http.StatusBadRequest) } - 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 len(*ss.DataSource) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "", http.StatusBadRequest) } - if o.SqlSettings.MaxIdleConns <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "") + if *ss.MaxOpenConns <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "", http.StatusBadRequest) } - if *o.SqlSettings.QueryTimeout <= 0 { - return NewAppError("Config.IsValid", "model.config.is_valid.sql_query_timeout.app_error", nil, "", http.StatusBadRequest) - } + return nil +} - if len(o.SqlSettings.DataSource) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "") +func (fs *FileSettings) isValid() *AppError { + if *fs.MaxFileSize <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "", http.StatusBadRequest) } - if o.SqlSettings.MaxOpenConns <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "") + if !(*fs.DriverName == IMAGE_DRIVER_LOCAL || *fs.DriverName == IMAGE_DRIVER_S3) { + return NewAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "", http.StatusBadRequest) } - if *o.FileSettings.MaxFileSize <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "") + if len(*fs.PublicLinkSalt) < 32 { + return NewAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "", http.StatusBadRequest) } - 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, "") - } + return nil +} - if len(*o.FileSettings.PublicLinkSalt) < 32 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "") +func (es *EmailSettings) isValid() *AppError { + if !(es.ConnectionSecurity == CONN_SECURITY_NONE || es.ConnectionSecurity == CONN_SECURITY_TLS || es.ConnectionSecurity == CONN_SECURITY_STARTTLS || es.ConnectionSecurity == CONN_SECURITY_PLAIN) { + return NewAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "", http.StatusBadRequest) } - if !(o.EmailSettings.ConnectionSecurity == CONN_SECURITY_NONE || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_TLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_STARTTLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_PLAIN) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "") + if len(es.InviteSalt) < 32 { + return NewAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "", http.StatusBadRequest) } - if len(o.EmailSettings.InviteSalt) < 32 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "") + if *es.EmailBatchingBufferSize <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_buffer_size.app_error", nil, "", http.StatusBadRequest) } - if *o.EmailSettings.EmailBatchingBufferSize <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.email_batching_buffer_size.app_error", nil, "") + if *es.EmailBatchingInterval < 30 { + return NewAppError("Config.IsValid", "model.config.is_valid.email_batching_interval.app_error", nil, "", http.StatusBadRequest) } - if *o.EmailSettings.EmailBatchingInterval < 30 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.email_batching_interval.app_error", nil, "") + if !(*es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_FULL || *es.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_GENERIC) { + return NewAppError("Config.IsValid", "model.config.is_valid.email_notification_contents_type.app_error", nil, "", http.StatusBadRequest) } - if !(*o.EmailSettings.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_FULL || *o.EmailSettings.EmailNotificationContentsType == EMAIL_NOTIFICATION_CONTENTS_GENERIC) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.email_notification_contents_type.app_error", nil, "") + return nil +} + +func (rls *RateLimitSettings) isValid() *AppError { + if *rls.MemoryStoreSize <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "", http.StatusBadRequest) } - if o.RateLimitSettings.MemoryStoreSize <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "") + if *rls.PerSec <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "", http.StatusBadRequest) } - if o.RateLimitSettings.PerSec <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "") + if *rls.MaxBurst <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.max_burst.app_error", nil, "", http.StatusBadRequest) } - if !(*o.LdapSettings.ConnectionSecurity == CONN_SECURITY_NONE || *o.LdapSettings.ConnectionSecurity == CONN_SECURITY_TLS || *o.LdapSettings.ConnectionSecurity == CONN_SECURITY_STARTTLS) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_security.app_error", nil, "") + return nil +} + +func (ls *LdapSettings) isValid() *AppError { + if !(*ls.ConnectionSecurity == CONN_SECURITY_NONE || *ls.ConnectionSecurity == CONN_SECURITY_TLS || *ls.ConnectionSecurity == CONN_SECURITY_STARTTLS) { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_security.app_error", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.SyncIntervalMinutes <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_sync_interval.app_error", nil, "") + if *ls.SyncIntervalMinutes <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_sync_interval.app_error", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.MaxPageSize < 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_max_page_size.app_error", nil, "") + if *ls.MaxPageSize < 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_max_page_size.app_error", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.Enable { - if *o.LdapSettings.LdapServer == "" { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_server", nil, "") + if *ls.Enable { + if *ls.LdapServer == "" { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_server", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.BaseDN == "" { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_basedn", nil, "") + if *ls.BaseDN == "" { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_basedn", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.EmailAttribute == "" { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_email", nil, "") + if *ls.EmailAttribute == "" { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_email", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.UsernameAttribute == "" { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_username", nil, "") + if *ls.UsernameAttribute == "" { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_username", nil, "", http.StatusBadRequest) } - if *o.LdapSettings.IdAttribute == "" { - return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_id", nil, "") + if *ls.IdAttribute == "" { + return NewAppError("Config.IsValid", "model.config.is_valid.ldap_id", nil, "", http.StatusBadRequest) } } - if *o.SamlSettings.Enable { - if len(*o.SamlSettings.IdpUrl) == 0 || !IsValidHttpUrl(*o.SamlSettings.IdpUrl) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "") + return nil +} + +func (ss *SamlSettings) isValid() *AppError { + if *ss.Enable { + if len(*ss.IdpUrl) == 0 || !IsValidHttpUrl(*ss.IdpUrl) { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "", http.StatusBadRequest) } - if len(*o.SamlSettings.IdpDescriptorUrl) == 0 || !IsValidHttpUrl(*o.SamlSettings.IdpDescriptorUrl) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_idp_descriptor_url.app_error", nil, "") + if len(*ss.IdpDescriptorUrl) == 0 || !IsValidHttpUrl(*ss.IdpDescriptorUrl) { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_descriptor_url.app_error", nil, "", http.StatusBadRequest) } - if len(*o.SamlSettings.IdpCertificateFile) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_idp_cert.app_error", nil, "") + if len(*ss.IdpCertificateFile) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_idp_cert.app_error", nil, "", http.StatusBadRequest) } - if len(*o.SamlSettings.EmailAttribute) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "") + if len(*ss.EmailAttribute) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest) } - if len(*o.SamlSettings.UsernameAttribute) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "") + if len(*ss.UsernameAttribute) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "", http.StatusBadRequest) } - if *o.SamlSettings.Verify { - if len(*o.SamlSettings.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*o.SamlSettings.AssertionConsumerServiceURL) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "") + if *ss.Verify { + if len(*ss.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*ss.AssertionConsumerServiceURL) { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "", http.StatusBadRequest) } } - if *o.SamlSettings.Encrypt { - if len(*o.SamlSettings.PrivateKeyFile) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_private_key.app_error", nil, "") + if *ss.Encrypt { + if len(*ss.PrivateKeyFile) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_private_key.app_error", nil, "", http.StatusBadRequest) } - if len(*o.SamlSettings.PublicCertificateFile) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_public_cert.app_error", nil, "") + if len(*ss.PublicCertificateFile) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_public_cert.app_error", nil, "", http.StatusBadRequest) } } - if len(*o.SamlSettings.EmailAttribute) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "") + if len(*ss.EmailAttribute) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.saml_email_attribute.app_error", nil, "", http.StatusBadRequest) } } - if *o.PasswordSettings.MinimumLength < PASSWORD_MINIMUM_LENGTH || *o.PasswordSettings.MinimumLength > PASSWORD_MAXIMUM_LENGTH { - return NewLocAppError("Config.IsValid", "model.config.is_valid.password_length.app_error", map[string]interface{}{"MinLength": PASSWORD_MINIMUM_LENGTH, "MaxLength": PASSWORD_MAXIMUM_LENGTH}, "") + return nil +} + +func (ws *WebrtcSettings) isValid() *AppError { + if *ws.Enable { + if len(*ws.GatewayWebsocketUrl) == 0 || !IsValidWebsocketUrl(*ws.GatewayWebsocketUrl) { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_ws_url.app_error", nil, "", http.StatusBadRequest) + } else if len(*ws.GatewayAdminUrl) == 0 || !IsValidHttpUrl(*ws.GatewayAdminUrl) { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_url.app_error", nil, "", http.StatusBadRequest) + } else if len(*ws.GatewayAdminSecret) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_secret.app_error", nil, "", http.StatusBadRequest) + } else if len(*ws.StunURI) != 0 && !IsValidTurnOrStunServer(*ws.StunURI) { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_stun_uri.app_error", nil, "", http.StatusBadRequest) + } else if len(*ws.TurnURI) != 0 { + if !IsValidTurnOrStunServer(*ws.TurnURI) { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_uri.app_error", nil, "", http.StatusBadRequest) + } + if len(*ws.TurnUsername) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_username.app_error", nil, "", http.StatusBadRequest) + } else if len(*ws.TurnSharedKey) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_shared_key.app_error", nil, "", http.StatusBadRequest) + } + } } - if len(o.TeamSettings.SiteName) > SITENAME_MAX_LENGTH { - return NewLocAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "") + return nil +} + +func (ss *ServiceSettings) isValid() *AppError { + if !(*ss.ConnectionSecurity == CONN_SECURITY_NONE || *ss.ConnectionSecurity == CONN_SECURITY_TLS) { + return NewAppError("Config.IsValid", "model.config.is_valid.webserver_security.app_error", nil, "", http.StatusBadRequest) } - if *o.RateLimitSettings.MaxBurst <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.max_burst.app_error", nil, "") + if *ss.ReadTimeout <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.read_timeout.app_error", nil, "", http.StatusBadRequest) } - if err := o.isValidWebrtcSettings(); err != nil { - return err + if *ss.WriteTimeout <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.write_timeout.app_error", nil, "", http.StatusBadRequest) } - if !(*o.ServiceSettings.ConnectionSecurity == CONN_SECURITY_NONE || *o.ServiceSettings.ConnectionSecurity == CONN_SECURITY_TLS) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webserver_security.app_error", nil, "") + if *ss.TimeBetweenUserTypingUpdatesMilliseconds < 1000 { + return NewAppError("Config.IsValid", "model.config.is_valid.time_between_user_typing.app_error", nil, "", http.StatusBadRequest) } - if *o.ServiceSettings.ReadTimeout <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.read_timeout.app_error", nil, "") + if *ss.MaximumLoginAttempts <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "", http.StatusBadRequest) } - if *o.ServiceSettings.WriteTimeout <= 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.write_timeout.app_error", nil, "") + if len(*ss.SiteURL) != 0 { + if _, err := url.ParseRequestURI(*ss.SiteURL); err != nil { + return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest) + } } - if *o.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds < 1000 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.time_between_user_typing.app_error", nil, "") + if len(*ss.ListenAddress) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "", http.StatusBadRequest) } - if *o.ElasticsearchSettings.EnableIndexing { - if len(*o.ElasticsearchSettings.ConnectionUrl) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.elastic_search.connection_url.app_error", nil, "") + return nil +} + +func (ess *ElasticsearchSettings) isValid() *AppError { + if *ess.EnableIndexing { + if len(*ess.ConnectionUrl) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.connection_url.app_error", nil, "", http.StatusBadRequest) } } - if *o.ElasticsearchSettings.EnableSearching && !*o.ElasticsearchSettings.EnableIndexing { - return NewLocAppError("Config.IsValid", "model.config.is_valid.elastic_search.enable_searching.app_error", nil, "") + if *ess.EnableSearching && !*ess.EnableIndexing { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.enable_searching.app_error", nil, "", http.StatusBadRequest) + } + + if *ess.AggregatePostsAfterDays < 1 { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.aggregate_posts_after_days.app_error", nil, "", http.StatusBadRequest) + } + + if _, err := time.Parse("15:04", *ess.PostsAggregatorJobStartTime); err != nil { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.posts_aggregator_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) + } + + if *ess.LiveIndexingBatchSize < 1 { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.live_indexing_batch_size.app_error", nil, "", http.StatusBadRequest) } + if *ess.BulkIndexingTimeWindowSeconds < 1 { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.bulk_indexing_time_window_seconds.app_error", nil, "", http.StatusBadRequest) + } + + if *ess.RequestTimeoutSeconds < 1 { + return NewAppError("Config.IsValid", "model.config.is_valid.elastic_search.request_timeout_seconds.app_error", nil, "", http.StatusBadRequest) + } + + return nil +} + +func (drs *DataRetentionSettings) isValid() *AppError { + if *drs.MessageRetentionDays <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.message_retention_days_too_low.app_error", nil, "", http.StatusBadRequest) + } + + if *drs.FileRetentionDays <= 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.file_retention_days_too_low.app_error", nil, "", http.StatusBadRequest) + } + + if _, err := time.Parse("15:04", *drs.DeletionJobStartTime); err != nil { + return NewAppError("Config.IsValid", "model.config.is_valid.data_retention.deletion_job_start_time.app_error", nil, err.Error(), http.StatusBadRequest) + } + + return nil +} + +func (ls *LocalizationSettings) isValid() *AppError { + if len(*ls.AvailableLocales) > 0 { + if !strings.Contains(*ls.AvailableLocales, *ls.DefaultClientLocale) { + return NewAppError("Config.IsValid", "model.config.is_valid.localization.available_locales.app_error", nil, "", http.StatusBadRequest) + } + } + + return nil +} + +func (mes *MessageExportSettings) isValid(fs FileSettings) *AppError { + if mes.EnableExport == nil { + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.enable.app_error", nil, "", http.StatusBadRequest) + } + if *mes.EnableExport { + if mes.ExportFromTimestamp == nil || *mes.ExportFromTimestamp < 0 || *mes.ExportFromTimestamp > GetMillis() { + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_from.app_error", nil, "", http.StatusBadRequest) + } else if mes.DailyRunTime == nil { + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, "", http.StatusBadRequest) + } else if _, err := time.Parse("15:04", *mes.DailyRunTime); err != nil { + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, err.Error(), http.StatusBadRequest) + } else if mes.BatchSize == nil || *mes.BatchSize < 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.batch_size.app_error", nil, "", http.StatusBadRequest) + } + } return nil } @@ -1725,7 +2153,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 { @@ -1738,71 +2166,3 @@ func (o *Config) Sanitize() { *o.ElasticsearchSettings.Password = FAKE_SETTING } - -func (o *Config) defaultWebrtcSettings() { - if o.WebrtcSettings.Enable == nil { - o.WebrtcSettings.Enable = new(bool) - *o.WebrtcSettings.Enable = false - } - - if o.WebrtcSettings.GatewayWebsocketUrl == nil { - o.WebrtcSettings.GatewayWebsocketUrl = new(string) - *o.WebrtcSettings.GatewayWebsocketUrl = "" - } - - if o.WebrtcSettings.GatewayAdminUrl == nil { - o.WebrtcSettings.GatewayAdminUrl = new(string) - *o.WebrtcSettings.GatewayAdminUrl = "" - } - - if o.WebrtcSettings.GatewayAdminSecret == nil { - o.WebrtcSettings.GatewayAdminSecret = new(string) - *o.WebrtcSettings.GatewayAdminSecret = "" - } - - if o.WebrtcSettings.StunURI == nil { - o.WebrtcSettings.StunURI = new(string) - *o.WebrtcSettings.StunURI = WEBRTC_SETTINGS_DEFAULT_STUN_URI - } - - if o.WebrtcSettings.TurnURI == nil { - o.WebrtcSettings.TurnURI = new(string) - *o.WebrtcSettings.TurnURI = WEBRTC_SETTINGS_DEFAULT_TURN_URI - } - - if o.WebrtcSettings.TurnUsername == nil { - o.WebrtcSettings.TurnUsername = new(string) - *o.WebrtcSettings.TurnUsername = "" - } - - if o.WebrtcSettings.TurnSharedKey == nil { - o.WebrtcSettings.TurnSharedKey = new(string) - *o.WebrtcSettings.TurnSharedKey = "" - } -} - -func (o *Config) isValidWebrtcSettings() *AppError { - if *o.WebrtcSettings.Enable { - if len(*o.WebrtcSettings.GatewayWebsocketUrl) == 0 || !IsValidWebsocketUrl(*o.WebrtcSettings.GatewayWebsocketUrl) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_ws_url.app_error", nil, "") - } else if len(*o.WebrtcSettings.GatewayAdminUrl) == 0 || !IsValidHttpUrl(*o.WebrtcSettings.GatewayAdminUrl) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_url.app_error", nil, "") - } else if len(*o.WebrtcSettings.GatewayAdminSecret) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_gateway_admin_secret.app_error", nil, "") - } else if len(*o.WebrtcSettings.StunURI) != 0 && !IsValidTurnOrStunServer(*o.WebrtcSettings.StunURI) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_stun_uri.app_error", nil, "") - } else if len(*o.WebrtcSettings.TurnURI) != 0 { - if !IsValidTurnOrStunServer(*o.WebrtcSettings.TurnURI) { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_uri.app_error", nil, "") - } - if len(*o.WebrtcSettings.TurnUsername) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_username.app_error", nil, "") - } else if len(*o.WebrtcSettings.TurnSharedKey) == 0 { - return NewLocAppError("Config.IsValid", "model.config.is_valid.webrtc_turn_shared_key.app_error", nil, "") - } - - } - } - - return nil -} |