From ac74066f0e4f3d62f2d4645c3fa34b88c13958d1 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 19 Sep 2017 18:31:35 -0500 Subject: remove einterface gets (#7455) --- api/admin.go | 27 +++++++++++++-------------- api/context.go | 17 ++++++++--------- api/user.go | 11 +++++------ api4/brand.go | 4 ++-- api4/cluster.go | 2 +- api4/context.go | 11 +++++------ api4/elasticsearch.go | 4 ++-- api4/ldap.go | 4 ++-- api4/saml.go | 2 +- api4/system.go | 10 +++++----- api4/system_test.go | 3 +-- api4/user.go | 2 +- app/admin.go | 41 ++++++++++++++++++++--------------------- app/analytics.go | 5 ++--- app/app.go | 28 +++++++++++++++++++++++++++- app/authentication.go | 28 ++++++++++++---------------- app/brand.go | 15 ++++++--------- app/channel.go | 2 +- app/cluster_discovery.go | 9 +++++++++ app/cluster_handlers.go | 30 ++++++++++++++---------------- app/compliance.go | 7 +++---- app/diagnostics.go | 2 +- app/elasticsearch.go | 9 ++++----- app/ldap.go | 15 +++++++-------- app/license.go | 4 ++-- app/login.go | 17 ++++++++--------- app/notification.go | 11 +++++------ app/oauth.go | 2 +- app/plugins.go | 6 ++---- app/post.go | 19 +++++++++---------- app/saml.go | 8 +++----- app/session.go | 13 ++++++------- app/session_test.go | 4 +++- app/status.go | 25 ++++++++++++------------- app/team.go | 6 +++--- app/user.go | 25 +++++++++++-------------- app/web_conn.go | 5 ++--- app/web_hub.go | 37 ++++++++++++++++++++----------------- app/webhook.go | 3 +-- cmd/platform/ldap.go | 6 +++--- cmd/platform/server.go | 25 ++++++++++++------------- cmd/platform/user.go | 9 ++++----- utils/config.go | 8 -------- 43 files changed, 259 insertions(+), 262 deletions(-) diff --git a/api/admin.go b/api/admin.go index 02b056931..65cea5eb7 100644 --- a/api/admin.go +++ b/api/admin.go @@ -10,7 +10,6 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/mattermost-server/app" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "github.com/mssola/user_agent" @@ -47,7 +46,7 @@ func InitAdmin() { } func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { - lines, err := app.GetLogs(0, 10000) + lines, err := c.App.GetLogs(0, 10000) if err != nil { c.Err = err return @@ -57,10 +56,10 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { } func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) { - infos := app.GetClusterStatus() + infos := c.App.GetClusterStatus() - if einterfaces.GetClusterInterface() != nil { - w.Header().Set(model.HEADER_CLUSTER_ID, einterfaces.GetClusterInterface().GetClusterId()) + if c.App.Cluster != nil { + w.Header().Set(model.HEADER_CLUSTER_ID, c.App.Cluster.GetClusterId()) } w.Write([]byte(model.ClusterInfosToJson(infos))) @@ -84,13 +83,13 @@ func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) { } func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { - cfg := app.GetConfig() + cfg := c.App.GetConfig() w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Write([]byte(cfg.ToJson())) } func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) { - app.ReloadConfig() + c.App.ReloadConfig() w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") ReturnStatusOK(w) } @@ -113,7 +112,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) { return } - err := app.SaveConfig(cfg, true) + err := c.App.SaveConfig(cfg, true) if err != nil { c.Err = err return @@ -261,7 +260,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.SaveBrandImage(imageArray[0]); err != nil { + if err := c.App.SaveBrandImage(imageArray[0]); err != nil { c.Err = err return } @@ -272,7 +271,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { } func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { - if img, err := app.GetBrandImage(); err != nil { + if img, err := c.App.GetBrandImage(); err != nil { w.Write(nil) } else { w.Header().Set("Content-Type", "image/png") @@ -289,7 +288,7 @@ func adminResetMfa(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.DeactivateMfa(userId); err != nil { + if err := c.App.DeactivateMfa(userId); err != nil { c.Err = err return } @@ -329,7 +328,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) { } func ldapSyncNow(c *Context, w http.ResponseWriter, r *http.Request) { - app.SyncLdap() + c.App.SyncLdap() rdata := map[string]string{} rdata["status"] = "ok" @@ -337,7 +336,7 @@ func ldapSyncNow(c *Context, w http.ResponseWriter, r *http.Request) { } func ldapTest(c *Context, w http.ResponseWriter, r *http.Request) { - if err := app.TestLdap(); err != nil { + if err := c.App.TestLdap(); err != nil { c.Err = err return } @@ -348,7 +347,7 @@ func ldapTest(c *Context, w http.ResponseWriter, r *http.Request) { } func samlMetadata(c *Context, w http.ResponseWriter, r *http.Request) { - if result, err := app.GetSamlMetadata(); err != nil { + if result, err := c.App.GetSamlMetadata(); err != nil { c.Err = model.NewAppError("loginWithSaml", "api.admin.saml.metadata.app_error", nil, "err="+err.Message, http.StatusInternalServerError) return } else { diff --git a/api/context.go b/api/context.go index 8cabf38b7..ebc439d31 100644 --- a/api/context.go +++ b/api/context.go @@ -15,7 +15,6 @@ import ( goi18n "github.com/nicksnyder/go-i18n/i18n" "github.com/mattermost/mattermost-server/app" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -103,10 +102,6 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { now := time.Now() l4g.Debug("%v", r.URL.Path) - if metrics := einterfaces.GetMetricsInterface(); metrics != nil && h.isApi { - metrics.IncrementHttpRequest() - } - c := &Context{} c.App = app.Global() c.T, c.Locale = utils.GetTranslationsAndLocale(w, r) @@ -114,6 +109,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.IpAddress = utils.GetIpAddress(r) c.TeamId = mux.Vars(r)["team_id"] + if metrics := c.App.Metrics; metrics != nil && h.isApi { + metrics.IncrementHttpRequest() + } + token := "" isTokenFromQueryString := false @@ -237,8 +236,8 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.WriteHeader(c.Err.StatusCode) w.Write([]byte(c.Err.ToJson())) - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementHttpError() + if c.App.Metrics != nil { + c.App.Metrics.IncrementHttpError() } } else { if c.Err.StatusCode == http.StatusUnauthorized { @@ -250,10 +249,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } - if h.isApi && einterfaces.GetMetricsInterface() != nil { + if h.isApi && c.App.Metrics != nil { if r.URL.Path != model.API_URL_SUFFIX_V3+"/users/websocket" { elapsed := float64(time.Since(now)) / float64(time.Second) - einterfaces.GetMetricsInterface().ObserveHttpRequestDuration(elapsed) + c.App.Metrics.ObserveHttpRequestDuration(elapsed) } } } diff --git a/api/user.go b/api/user.go index 1ca46bd56..af012ac2c 100644 --- a/api/user.go +++ b/api/user.go @@ -14,7 +14,6 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/mattermost-server/app" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -169,7 +168,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) { return } - app.ClearSessionCacheForUser(c.Session.UserId) + c.App.ClearSessionCacheForUser(c.Session.UserId) c.Session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays) maxAge := *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24 @@ -1075,7 +1074,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) { } c.LogAudit("success - activated") } else { - if err := app.DeactivateMfa(c.Session.UserId); err != nil { + if err := c.App.DeactivateMfa(c.Session.UserId); err != nil { c.Err = err return } @@ -1126,7 +1125,7 @@ func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) { } func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) { - samlInterface := einterfaces.GetSamlInterface() + samlInterface := c.App.Saml if samlInterface == nil { c.Err = model.NewAppError("loginWithSaml", "api.user.saml.not_available.app_error", nil, "", http.StatusFound) @@ -1169,7 +1168,7 @@ func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) { } func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) { - samlInterface := einterfaces.GetSamlInterface() + samlInterface := c.App.Saml if samlInterface == nil { c.Err = model.NewAppError("completeSaml", "api.user.saml.not_available.app_error", nil, "", http.StatusFound) @@ -1203,7 +1202,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) { } return } else { - if err := app.CheckUserAdditionalAuthenticationCriteria(user, ""); err != nil { + if err := c.App.CheckUserAdditionalAuthenticationCriteria(user, ""); err != nil { c.Err = err c.Err.StatusCode = http.StatusFound return diff --git a/api4/brand.go b/api4/brand.go index bc1ddd2cc..ef4ea25b5 100644 --- a/api4/brand.go +++ b/api4/brand.go @@ -22,7 +22,7 @@ func InitBrand() { func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { // No permission check required - if img, err := app.GetBrandImage(); err != nil { + if img, err := c.App.GetBrandImage(); err != nil { w.WriteHeader(http.StatusNotFound) w.Write(nil) } else { @@ -60,7 +60,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.SaveBrandImage(imageArray[0]); err != nil { + if err := c.App.SaveBrandImage(imageArray[0]); err != nil { c.Err = err return } diff --git a/api4/cluster.go b/api4/cluster.go index 0b119ad1a..c802d2a7e 100644 --- a/api4/cluster.go +++ b/api4/cluster.go @@ -24,6 +24,6 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) { return } - infos := app.GetClusterStatus() + infos := c.App.GetClusterStatus() w.Write([]byte(model.ClusterInfosToJson(infos))) } diff --git a/api4/context.go b/api4/context.go index 04eb9bbc3..cd32bc7b1 100644 --- a/api4/context.go +++ b/api4/context.go @@ -14,7 +14,6 @@ import ( goi18n "github.com/nicksnyder/go-i18n/i18n" "github.com/mattermost/mattermost-server/app" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -184,17 +183,17 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.WriteHeader(c.Err.StatusCode) w.Write([]byte(c.Err.ToJson())) - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementHttpError() + if c.App.Metrics != nil { + c.App.Metrics.IncrementHttpError() } } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementHttpRequest() + if c.App.Metrics != nil { + c.App.Metrics.IncrementHttpRequest() if r.URL.Path != model.API_URL_SUFFIX+"/websocket" { elapsed := float64(time.Since(now)) / float64(time.Second) - einterfaces.GetMetricsInterface().ObserveHttpRequestDuration(elapsed) + c.App.Metrics.ObserveHttpRequestDuration(elapsed) } } } diff --git a/api4/elasticsearch.go b/api4/elasticsearch.go index c4d059af9..cfa8292b6 100644 --- a/api4/elasticsearch.go +++ b/api4/elasticsearch.go @@ -30,7 +30,7 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.TestElasticsearch(cfg); err != nil { + if err := c.App.TestElasticsearch(cfg); err != nil { c.Err = err return } @@ -44,7 +44,7 @@ func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Reques return } - if err := app.PurgeElasticsearchIndexes(); err != nil { + if err := c.App.PurgeElasticsearchIndexes(); err != nil { c.Err = err return } diff --git a/api4/ldap.go b/api4/ldap.go index 84c0eff28..6ed581783 100644 --- a/api4/ldap.go +++ b/api4/ldap.go @@ -25,7 +25,7 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) { return } - app.SyncLdap() + c.App.SyncLdap() ReturnStatusOK(w) } @@ -36,7 +36,7 @@ func testLdap(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.TestLdap(); err != nil { + if err := c.App.TestLdap(); err != nil { c.Err = err return } diff --git a/api4/saml.go b/api4/saml.go index d16bef787..0fae1965b 100644 --- a/api4/saml.go +++ b/api4/saml.go @@ -30,7 +30,7 @@ func InitSaml() { } func getSamlMetadata(c *Context, w http.ResponseWriter, r *http.Request) { - metadata, err := app.GetSamlMetadata() + metadata, err := c.App.GetSamlMetadata() if err != nil { c.Err = err return diff --git a/api4/system.go b/api4/system.go index b50dc97a5..766ea09ee 100644 --- a/api4/system.go +++ b/api4/system.go @@ -94,7 +94,7 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { return } - cfg := app.GetConfig() + cfg := c.App.GetConfig() w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Write([]byte(cfg.ToJson())) @@ -106,7 +106,7 @@ func configReload(c *Context, w http.ResponseWriter, r *http.Request) { return } - app.ReloadConfig() + c.App.ReloadConfig() w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") ReturnStatusOK(w) @@ -124,7 +124,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) { return } - err := app.SaveConfig(cfg, true) + err := c.App.SaveConfig(cfg, true) if err != nil { c.Err = err return @@ -132,7 +132,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("updateConfig") - cfg = app.GetConfig() + cfg = c.App.GetConfig() w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Write([]byte(cfg.ToJson())) @@ -188,7 +188,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { return } - lines, err := app.GetLogs(c.Params.Page, c.Params.PerPage) + lines, err := c.App.GetLogs(c.Params.Page, c.Params.PerPage) if err != nil { c.Err = err return diff --git a/api4/system_test.go b/api4/system_test.go index c960f8689..426752b58 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -6,7 +6,6 @@ import ( "testing" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -108,7 +107,7 @@ func TestUpdateConfig(t *testing.T) { defer TearDown() Client := th.Client - cfg := app.GetConfig() + cfg := th.App.GetConfig() _, resp := Client.UpdateConfig(cfg) CheckForbiddenStatus(t, resp) diff --git a/api4/user.go b/api4/user.go index cb1ae0fa3..e62091320 100644 --- a/api4/user.go +++ b/api4/user.go @@ -947,7 +947,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) { return } - app.ClearSessionCacheForUser(c.Session.UserId) + c.App.ClearSessionCacheForUser(c.Session.UserId) c.Session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays) maxAge := *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24 diff --git a/app/admin.go b/app/admin.go index bd48431c1..1bd33527b 100644 --- a/app/admin.go +++ b/app/admin.go @@ -14,35 +14,34 @@ import ( "net/http" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/jobs" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" ) -func GetLogs(page, perPage int) ([]string, *model.AppError) { +func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) { perPage = 10000 var lines []string - if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable { + if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable { lines = append(lines, "-----------------------------------------------------------------------------------------------------------") lines = append(lines, "-----------------------------------------------------------------------------------------------------------") - lines = append(lines, einterfaces.GetClusterInterface().GetMyClusterInfo().Hostname) + lines = append(lines, a.Cluster.GetMyClusterInfo().Hostname) lines = append(lines, "-----------------------------------------------------------------------------------------------------------") lines = append(lines, "-----------------------------------------------------------------------------------------------------------") } - melines, err := GetLogsSkipSend(page, perPage) + melines, err := a.GetLogsSkipSend(page, perPage) if err != nil { return nil, err } lines = append(lines, melines...) - if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable { - clines, err := einterfaces.GetClusterInterface().GetLogs(page, perPage) + if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable { + clines, err := a.Cluster.GetLogs(page, perPage) if err != nil { return nil, err } @@ -53,7 +52,7 @@ func GetLogs(page, perPage int) ([]string, *model.AppError) { return lines, nil } -func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { +func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { var lines []string if utils.Cfg.LogSettings.EnableFile { @@ -86,11 +85,11 @@ func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { return lines, nil } -func GetClusterStatus() []*model.ClusterInfo { +func (a *App) GetClusterStatus() []*model.ClusterInfo { infos := make([]*model.ClusterInfo, 0) - if einterfaces.GetClusterInterface() != nil { - infos = einterfaces.GetClusterInterface().GetClusterInfos() + if a.Cluster != nil { + infos = a.Cluster.GetClusterInfos() } return infos @@ -100,7 +99,7 @@ func (a *App) InvalidateAllCaches() *model.AppError { debug.FreeOSMemory() a.InvalidateAllCachesSkipSend() - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, @@ -108,7 +107,7 @@ func (a *App) InvalidateAllCaches() *model.AppError { WaitForAllToSend: true, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } return nil @@ -125,7 +124,7 @@ func (a *App) InvalidateAllCachesSkipSend() { a.LoadLicense() } -func GetConfig() *model.Config { +func (a *App) GetConfig() *model.Config { json := utils.Cfg.ToJson() cfg := model.ConfigFromJson(strings.NewReader(json)) cfg.Sanitize() @@ -133,7 +132,7 @@ func GetConfig() *model.Config { return cfg } -func ReloadConfig() { +func (a *App) ReloadConfig() { debug.FreeOSMemory() utils.LoadConfig(utils.CfgFileName) @@ -141,7 +140,7 @@ func ReloadConfig() { InitEmailBatching() } -func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError { +func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError { oldCfg := utils.Cfg cfg.SetDefaults() utils.Desanitize(cfg) @@ -163,16 +162,16 @@ func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.A utils.LoadConfig(utils.CfgFileName) utils.EnableConfigWatch() - if einterfaces.GetMetricsInterface() != nil { + if a.Metrics != nil { if *utils.Cfg.MetricsSettings.Enable { - einterfaces.GetMetricsInterface().StartServer() + a.Metrics.StartServer() } else { - einterfaces.GetMetricsInterface().StopServer() + a.Metrics.StopServer() } } - if einterfaces.GetClusterInterface() != nil { - err := einterfaces.GetClusterInterface().ConfigChanged(cfg, oldCfg, sendConfigChangeClusterMessage) + if a.Cluster != nil { + err := a.Cluster.ConfigChanged(cfg, oldCfg, sendConfigChangeClusterMessage) if err != nil { return err } diff --git a/app/analytics.go b/app/analytics.go index 562569fa2..70c049350 100644 --- a/app/analytics.go +++ b/app/analytics.go @@ -5,7 +5,6 @@ package app import ( l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -98,8 +97,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo } // If in HA mode then aggregrate all the stats - if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable { - stats, err := einterfaces.GetClusterInterface().GetClusterStats() + if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable { + stats, err := a.Cluster.GetClusterStats() if err != nil { return nil, err } diff --git a/app/app.go b/app/app.go index 667c425bd..bf4a6b1b6 100644 --- a/app/app.go +++ b/app/app.go @@ -6,19 +6,45 @@ package app import ( "io/ioutil" "net/http" + "sync" + "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/plugin/pluginenv" ) type App struct { - Srv *Server + Srv *Server + PluginEnv *pluginenv.Environment PluginConfigListenerId string + + AccountMigration einterfaces.AccountMigrationInterface + Brand einterfaces.BrandInterface + Cluster einterfaces.ClusterInterface + Compliance einterfaces.ComplianceInterface + Elasticsearch einterfaces.ElasticsearchInterface + Ldap einterfaces.LdapInterface + Metrics einterfaces.MetricsInterface + Mfa einterfaces.MfaInterface + Saml einterfaces.SamlInterface } var globalApp App +var initEnterprise sync.Once + func Global() *App { + initEnterprise.Do(func() { + globalApp.AccountMigration = einterfaces.GetAccountMigrationInterface() + globalApp.Brand = einterfaces.GetBrandInterface() + globalApp.Cluster = einterfaces.GetClusterInterface() + globalApp.Compliance = einterfaces.GetComplianceInterface() + globalApp.Elasticsearch = einterfaces.GetElasticsearchInterface() + globalApp.Ldap = einterfaces.GetLdapInterface() + globalApp.Metrics = einterfaces.GetMetricsInterface() + globalApp.Mfa = einterfaces.GetMfaInterface() + globalApp.Saml = einterfaces.GetSamlInterface() + }) return &globalApp } diff --git a/app/authentication.go b/app/authentication.go index 5550589cf..01e1e0a48 100644 --- a/app/authentication.go +++ b/app/authentication.go @@ -7,13 +7,12 @@ import ( "net/http" "strings" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError { - if err := CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil { + if err := a.CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil { return err } @@ -53,23 +52,21 @@ func (a *App) checkUserPassword(user *model.User, password string) *model.AppErr } } -func checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) { - ldapInterface := einterfaces.GetLdapInterface() - - if ldapInterface == nil || ldapId == nil { +func (a *App) checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) { + if a.Ldap == nil || ldapId == nil { err := model.NewAppError("doLdapAuthentication", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented) return nil, err } var user *model.User - if ldapUser, err := ldapInterface.DoLogin(*ldapId, password); err != nil { + if ldapUser, err := a.Ldap.DoLogin(*ldapId, password); err != nil { err.StatusCode = http.StatusUnauthorized return nil, err } else { user = ldapUser } - if err := CheckUserMfa(user, mfaToken); err != nil { + if err := a.CheckUserMfa(user, mfaToken); err != nil { return nil, err } @@ -81,8 +78,8 @@ func checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaTok return user, nil } -func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError { - if err := CheckUserMfa(user, mfaToken); err != nil { +func (a *App) CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError { + if err := a.CheckUserMfa(user, mfaToken); err != nil { return err } @@ -101,17 +98,16 @@ func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string return nil } -func CheckUserMfa(user *model.User, token string) *model.AppError { +func (a *App) CheckUserMfa(user *model.User, token string) *model.AppError { if !user.MfaActive || !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { return nil } - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { + if a.Mfa == nil { return model.NewAppError("checkUserMfa", "api.user.check_user_mfa.not_available.app_error", nil, "", http.StatusNotImplemented) } - if ok, err := mfaInterface.ValidateToken(user.MfaSecret, token); err != nil { + if ok, err := a.Mfa.ValidateToken(user.MfaSecret, token); err != nil { return err } else if !ok { return model.NewAppError("checkUserMfa", "api.user.check_user_mfa.bad_code.app_error", nil, "", http.StatusUnauthorized) @@ -143,13 +139,13 @@ func checkUserNotDisabled(user *model.User) *model.AppError { } func (a *App) authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) { - ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP + ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP if user.AuthService == model.USER_AUTH_SERVICE_LDAP { if !ldapAvailable { err := model.NewAppError("login", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented) return user, err - } else if ldapUser, err := checkLdapUserPasswordAndAllCriteria(user.AuthData, password, mfaToken); err != nil { + } else if ldapUser, err := a.checkLdapUserPasswordAndAllCriteria(user.AuthData, password, mfaToken); err != nil { err.StatusCode = http.StatusUnauthorized return user, err } else { diff --git a/app/brand.go b/app/brand.go index dab69abd8..b108a7b32 100644 --- a/app/brand.go +++ b/app/brand.go @@ -7,39 +7,36 @@ import ( "mime/multipart" "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func SaveBrandImage(imageData *multipart.FileHeader) *model.AppError { +func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError { if len(*utils.Cfg.FileSettings.DriverName) == 0 { return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "", http.StatusNotImplemented) } - brandInterface := einterfaces.GetBrandInterface() - if brandInterface == nil { + if a.Brand == nil { return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.not_available.app_error", nil, "", http.StatusNotImplemented) } - if err := brandInterface.SaveBrandImage(imageData); err != nil { + if err := a.Brand.SaveBrandImage(imageData); err != nil { return err } return nil } -func GetBrandImage() ([]byte, *model.AppError) { +func (a *App) GetBrandImage() ([]byte, *model.AppError) { if len(*utils.Cfg.FileSettings.DriverName) == 0 { return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "", http.StatusNotImplemented) } - brandInterface := einterfaces.GetBrandInterface() - if brandInterface == nil { + if a.Brand == nil { return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.not_available.app_error", nil, "", http.StatusNotImplemented) } - if img, err := brandInterface.GetBrandImage(); err != nil { + if img, err := a.Brand.GetBrandImage(); err != nil { return nil, err } else { return img, nil diff --git a/app/channel.go b/app/channel.go index e7025633f..8ca3a563a 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1087,7 +1087,7 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError status.LastActivityAt = model.GetMillis() } - AddStatusCache(status) + a.AddStatusCache(status) if status.Status != oldStatus { BroadcastStatus(status) diff --git a/app/cluster_discovery.go b/app/cluster_discovery.go index c93684ccd..223b012dd 100644 --- a/app/cluster_discovery.go +++ b/app/cluster_discovery.go @@ -9,6 +9,7 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" ) const ( @@ -75,3 +76,11 @@ func (me *ClusterDiscoveryService) Start() { func (me *ClusterDiscoveryService) Stop() { me.stop <- true } + +func (a *App) IsLeader() bool { + if utils.IsLicensed() && *utils.Cfg.ClusterSettings.Enable && a.Cluster != nil { + return a.Cluster.IsLeader() + } else { + return true + } +} diff --git a/app/cluster_handlers.go b/app/cluster_handlers.go index daf87e886..5c4bd7026 100644 --- a/app/cluster_handlers.go +++ b/app/cluster_handlers.go @@ -6,33 +6,31 @@ package app import ( "strings" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" ) func (a *App) RegisterAllClusterMessageHandlers() { - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, ClusterPublishHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, ClusterUpdateStatusHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler) - + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, a.ClusterPublishHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, a.ClusterUpdateStatusHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler) } -func ClusterPublishHandler(msg *model.ClusterMessage) { +func (a *App) ClusterPublishHandler(msg *model.ClusterMessage) { event := model.WebSocketEventFromJson(strings.NewReader(msg.Data)) PublishSkipClusterSend(event) } -func ClusterUpdateStatusHandler(msg *model.ClusterMessage) { +func (a *App) ClusterUpdateStatusHandler(msg *model.ClusterMessage) { status := model.StatusFromJson(strings.NewReader(msg.Data)) - AddStatusCacheSkipClusterSend(status) + a.AddStatusCacheSkipClusterSend(status) } func (a *App) ClusterInvalidateAllCachesHandler(msg *model.ClusterMessage) { diff --git a/app/compliance.go b/app/compliance.go index fcfb35d41..cf942ca00 100644 --- a/app/compliance.go +++ b/app/compliance.go @@ -8,7 +8,6 @@ import ( "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -26,7 +25,7 @@ func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model } func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) { - if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil { + if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil { return nil, model.NewAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented) } @@ -36,14 +35,14 @@ func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *m return nil, result.Err } else { job = result.Data.(*model.Compliance) - go einterfaces.GetComplianceInterface().RunComplianceJob(job) + go a.Compliance.RunComplianceJob(job) } return job, nil } func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) { - if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil { + if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil { return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented) } diff --git a/app/diagnostics.go b/app/diagnostics.go index 25f75ddad..1c0fab7ac 100644 --- a/app/diagnostics.go +++ b/app/diagnostics.go @@ -51,7 +51,7 @@ const ( var client *analytics.Client func (a *App) SendDailyDiagnostics() { - if *utils.Cfg.LogSettings.EnableDiagnostics && utils.IsLeader() { + if *utils.Cfg.LogSettings.EnableDiagnostics && a.IsLeader() { initDiagnostics("") a.trackActivity() trackConfig() diff --git a/app/elasticsearch.go b/app/elasticsearch.go index 96e271272..71fe6cedb 100644 --- a/app/elasticsearch.go +++ b/app/elasticsearch.go @@ -6,12 +6,11 @@ package app import ( "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func TestElasticsearch(cfg *model.Config) *model.AppError { +func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError { if *cfg.ElasticsearchSettings.Password == model.FAKE_SETTING { if *cfg.ElasticsearchSettings.ConnectionUrl == *utils.Cfg.ElasticsearchSettings.ConnectionUrl && *cfg.ElasticsearchSettings.Username == *utils.Cfg.ElasticsearchSettings.Username { *cfg.ElasticsearchSettings.Password = *utils.Cfg.ElasticsearchSettings.Password @@ -20,7 +19,7 @@ func TestElasticsearch(cfg *model.Config) *model.AppError { } } - if esI := einterfaces.GetElasticsearchInterface(); esI != nil { + if esI := a.Elasticsearch; esI != nil { if err := esI.TestConfig(cfg); err != nil { return err } @@ -32,8 +31,8 @@ func TestElasticsearch(cfg *model.Config) *model.AppError { return nil } -func PurgeElasticsearchIndexes() *model.AppError { - if esI := einterfaces.GetElasticsearchInterface(); esI != nil { +func (a *App) PurgeElasticsearchIndexes() *model.AppError { + if esI := a.Elasticsearch; esI != nil { if err := esI.PurgeIndexes(); err != nil { return err } diff --git a/app/ldap.go b/app/ldap.go index b448850dd..279ea3708 100644 --- a/app/ldap.go +++ b/app/ldap.go @@ -7,15 +7,14 @@ import ( "net/http" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func SyncLdap() { +func (a *App) SyncLdap() { go func() { if utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable { - if ldapI := einterfaces.GetLdapInterface(); ldapI != nil { + if ldapI := a.Ldap; ldapI != nil { ldapI.SyncNow() } else { l4g.Error("%v", model.NewAppError("SyncLdap", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented).Error()) @@ -24,8 +23,8 @@ func SyncLdap() { }() } -func TestLdap() *model.AppError { - if ldapI := einterfaces.GetLdapInterface(); ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable { +func (a *App) TestLdap() *model.AppError { + if ldapI := a.Ldap; ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable { if err := ldapI.RunTest(); err != nil { err.StatusCode = 500 return err @@ -52,7 +51,7 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapId, ldapPassword stri return "", err } - ldapInterface := einterfaces.GetLdapInterface() + ldapInterface := a.Ldap if ldapInterface == nil { return "", model.NewAppError("SwitchEmailToLdap", "api.user.email_to_ldap.not_available.app_error", nil, "", http.StatusNotImplemented) } @@ -80,7 +79,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) ( return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_ldap_account.app_error", nil, "", http.StatusBadRequest) } - ldapInterface := einterfaces.GetLdapInterface() + ldapInterface := a.Ldap if ldapInterface == nil || user.AuthData == nil { return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusNotImplemented) } @@ -89,7 +88,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) ( return "", err } - if err := CheckUserMfa(user, code); err != nil { + if err := a.CheckUserMfa(user, code); err != nil { return "", err } diff --git a/app/license.go b/app/license.go index 5c3dbdd9f..18836c571 100644 --- a/app/license.go +++ b/app/license.go @@ -86,7 +86,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) return nil, model.NewAppError("addLicense", model.INVALID_LICENSE_ERROR, nil, "", http.StatusBadRequest) } - ReloadConfig() + a.ReloadConfig() a.InvalidateAllCaches() return license, nil @@ -104,7 +104,7 @@ func (a *App) RemoveLicense() *model.AppError { return result.Err } - ReloadConfig() + a.ReloadConfig() a.InvalidateAllCaches() diff --git a/app/login.go b/app/login.go index ad2412644..18b26c55c 100644 --- a/app/login.go +++ b/app/login.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "github.com/mssola/user_agent" @@ -27,15 +26,15 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId if len(id) != 0 { if user, err = a.GetUser(id); err != nil { err.StatusCode = http.StatusBadRequest - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLoginFail() + if a.Metrics != nil { + a.Metrics.IncrementLoginFail() } return nil, err } } else { if user, err = a.GetUserForLogin(loginId, ldapOnly); err != nil { - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLoginFail() + if a.Metrics != nil { + a.Metrics.IncrementLoginFail() } return nil, err } @@ -43,14 +42,14 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId // and then authenticate them if user, err = a.authenticateUser(user, password, mfaToken); err != nil { - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLoginFail() + if a.Metrics != nil { + a.Metrics.IncrementLoginFail() } return nil, err } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLogin() + if a.Metrics != nil { + a.Metrics.IncrementLogin() } return user, nil diff --git a/app/notification.go b/app/notification.go index 511960f84..cc3db8b55 100644 --- a/app/notification.go +++ b/app/notification.go @@ -18,7 +18,6 @@ import ( "unicode" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -369,8 +368,8 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel } }() - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostSentEmail() + if a.Metrics != nil { + a.Metrics.IncrementPostSentEmail() } return nil @@ -641,8 +640,8 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel * go a.sendToPushProxy(tmpMessage, session) - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostSentPush() + if a.Metrics != nil { + a.Metrics.IncrementPostSentPush() } } @@ -701,7 +700,7 @@ func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_REMOVE { l4g.Info("Device was reported as removed for UserId=%v SessionId=%v removing push for this session", session.UserId, session.Id) a.AttachDeviceId(session.Id, "", session.ExpiresAt) - ClearSessionCacheForUser(session.UserId) + a.ClearSessionCacheForUser(session.UserId) } if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_FAIL { diff --git a/app/oauth.go b/app/oauth.go index 2b45409a6..cd45b0c10 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -426,7 +426,7 @@ func (a *App) RevokeAccessToken(token string) *model.AppError { } if session != nil { - ClearSessionCacheForUser(session.UserId) + a.ClearSessionCacheForUser(session.UserId) } return nil diff --git a/app/plugins.go b/app/plugins.go index fb8182823..86c18ce22 100644 --- a/app/plugins.go +++ b/app/plugins.go @@ -16,7 +16,6 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -96,8 +95,7 @@ func (api *BuiltInPluginAPI) CreatePost(post *model.Post) (*model.Post, *model.A } func (api *BuiltInPluginAPI) GetLdapUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) { - ldapInterface := einterfaces.GetLdapInterface() - if ldapInterface == nil { + if api.app.Ldap == nil { return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented) } @@ -106,7 +104,7 @@ func (api *BuiltInPluginAPI) GetLdapUserAttributes(userId string, attributes []s return nil, err } - return ldapInterface.GetUserAttributes(*user.AuthData, attributes) + return api.app.Ldap.GetUserAttributes(*user.AuthData, attributes) } func (api *BuiltInPluginAPI) GetSessionFromRequest(r *http.Request) (*model.Session, *model.AppError) { diff --git a/app/post.go b/app/post.go index 80c66e530..feb024fb1 100644 --- a/app/post.go +++ b/app/post.go @@ -12,7 +12,6 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/dyatlov/go-opengraph/opengraph" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -151,13 +150,13 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo rpost = result.Data.(*model.Post) } - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing { go esInterface.IndexPost(rpost, channel.TeamId) } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostCreate() + if a.Metrics != nil { + a.Metrics.IncrementPostCreate() } if len(post.FileIds) > 0 { @@ -170,8 +169,8 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo } } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostFileAttachment(len(post.FileIds)) + if a.Metrics != nil { + a.Metrics.IncrementPostFileAttachment(len(post.FileIds)) } } @@ -320,7 +319,7 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model } else { rpost := result.Data.(*model.Post) - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing { go func() { if rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil { @@ -507,7 +506,7 @@ func (a *App) DeletePost(postId string) (*model.Post, *model.AppError) { go a.DeletePostFiles(post) go a.DeleteFlaggedPosts(post.Id) - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing { go esInterface.DeletePost(post) } @@ -538,7 +537,7 @@ func (a *App) DeletePostFiles(post *model.Post) { func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostList, *model.AppError) { paramsList := model.ParseSearchParams(terms) - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableSearching && utils.IsLicensed() && *utils.License().Features.Elasticsearch { finalParamsList := []*model.SearchParams{} @@ -580,7 +579,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr return nil, err } - postIds, err := einterfaces.GetElasticsearchInterface().SearchPosts(userChannels, finalParamsList) + postIds, err := a.Elasticsearch.SearchPosts(userChannels, finalParamsList) if err != nil { return nil, err } diff --git a/app/saml.go b/app/saml.go index f9e8dab3c..e6a688d8e 100644 --- a/app/saml.go +++ b/app/saml.go @@ -11,19 +11,17 @@ import ( "path/filepath" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func GetSamlMetadata() (string, *model.AppError) { - samlInterface := einterfaces.GetSamlInterface() - if samlInterface == nil { +func (a *App) GetSamlMetadata() (string, *model.AppError) { + if a.Saml == nil { err := model.NewAppError("GetSamlMetadata", "api.admin.saml.not_available.app_error", nil, "", http.StatusNotImplemented) return "", err } - if result, err := samlInterface.GetMetadata(); err != nil { + if result, err := a.Saml.GetMetadata(); err != nil { return "", model.NewAppError("GetSamlMetadata", "api.admin.saml.metadata.app_error", nil, "err="+err.Message, err.StatusCode) } else { return result, nil diff --git a/app/session.go b/app/session.go index bf1a24c58..e5e5c939d 100644 --- a/app/session.go +++ b/app/session.go @@ -6,7 +6,6 @@ package app import ( "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -30,7 +29,7 @@ func (a *App) CreateSession(session *model.Session) (*model.Session, *model.AppE } func (a *App) GetSession(token string) (*model.Session, *model.AppError) { - metrics := einterfaces.GetMetricsInterface() + metrics := a.Metrics var session *model.Session if ts, ok := sessionCache.Get(token); ok { @@ -102,22 +101,22 @@ func (a *App) RevokeAllSessions(userId string) *model.AppError { } } - ClearSessionCacheForUser(userId) + a.ClearSessionCacheForUser(userId) return nil } -func ClearSessionCacheForUser(userId string) { +func (a *App) ClearSessionCacheForUser(userId string) { ClearSessionCacheForUserSkipClusterSend(userId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: userId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -185,7 +184,7 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError { } RevokeWebrtcToken(session.Id) - ClearSessionCacheForUser(session.UserId) + a.ClearSessionCacheForUser(session.UserId) return nil } diff --git a/app/session_test.go b/app/session_test.go index b4fa42330..e91132a8a 100644 --- a/app/session_test.go +++ b/app/session_test.go @@ -10,6 +10,8 @@ import ( ) func TestCache(t *testing.T) { + th := Setup().InitBasic() + session := &model.Session{ Id: model.NewId(), Token: model.NewId(), @@ -23,7 +25,7 @@ func TestCache(t *testing.T) { t.Fatal("should have items") } - ClearSessionCacheForUser(session.UserId) + th.App.ClearSessionCacheForUser(session.UserId) rkeys := sessionCache.Keys() if len(rkeys) != len(keys)-1 { diff --git a/app/status.go b/app/status.go index e783e1d9d..fb93a9e39 100644 --- a/app/status.go +++ b/app/status.go @@ -6,7 +6,6 @@ package app import ( l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -18,20 +17,20 @@ func ClearStatusCache() { statusCache.Purge() } -func AddStatusCacheSkipClusterSend(status *model.Status) { +func (a *App) AddStatusCacheSkipClusterSend(status *model.Status) { statusCache.Add(status.UserId, status) } -func AddStatusCache(status *model.Status) { - AddStatusCacheSkipClusterSend(status) +func (a *App) AddStatusCache(status *model.Status) { + a.AddStatusCacheSkipClusterSend(status) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_UPDATE_STATUS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: status.ToJson(), } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -63,7 +62,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model } statusMap := map[string]interface{}{} - metrics := einterfaces.GetMetricsInterface() + metrics := a.Metrics missingUserIds := []string{} for _, userId := range userIds { @@ -87,7 +86,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model statuses := result.Data.([]*model.Status) for _, s := range statuses { - AddStatusCache(s) + a.AddStatusCache(s) statusMap[s.UserId] = s.Status } } @@ -110,7 +109,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap } var statusMap []*model.Status - metrics := einterfaces.GetMetricsInterface() + metrics := a.Metrics missingUserIds := []string{} for _, userId := range userIds { @@ -134,7 +133,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap statuses := result.Data.([]*model.Status) for _, s := range statuses { - AddStatusCache(s) + a.AddStatusCache(s) } statusMap = append(statusMap, statuses...) @@ -195,7 +194,7 @@ func (a *App) SetStatusOnline(userId string, sessionId string, manual bool) { status.LastActivityAt = model.GetMillis() } - AddStatusCache(status) + a.AddStatusCache(status) // Only update the database if the status has changed, the status has been manually set, // or enough time has passed since the previous action @@ -237,7 +236,7 @@ func (a *App) SetStatusOffline(userId string, manual bool) { status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: manual, LastActivityAt: model.GetMillis(), ActiveChannel: ""} - AddStatusCache(status) + a.AddStatusCache(status) if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil { l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) @@ -278,7 +277,7 @@ func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) { status.Manual = manual status.ActiveChannel = "" - AddStatusCache(status) + a.AddStatusCache(status) if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil { l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) diff --git a/app/team.go b/app/team.go index 1aa7abf87..fdf44a783 100644 --- a/app/team.go +++ b/app/team.go @@ -161,7 +161,7 @@ func (a *App) UpdateTeamMemberRoles(teamId string, userId string, newRoles strin return nil, result.Err } - ClearSessionCacheForUser(userId) + a.ClearSessionCacheForUser(userId) sendUpdatedMemberRoleEvent(userId, member) @@ -324,7 +324,7 @@ func (a *App) JoinUserToTeam(team *model.Team, user *model.User, userRequestorId l4g.Error(utils.T("api.user.create_user.joining.error"), user.Id, team.Id, err) } - ClearSessionCacheForUser(user.Id) + a.ClearSessionCacheForUser(user.Id) a.InvalidateCacheForUser(user.Id) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_ADDED_TO_TEAM, "", "", user.Id, nil) @@ -621,7 +621,7 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User) *model.AppError { return result.Err } - ClearSessionCacheForUser(user.Id) + a.ClearSessionCacheForUser(user.Id) a.InvalidateCacheForUser(user.Id) return nil diff --git a/app/user.go b/app/user.go index 9d3a52da3..c91b4cfb7 100644 --- a/app/user.go +++ b/app/user.go @@ -372,7 +372,7 @@ func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, } func (a *App) GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *model.AppError) { - ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP + ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP if result := <-a.Srv.Store.User().GetForLogin( loginId, @@ -391,7 +391,7 @@ func (a *App) GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *mode } // fall back to LDAP server to see if we can find a user - if ldapUser, ldapErr := einterfaces.GetLdapInterface().GetUser(loginId); ldapErr != nil { + if ldapUser, ldapErr := a.Ldap.GetUser(loginId); ldapErr != nil { ldapErr.StatusCode = http.StatusBadRequest return nil, ldapErr } else { @@ -607,8 +607,7 @@ func sanitizeProfiles(users []*model.User, asAdmin bool) []*model.User { } func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppError) { - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { + if a.Mfa == nil { return nil, model.NewAppError("generateMfaSecret", "api.user.generate_mfa_qr.not_available.app_error", nil, "", http.StatusNotImplemented) } @@ -618,7 +617,7 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro return nil, err } - secret, img, err := mfaInterface.GenerateSecret(user) + secret, img, err := a.Mfa.GenerateSecret(user) if err != nil { return nil, err } @@ -628,8 +627,7 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro } func (a *App) ActivateMfa(userId, token string) *model.AppError { - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { + if a.Mfa == nil { err := model.NewAppError("ActivateMfa", "api.user.update_mfa.not_available.app_error", nil, "", http.StatusNotImplemented) return err } @@ -645,21 +643,20 @@ func (a *App) ActivateMfa(userId, token string) *model.AppError { return model.NewAppError("ActivateMfa", "api.user.activate_mfa.email_and_ldap_only.app_error", nil, "", http.StatusBadRequest) } - if err := mfaInterface.Activate(user, token); err != nil { + if err := a.Mfa.Activate(user, token); err != nil { return err } return nil } -func DeactivateMfa(userId string) *model.AppError { - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { +func (a *App) DeactivateMfa(userId string) *model.AppError { + if a.Mfa == nil { err := model.NewAppError("DeactivateMfa", "api.user.update_mfa.not_available.app_error", nil, "", http.StatusNotImplemented) return err } - if err := mfaInterface.Deactivate(userId); err != nil { + if err := a.Mfa.Deactivate(userId); err != nil { return err } @@ -1045,7 +1042,7 @@ func (a *App) UpdateMfa(activate bool, userId, token string) *model.AppError { return err } } else { - if err := DeactivateMfa(userId); err != nil { + if err := a.DeactivateMfa(userId); err != nil { return err } } @@ -1215,7 +1212,7 @@ func (a *App) UpdateUserRoles(userId string, newRoles string) (*model.User, *mod l4g.Error(result.Err) } - ClearSessionCacheForUser(user.Id) + a.ClearSessionCacheForUser(user.Id) return ruser, nil } diff --git a/app/web_conn.go b/app/web_conn.go index 556612e79..069d2c8f4 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -8,7 +8,6 @@ import ( "sync/atomic" "time" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -191,8 +190,8 @@ func (c *WebConn) WritePump() { return } - if einterfaces.GetMetricsInterface() != nil { - go einterfaces.GetMetricsInterface().IncrementWebSocketBroadcast(msg.EventType()) + if c.App.Metrics != nil { + go c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType()) } } diff --git a/app/web_hub.go b/app/web_hub.go index cd12202b5..b351de39e 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -15,7 +15,6 @@ import ( l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -145,13 +144,17 @@ func HubUnregister(webConn *WebConn) { } func Publish(message *model.WebSocketEvent) { - if metrics := einterfaces.GetMetricsInterface(); metrics != nil { + Global().Publish(message) +} + +func (a *App) Publish(message *model.WebSocketEvent) { + if metrics := a.Metrics; metrics != nil { metrics.IncrementWebsocketEvent(message.Event) } PublishSkipClusterSend(message) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { cm := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_PUBLISH, SendType: model.CLUSTER_SEND_BEST_EFFORT, @@ -166,7 +169,7 @@ func Publish(message *model.WebSocketEvent) { cm.SendType = model.CLUSTER_SEND_RELIABLE } - einterfaces.GetClusterInterface().SendClusterMessage(cm) + a.Cluster.SendClusterMessage(cm) } } @@ -180,14 +183,14 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) { a.InvalidateCacheForChannelSkipClusterSend(channel.Id) a.InvalidateCacheForChannelByNameSkipClusterSend(channel.TeamId, channel.Name) - if cluster := einterfaces.GetClusterInterface(); cluster != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channel.Id, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) nameMsg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, @@ -202,7 +205,7 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) { nameMsg.Props["id"] = channel.TeamId } - einterfaces.GetClusterInterface().SendClusterMessage(nameMsg) + a.Cluster.SendClusterMessage(nameMsg) } } @@ -213,13 +216,13 @@ func (a *App) InvalidateCacheForChannelSkipClusterSend(channelId string) { func (a *App) InvalidateCacheForChannelMembers(channelId string) { a.InvalidateCacheForChannelMembersSkipClusterSend(channelId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channelId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -231,13 +234,13 @@ func (a *App) InvalidateCacheForChannelMembersSkipClusterSend(channelId string) func (a *App) InvalidateCacheForChannelMembersNotifyProps(channelId string) { a.InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channelId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -256,13 +259,13 @@ func (a *App) InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string func (a *App) InvalidateCacheForChannelPosts(channelId string) { a.InvalidateCacheForChannelPostsSkipClusterSend(channelId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channelId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -273,13 +276,13 @@ func (a *App) InvalidateCacheForChannelPostsSkipClusterSend(channelId string) { func (a *App) InvalidateCacheForUser(userId string) { a.InvalidateCacheForUserSkipClusterSend(userId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: userId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -296,13 +299,13 @@ func (a *App) InvalidateCacheForUserSkipClusterSend(userId string) { func (a *App) InvalidateCacheForWebhook(webhookId string) { a.InvalidateCacheForWebhookSkipClusterSend(webhookId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: webhookId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } diff --git a/app/webhook.go b/app/webhook.go index 61b8b4d1a..04887f203 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -11,7 +11,6 @@ import ( "unicode/utf8" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -126,7 +125,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove post := &model.Post{UserId: userId, ChannelId: channel.Id, Message: text, Type: postType} post.AddProp("from_webhook", "true") - if metrics := einterfaces.GetMetricsInterface(); metrics != nil { + if metrics := a.Metrics; metrics != nil { metrics.IncrementWebhookPost() } diff --git a/cmd/platform/ldap.go b/cmd/platform/ldap.go index ad9b0a2f6..16ad429bd 100644 --- a/cmd/platform/ldap.go +++ b/cmd/platform/ldap.go @@ -3,7 +3,6 @@ package main import ( - "github.com/mattermost/mattermost-server/einterfaces" "github.com/spf13/cobra" ) @@ -27,11 +26,12 @@ func init() { } func ldapSyncCmdF(cmd *cobra.Command, args []string) error { - if _, err := initDBCommandContextCobra(cmd); err != nil { + a, err := initDBCommandContextCobra(cmd) + if err != nil { return err } - if ldapI := einterfaces.GetLdapInterface(); ldapI != nil { + if ldapI := a.Ldap; ldapI != nil { if err := ldapI.Syncronize(); err != nil { CommandPrintErrorln("ERROR: AD/LDAP Synchronization Failed") } else { diff --git a/cmd/platform/server.go b/cmd/platform/server.go index a8e724f58..60d3804e4 100644 --- a/cmd/platform/server.go +++ b/cmd/platform/server.go @@ -13,7 +13,6 @@ import ( "github.com/mattermost/mattermost-server/api" "github.com/mattermost/mattermost-server/api4" "github.com/mattermost/mattermost-server/app" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/jobs" "github.com/mattermost/mattermost-server/manualtesting" "github.com/mattermost/mattermost-server/model" @@ -96,7 +95,7 @@ func runServer(configFileLocation string) { utils.Cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault } - app.ReloadConfig() + a.ReloadConfig() // Enable developer settings if this is a "dev" build if model.BuildNumber == "dev" { @@ -120,21 +119,21 @@ func runServer(configFileLocation string) { go runTokenCleanupJob(a) go runCommandWebhookCleanupJob(a) - if complianceI := einterfaces.GetComplianceInterface(); complianceI != nil { + if complianceI := a.Compliance; complianceI != nil { complianceI.StartComplianceDailyJob() } - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { a.RegisterAllClusterMessageHandlers() - einterfaces.GetClusterInterface().StartInterNodeCommunication() + a.Cluster.StartInterNodeCommunication() } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().StartServer() + if a.Metrics != nil { + a.Metrics.StartServer() } - if einterfaces.GetElasticsearchInterface() != nil { - if err := einterfaces.GetElasticsearchInterface().Start(); err != nil { + if a.Elasticsearch != nil { + if err := a.Elasticsearch.Start(); err != nil { l4g.Error(err.Error()) } } @@ -153,12 +152,12 @@ func runServer(configFileLocation string) { signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) <-c - if einterfaces.GetClusterInterface() != nil { - einterfaces.GetClusterInterface().StopInterNodeCommunication() + if a.Cluster != nil { + a.Cluster.StopInterNodeCommunication() } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().StopServer() + if a.Metrics != nil { + a.Metrics.StopServer() } jobs.Srv.StopSchedulers() diff --git a/cmd/platform/user.go b/cmd/platform/user.go index a5a16049e..695e53173 100644 --- a/cmd/platform/user.go +++ b/cmd/platform/user.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/mattermost/mattermost-server/app" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "github.com/spf13/cobra" @@ -320,7 +319,7 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error { } func resetUserMfaCmdF(cmd *cobra.Command, args []string) error { - _, err := initDBCommandContextCobra(cmd) + a, err := initDBCommandContextCobra(cmd) if err != nil { return err } @@ -336,7 +335,7 @@ func resetUserMfaCmdF(cmd *cobra.Command, args []string) error { return errors.New("Unable to find user '" + args[i] + "'") } - if err := app.DeactivateMfa(user.Id); err != nil { + if err := a.DeactivateMfa(user.Id); err != nil { return err } } @@ -420,7 +419,7 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error { } func migrateAuthCmdF(cmd *cobra.Command, args []string) error { - _, err := initDBCommandContextCobra(cmd) + a, err := initDBCommandContextCobra(cmd) if err != nil { return err } @@ -452,7 +451,7 @@ func migrateAuthCmdF(cmd *cobra.Command, args []string) error { forceFlag, _ := cmd.Flags().GetBool("force") - if migrate := einterfaces.GetAccountMigrationInterface(); migrate != nil { + if migrate := a.AccountMigration; migrate != nil { if err := migrate.MigrateToLdap(fromAuth, matchField, forceFlag); err != nil { return errors.New("Error while migrating users: " + err.Error()) } diff --git a/utils/config.go b/utils/config.go index 94737adc8..a4b475449 100644 --- a/utils/config.go +++ b/utils/config.go @@ -689,11 +689,3 @@ func Desanitize(cfg *model.Config) { cfg.SqlSettings.DataSourceSearchReplicas[i] = Cfg.SqlSettings.DataSourceSearchReplicas[i] } } - -func IsLeader() bool { - if IsLicensed() && *Cfg.ClusterSettings.Enable && einterfaces.GetClusterInterface() != nil { - return einterfaces.GetClusterInterface().IsLeader() - } else { - return true - } -} -- cgit v1.2.3-1-g7c22