summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/admin.go4
-rw-r--r--app/app.go94
-rw-r--r--app/cluster_discovery.go16
-rw-r--r--app/cluster_discovery_test.go4
-rw-r--r--app/server.go2
5 files changed, 99 insertions, 21 deletions
diff --git a/app/admin.go b/app/admin.go
index 1bd33527b..022d86f3c 100644
--- a/app/admin.go
+++ b/app/admin.go
@@ -149,7 +149,7 @@ func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool)
return err
}
- if err := utils.ValidateLdapFilter(cfg); err != nil {
+ if err := utils.ValidateLdapFilter(cfg, a.Ldap); err != nil {
return err
}
@@ -187,7 +187,7 @@ func (a *App) RecycleDatabaseConnection() {
oldStore := a.Srv.Store
l4g.Warn(utils.T("api.admin.recycle_db_start.warn"))
- a.Srv.Store = store.NewLayeredStore()
+ a.Srv.Store = store.NewLayeredStore(a.Metrics, a.Cluster)
jobs.Srv.Store = a.Srv.Store
diff --git a/app/app.go b/app/app.go
index bf4a6b1b6..1289e4a6d 100644
--- a/app/app.go
+++ b/app/app.go
@@ -9,7 +9,9 @@ import (
"sync"
"github.com/mattermost/mattermost-server/einterfaces"
+ "github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin/pluginenv"
+ "github.com/mattermost/mattermost-server/utils"
)
type App struct {
@@ -35,19 +37,93 @@ 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()
+ globalApp.initEnterprise()
})
return &globalApp
}
+var accountMigrationInterface func(*App) einterfaces.AccountMigrationInterface
+
+func RegisterAccountMigrationInterface(f func(*App) einterfaces.AccountMigrationInterface) {
+ accountMigrationInterface = f
+}
+
+var clusterInterface func(*App) einterfaces.ClusterInterface
+
+func RegisterClusterInterface(f func(*App) einterfaces.ClusterInterface) {
+ clusterInterface = f
+}
+
+var complianceInterface func(*App) einterfaces.ComplianceInterface
+
+func RegisterComplianceInterface(f func(*App) einterfaces.ComplianceInterface) {
+ complianceInterface = f
+}
+
+var ldapInterface func(*App) einterfaces.LdapInterface
+
+func RegisterLdapInterface(f func(*App) einterfaces.LdapInterface) {
+ ldapInterface = f
+}
+
+var metricsInterface func(*App) einterfaces.MetricsInterface
+
+func RegisterMetricsInterface(f func(*App) einterfaces.MetricsInterface) {
+ metricsInterface = f
+}
+
+var mfaInterface func(*App) einterfaces.MfaInterface
+
+func RegisterMfaInterface(f func(*App) einterfaces.MfaInterface) {
+ mfaInterface = f
+}
+
+var samlInterface func(*App) einterfaces.SamlInterface
+
+func RegisterSamlInterface(f func(*App) einterfaces.SamlInterface) {
+ samlInterface = f
+}
+
+func (a *App) initEnterprise() {
+ if accountMigrationInterface != nil {
+ a.AccountMigration = accountMigrationInterface(a)
+ }
+ a.Brand = einterfaces.GetBrandInterface()
+ if clusterInterface != nil {
+ a.Cluster = clusterInterface(a)
+ }
+ if complianceInterface != nil {
+ a.Compliance = complianceInterface(a)
+ }
+ a.Elasticsearch = einterfaces.GetElasticsearchInterface()
+ if ldapInterface != nil {
+ a.Ldap = ldapInterface(a)
+ utils.AddConfigListener(func(_, cfg *model.Config) {
+ if err := utils.ValidateLdapFilter(cfg, a.Ldap); err != nil {
+ panic(utils.T(err.Id))
+ }
+
+ a.Ldap.StartLdapSyncJob()
+ })
+ }
+ if metricsInterface != nil {
+ a.Metrics = metricsInterface(a)
+ }
+ if mfaInterface != nil {
+ a.Mfa = mfaInterface(a)
+ }
+ if samlInterface != nil {
+ a.Saml = samlInterface(a)
+ utils.AddConfigListener(func(_, cfg *model.Config) {
+ a.Saml.ConfigureSP()
+ })
+ }
+}
+
+func (a *App) Config() *model.Config {
+ return utils.Cfg
+}
+
func CloseBody(r *http.Response) {
if r.Body != nil {
ioutil.ReadAll(r.Body)
diff --git a/app/cluster_discovery.go b/app/cluster_discovery.go
index 223b012dd..5278b339d 100644
--- a/app/cluster_discovery.go
+++ b/app/cluster_discovery.go
@@ -18,12 +18,14 @@ const (
type ClusterDiscoveryService struct {
model.ClusterDiscovery
+ app *App
stop chan bool
}
-func NewClusterDiscoveryService() *ClusterDiscoveryService {
+func (a *App) NewClusterDiscoveryService() *ClusterDiscoveryService {
ds := &ClusterDiscoveryService{
ClusterDiscovery: model.ClusterDiscovery{},
+ app: a,
stop: make(chan bool),
}
@@ -32,19 +34,19 @@ func NewClusterDiscoveryService() *ClusterDiscoveryService {
func (me *ClusterDiscoveryService) Start() {
- <-Global().Srv.Store.ClusterDiscovery().Cleanup()
+ <-me.app.Srv.Store.ClusterDiscovery().Cleanup()
- if cresult := <-Global().Srv.Store.ClusterDiscovery().Exists(&me.ClusterDiscovery); cresult.Err != nil {
+ if cresult := <-me.app.Srv.Store.ClusterDiscovery().Exists(&me.ClusterDiscovery); cresult.Err != nil {
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to check if row exists for %v with err=%v", me.ClusterDiscovery.ToJson(), cresult.Err))
} else {
if cresult.Data.(bool) {
- if u := <-Global().Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
+ if u := <-me.app.Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to start clean for %v with err=%v", me.ClusterDiscovery.ToJson(), u.Err))
}
}
}
- if result := <-Global().Srv.Store.ClusterDiscovery().Save(&me.ClusterDiscovery); result.Err != nil {
+ if result := <-me.app.Srv.Store.ClusterDiscovery().Save(&me.ClusterDiscovery); result.Err != nil {
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to save for %v with err=%v", me.ClusterDiscovery.ToJson(), result.Err))
return
}
@@ -54,7 +56,7 @@ func (me *ClusterDiscoveryService) Start() {
ticker := time.NewTicker(DISCOVERY_SERVICE_WRITE_PING)
defer func() {
ticker.Stop()
- if u := <-Global().Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
+ if u := <-me.app.Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to cleanup for %v with err=%v", me.ClusterDiscovery.ToJson(), u.Err))
}
l4g.Debug(fmt.Sprintf("ClusterDiscoveryService ping writer stopped for %v", me.ClusterDiscovery.ToJson()))
@@ -63,7 +65,7 @@ func (me *ClusterDiscoveryService) Start() {
for {
select {
case <-ticker.C:
- if u := <-Global().Srv.Store.ClusterDiscovery().SetLastPingAt(&me.ClusterDiscovery); u.Err != nil {
+ if u := <-me.app.Srv.Store.ClusterDiscovery().SetLastPingAt(&me.ClusterDiscovery); u.Err != nil {
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to write ping for %v with err=%v", me.ClusterDiscovery.ToJson(), u.Err))
}
case <-me.stop:
diff --git a/app/cluster_discovery_test.go b/app/cluster_discovery_test.go
index e8ce62b5c..cd61c0f03 100644
--- a/app/cluster_discovery_test.go
+++ b/app/cluster_discovery_test.go
@@ -12,9 +12,9 @@ import (
)
func TestClusterDiscoveryService(t *testing.T) {
- Setup()
+ th := Setup()
- ds := NewClusterDiscoveryService()
+ ds := th.App.NewClusterDiscoveryService()
ds.Type = model.CDS_TYPE_APP
ds.ClusterName = "ClusterA"
ds.AutoFillHostname()
diff --git a/app/server.go b/app/server.go
index c44408d12..1564a6344 100644
--- a/app/server.go
+++ b/app/server.go
@@ -84,7 +84,7 @@ func (a *App) NewServer() {
}
func (a *App) InitStores() {
- a.Srv.Store = store.NewLayeredStore()
+ a.Srv.Store = store.NewLayeredStore(a.Metrics, a.Cluster)
}
type VaryBy struct{}