MM-12849 Moving all non request scoped items to Server struct (#9806)
* Moving goroutine pool * Auto refactor * Moving plugins. * Auto refactor * Moving fields to server * Auto refactor * Removing siteurl duplication. * Moving reset of app fields * Auto refactor * Formatting * Moving niling of Server to after last use * Fixing unit tests.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0dcbecac87
Коммит
ecade2f1ec
@@ -28,15 +28,15 @@ const (
|
||||
)
|
||||
|
||||
func (a *App) Config() *model.Config {
|
||||
if cfg := a.config.Load(); cfg != nil {
|
||||
if cfg := a.Srv.config.Load(); cfg != nil {
|
||||
return cfg.(*model.Config)
|
||||
}
|
||||
return &model.Config{}
|
||||
}
|
||||
|
||||
func (a *App) EnvironmentConfig() map[string]interface{} {
|
||||
if a.envConfig != nil {
|
||||
return a.envConfig
|
||||
if a.Srv.envConfig != nil {
|
||||
return a.Srv.envConfig
|
||||
}
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (a *App) UpdateConfig(f func(*model.Config)) {
|
||||
old := a.Config()
|
||||
updated := old.Clone()
|
||||
f(updated)
|
||||
a.config.Store(updated)
|
||||
a.Srv.config.Store(updated)
|
||||
|
||||
a.InvokeConfigListeners(old, updated)
|
||||
}
|
||||
@@ -62,11 +62,10 @@ func (a *App) LoadConfig(configFile string) *model.AppError {
|
||||
return err
|
||||
}
|
||||
*cfg.ServiceSettings.SiteURL = strings.TrimRight(*cfg.ServiceSettings.SiteURL, "/")
|
||||
a.config.Store(cfg)
|
||||
a.Srv.config.Store(cfg)
|
||||
|
||||
a.configFile = configPath
|
||||
a.envConfig = envConfig
|
||||
a.siteURL = *cfg.ServiceSettings.SiteURL
|
||||
a.Srv.configFile = configPath
|
||||
a.Srv.envConfig = envConfig
|
||||
|
||||
a.InvokeConfigListeners(old, cfg)
|
||||
return nil
|
||||
@@ -74,7 +73,7 @@ func (a *App) LoadConfig(configFile string) *model.AppError {
|
||||
|
||||
func (a *App) ReloadConfig() *model.AppError {
|
||||
debug.FreeOSMemory()
|
||||
if err := a.LoadConfig(a.configFile); err != nil {
|
||||
if err := a.LoadConfig(a.Srv.configFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -84,37 +83,37 @@ func (a *App) ReloadConfig() *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) ConfigFileName() string {
|
||||
return a.configFile
|
||||
return a.Srv.configFile
|
||||
}
|
||||
|
||||
func (a *App) ClientConfig() map[string]string {
|
||||
return a.clientConfig
|
||||
return a.Srv.clientConfig
|
||||
}
|
||||
|
||||
func (a *App) ClientConfigHash() string {
|
||||
return a.clientConfigHash
|
||||
return a.Srv.clientConfigHash
|
||||
}
|
||||
|
||||
func (a *App) LimitedClientConfig() map[string]string {
|
||||
return a.limitedClientConfig
|
||||
return a.Srv.limitedClientConfig
|
||||
}
|
||||
|
||||
func (a *App) EnableConfigWatch() {
|
||||
if a.configWatcher == nil && !a.disableConfigWatch {
|
||||
if a.Srv.configWatcher == nil && !a.Srv.disableConfigWatch {
|
||||
configWatcher, err := utils.NewConfigWatcher(a.ConfigFileName(), func() {
|
||||
a.ReloadConfig()
|
||||
})
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprint(err))
|
||||
}
|
||||
a.configWatcher = configWatcher
|
||||
a.Srv.configWatcher = configWatcher
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) DisableConfigWatch() {
|
||||
if a.configWatcher != nil {
|
||||
a.configWatcher.Close()
|
||||
a.configWatcher = nil
|
||||
if a.Srv.configWatcher != nil {
|
||||
a.Srv.configWatcher.Close()
|
||||
a.Srv.configWatcher = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,17 +122,17 @@ func (a *App) DisableConfigWatch() {
|
||||
// for the listener that can later be used to remove it.
|
||||
func (a *App) AddConfigListener(listener func(*model.Config, *model.Config)) string {
|
||||
id := model.NewId()
|
||||
a.configListeners[id] = listener
|
||||
a.Srv.configListeners[id] = listener
|
||||
return id
|
||||
}
|
||||
|
||||
// Removes a listener function by the unique ID returned when AddConfigListener was called
|
||||
func (a *App) RemoveConfigListener(id string) {
|
||||
delete(a.configListeners, id)
|
||||
delete(a.Srv.configListeners, id)
|
||||
}
|
||||
|
||||
func (a *App) InvokeConfigListeners(old, current *model.Config) {
|
||||
for _, listener := range a.configListeners {
|
||||
for _, listener := range a.Srv.configListeners {
|
||||
listener(old, current)
|
||||
}
|
||||
}
|
||||
@@ -141,7 +140,7 @@ func (a *App) InvokeConfigListeners(old, current *model.Config) {
|
||||
// EnsureAsymmetricSigningKey ensures that an asymmetric signing key exists and future calls to
|
||||
// AsymmetricSigningKey will always return a valid signing key.
|
||||
func (a *App) ensureAsymmetricSigningKey() error {
|
||||
if a.asymmetricSigningKey != nil {
|
||||
if a.Srv.asymmetricSigningKey != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -202,7 +201,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
default:
|
||||
return fmt.Errorf("unknown curve: " + key.ECDSAKey.Curve)
|
||||
}
|
||||
a.asymmetricSigningKey = &ecdsa.PrivateKey{
|
||||
a.Srv.asymmetricSigningKey = &ecdsa.PrivateKey{
|
||||
PublicKey: ecdsa.PublicKey{
|
||||
Curve: curve,
|
||||
X: key.ECDSAKey.X,
|
||||
@@ -240,31 +239,31 @@ func (a *App) ensureInstallationDate() error {
|
||||
|
||||
// AsymmetricSigningKey will return a private key that can be used for asymmetric signing.
|
||||
func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey {
|
||||
return a.asymmetricSigningKey
|
||||
return a.Srv.asymmetricSigningKey
|
||||
}
|
||||
|
||||
func (a *App) regenerateClientConfig() {
|
||||
a.clientConfig = utils.GenerateClientConfig(a.Config(), a.DiagnosticId(), a.License())
|
||||
a.Srv.clientConfig = utils.GenerateClientConfig(a.Config(), a.DiagnosticId(), a.License())
|
||||
|
||||
if a.clientConfig["EnableCustomTermsOfService"] == "true" {
|
||||
if a.Srv.clientConfig["EnableCustomTermsOfService"] == "true" {
|
||||
termsOfService, err := a.GetLatestTermsOfService()
|
||||
if err != nil {
|
||||
mlog.Err(err)
|
||||
} else {
|
||||
a.clientConfig["CustomTermsOfServiceId"] = termsOfService.Id
|
||||
a.Srv.clientConfig["CustomTermsOfServiceId"] = termsOfService.Id
|
||||
}
|
||||
}
|
||||
|
||||
a.limitedClientConfig = utils.GenerateLimitedClientConfig(a.Config(), a.DiagnosticId(), a.License())
|
||||
a.Srv.limitedClientConfig = utils.GenerateLimitedClientConfig(a.Config(), a.DiagnosticId(), a.License())
|
||||
|
||||
if key := a.AsymmetricSigningKey(); key != nil {
|
||||
der, _ := x509.MarshalPKIXPublicKey(&key.PublicKey)
|
||||
a.clientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
|
||||
a.limitedClientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
|
||||
a.Srv.clientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
|
||||
a.Srv.limitedClientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
|
||||
}
|
||||
|
||||
clientConfigJSON, _ := json.Marshal(a.clientConfig)
|
||||
a.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
clientConfigJSON, _ := json.Marshal(a.Srv.clientConfig)
|
||||
a.Srv.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
}
|
||||
|
||||
func (a *App) Desanitize(cfg *model.Config) {
|
||||
@@ -322,7 +321,7 @@ func (a *App) GetCookieDomain() string {
|
||||
}
|
||||
|
||||
func (a *App) GetSiteURL() string {
|
||||
return a.siteURL
|
||||
return *a.Config().ServiceSettings.SiteURL
|
||||
}
|
||||
|
||||
// ClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
|
||||
|
||||
Ссылка в новой задаче
Block a user