summaryrefslogtreecommitdiffstats
path: root/app/app.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-09-21 04:13:34 -0500
committerGeorge Goldberg <george@gberg.me>2017-09-21 10:13:34 +0100
commit266ff8670244da288aec937320d9eecc7996af35 (patch)
tree39e4e528cda0abb24be317683516ee246717fc68 /app/app.go
parentadab1a660fdc0c307238279edc7a9918d14577e5 (diff)
downloadchat-266ff8670244da288aec937320d9eecc7996af35.tar.gz
chat-266ff8670244da288aec937320d9eecc7996af35.tar.bz2
chat-266ff8670244da288aec937320d9eecc7996af35.zip
remove more global refs (#7480)
Diffstat (limited to 'app/app.go')
-rw-r--r--app/app.go94
1 files changed, 85 insertions, 9 deletions
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)