2017-10-09 14:59:48 -07:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2019-02-14 23:22:11 +05:30
|
|
|
"github.com/mattermost/mattermost-server/mlog"
|
2019-02-12 08:37:54 -05:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
|
2019-02-12 14:19:01 -04:00
|
|
|
"github.com/mattermost/mattermost-server/config"
|
2017-10-09 14:59:48 -07:00
|
|
|
"github.com/mattermost/mattermost-server/store"
|
|
|
|
|
)
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
type Option func(s *Server) error
|
2017-10-09 14:59:48 -07:00
|
|
|
|
|
|
|
|
// By default, the app will use the store specified by the configuration. This allows you to
|
|
|
|
|
// construct an app with a different store.
|
|
|
|
|
//
|
2017-10-16 08:09:43 -07:00
|
|
|
// The override parameter must be either a store.Store or func(App) store.Store.
|
|
|
|
|
func StoreOverride(override interface{}) Option {
|
2019-02-12 08:37:54 -05:00
|
|
|
return func(s *Server) error {
|
2017-10-16 08:09:43 -07:00
|
|
|
switch o := override.(type) {
|
2017-10-09 14:59:48 -07:00
|
|
|
case store.Store:
|
2018-11-28 10:56:21 -08:00
|
|
|
s.newStore = func() store.Store {
|
2017-10-16 08:09:43 -07:00
|
|
|
return o
|
2017-10-09 14:59:48 -07:00
|
|
|
}
|
2019-02-12 08:37:54 -05:00
|
|
|
return nil
|
|
|
|
|
|
2018-11-28 10:56:21 -08:00
|
|
|
case func(*Server) store.Store:
|
|
|
|
|
s.newStore = func() store.Store {
|
|
|
|
|
return o(s)
|
2017-10-12 12:24:54 -07:00
|
|
|
}
|
2019-02-12 08:37:54 -05:00
|
|
|
return nil
|
|
|
|
|
|
2017-10-09 14:59:48 -07:00
|
|
|
default:
|
2019-02-12 08:37:54 -05:00
|
|
|
return errors.New("invalid StoreOverride")
|
2017-10-09 14:59:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-16 08:40:26 -06:00
|
|
|
|
2019-02-15 10:05:29 -04:00
|
|
|
// Config applies the given config dsn, whether a path to config.json or a database connection string.
|
|
|
|
|
func Config(dsn string, watch bool) Option {
|
2019-02-12 08:37:54 -05:00
|
|
|
return func(s *Server) error {
|
2019-02-15 10:05:29 -04:00
|
|
|
configStore, err := config.NewStore(dsn, watch)
|
2019-02-12 14:19:01 -04:00
|
|
|
if err != nil {
|
2019-02-15 10:05:29 -04:00
|
|
|
return errors.Wrap(err, "failed to apply Config option")
|
2019-02-12 14:19:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.configStore = configStore
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-15 10:05:29 -04:00
|
|
|
// ConfigStore applies the given config store, typically to replace the traditional sources with a memory store for testing.
|
2019-02-12 14:19:01 -04:00
|
|
|
func ConfigStore(configStore config.Store) Option {
|
|
|
|
|
return func(s *Server) error {
|
|
|
|
|
s.configStore = configStore
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2017-11-16 08:40:26 -06:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-11 15:23:41 -06:00
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func RunJobs(s *Server) error {
|
2018-12-17 08:51:46 -08:00
|
|
|
s.runjobs = true
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2018-12-17 08:51:46 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func JoinCluster(s *Server) error {
|
2019-01-15 09:09:25 -08:00
|
|
|
s.joinCluster = true
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2019-01-15 09:09:25 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func StartMetrics(s *Server) error {
|
2019-01-15 09:09:25 -08:00
|
|
|
s.startMetrics = true
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2019-01-15 09:09:25 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func StartElasticsearch(s *Server) error {
|
2019-01-15 09:09:25 -08:00
|
|
|
s.startElasticsearch = true
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
return nil
|
2018-11-28 10:56:21 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-14 23:22:11 +05:30
|
|
|
func SetLogger(logger *mlog.Logger) Option {
|
|
|
|
|
return func(s *Server) error {
|
|
|
|
|
s.Log = logger
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 10:56:21 -08:00
|
|
|
type AppOption func(a *App)
|
|
|
|
|
type AppOptionCreator func() []AppOption
|
|
|
|
|
|
|
|
|
|
func ServerConnector(s *Server) AppOption {
|
|
|
|
|
return func(a *App) {
|
|
|
|
|
a.Srv = s
|
|
|
|
|
|
|
|
|
|
a.Log = s.Log
|
2019-05-13 10:53:46 -04:00
|
|
|
a.NotificationsLog = s.NotificationsLog
|
2018-11-28 10:56:21 -08:00
|
|
|
|
|
|
|
|
a.AccountMigration = s.AccountMigration
|
|
|
|
|
a.Cluster = s.Cluster
|
|
|
|
|
a.Compliance = s.Compliance
|
|
|
|
|
a.DataRetention = s.DataRetention
|
|
|
|
|
a.Elasticsearch = s.Elasticsearch
|
|
|
|
|
a.Ldap = s.Ldap
|
|
|
|
|
a.MessageExport = s.MessageExport
|
|
|
|
|
a.Metrics = s.Metrics
|
|
|
|
|
a.Saml = s.Saml
|
2018-12-17 08:51:46 -08:00
|
|
|
|
|
|
|
|
a.HTTPService = s.HTTPService
|
2019-01-24 16:11:32 -04:00
|
|
|
a.ImageProxy = s.ImageProxy
|
2018-12-17 08:51:46 -08:00
|
|
|
a.Timezones = s.timezones
|
2018-11-28 10:56:21 -08:00
|
|
|
}
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|