MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
66fc096768
Коммит
17523fa5d9
@@ -35,7 +35,7 @@ func (s *Server) Config() *model.Config {
|
||||
}
|
||||
|
||||
func (a *App) Config() *model.Config {
|
||||
return a.Srv.Config()
|
||||
return a.Srv().Config()
|
||||
}
|
||||
|
||||
func (s *Server) EnvironmentConfig() map[string]interface{} {
|
||||
@@ -43,7 +43,7 @@ func (s *Server) EnvironmentConfig() map[string]interface{} {
|
||||
}
|
||||
|
||||
func (a *App) EnvironmentConfig() map[string]interface{} {
|
||||
return a.Srv.EnvironmentConfig()
|
||||
return a.Srv().EnvironmentConfig()
|
||||
}
|
||||
|
||||
func (s *Server) UpdateConfig(f func(*model.Config)) {
|
||||
@@ -56,7 +56,7 @@ func (s *Server) UpdateConfig(f func(*model.Config)) {
|
||||
}
|
||||
|
||||
func (a *App) UpdateConfig(f func(*model.Config)) {
|
||||
a.Srv.UpdateConfig(f)
|
||||
a.Srv().UpdateConfig(f)
|
||||
}
|
||||
|
||||
func (s *Server) ReloadConfig() error {
|
||||
@@ -68,19 +68,19 @@ func (s *Server) ReloadConfig() error {
|
||||
}
|
||||
|
||||
func (a *App) ReloadConfig() error {
|
||||
return a.Srv.ReloadConfig()
|
||||
return a.Srv().ReloadConfig()
|
||||
}
|
||||
|
||||
func (a *App) ClientConfig() map[string]string {
|
||||
return a.Srv.clientConfig
|
||||
return a.Srv().clientConfig
|
||||
}
|
||||
|
||||
func (a *App) ClientConfigHash() string {
|
||||
return a.Srv.clientConfigHash
|
||||
return a.Srv().clientConfigHash
|
||||
}
|
||||
|
||||
func (a *App) LimitedClientConfig() map[string]string {
|
||||
return a.Srv.limitedClientConfig
|
||||
return a.Srv().limitedClientConfig
|
||||
}
|
||||
|
||||
// Registers a function with a given listener to be called when the config is reloaded and may have changed. The function
|
||||
@@ -91,7 +91,7 @@ func (s *Server) AddConfigListener(listener func(*model.Config, *model.Config))
|
||||
}
|
||||
|
||||
func (a *App) AddConfigListener(listener func(*model.Config, *model.Config)) string {
|
||||
return a.Srv.AddConfigListener(listener)
|
||||
return a.Srv().AddConfigListener(listener)
|
||||
}
|
||||
|
||||
// Removes a listener function by the unique ID returned when AddConfigListener was called
|
||||
@@ -100,20 +100,20 @@ func (s *Server) RemoveConfigListener(id string) {
|
||||
}
|
||||
|
||||
func (a *App) RemoveConfigListener(id string) {
|
||||
a.Srv.RemoveConfigListener(id)
|
||||
a.Srv().RemoveConfigListener(id)
|
||||
}
|
||||
|
||||
// ensurePostActionCookieSecret ensures that the key for encrypting PostActionCookie exists
|
||||
// and future calls to PostActionCookieSecret will always return a valid key, same on all
|
||||
// servers in the cluster
|
||||
func (a *App) ensurePostActionCookieSecret() error {
|
||||
if a.Srv.postActionCookieSecret != nil {
|
||||
if a.Srv().postActionCookieSecret != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var secret *model.SystemPostActionCookieSecret
|
||||
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &secret); err != nil {
|
||||
return err
|
||||
@@ -139,7 +139,7 @@ func (a *App) ensurePostActionCookieSecret() error {
|
||||
}
|
||||
system.Value = string(v)
|
||||
// If we were able to save the key, use it, otherwise log the error.
|
||||
if appErr := a.Srv.Store.System().Save(system); appErr != nil {
|
||||
if appErr := a.Srv().Store.System().Save(system); appErr != nil {
|
||||
mlog.Error("Failed to save PostActionCookieSecret", mlog.Err(appErr))
|
||||
} else {
|
||||
secret = newSecret
|
||||
@@ -149,7 +149,7 @@ func (a *App) ensurePostActionCookieSecret() error {
|
||||
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
||||
// key from the database, and if that fails, error out.
|
||||
if secret == nil {
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -159,20 +159,20 @@ func (a *App) ensurePostActionCookieSecret() error {
|
||||
}
|
||||
}
|
||||
|
||||
a.Srv.postActionCookieSecret = secret.Secret
|
||||
a.Srv().postActionCookieSecret = secret.Secret
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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.Srv.asymmetricSigningKey != nil {
|
||||
if a.Srv().asymmetricSigningKey != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var key *model.SystemAsymmetricSigningKey
|
||||
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &key); err != nil {
|
||||
return err
|
||||
@@ -202,7 +202,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
}
|
||||
system.Value = string(v)
|
||||
// If we were able to save the key, use it, otherwise log the error.
|
||||
if appErr := a.Srv.Store.System().Save(system); appErr != nil {
|
||||
if appErr := a.Srv().Store.System().Save(system); appErr != nil {
|
||||
mlog.Error("Failed to save AsymmetricSigningKey", mlog.Err(appErr))
|
||||
} else {
|
||||
key = newKey
|
||||
@@ -212,7 +212,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
||||
// key from the database, and if that fails, error out.
|
||||
if key == nil {
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
default:
|
||||
return fmt.Errorf("unknown curve: " + key.ECDSAKey.Curve)
|
||||
}
|
||||
a.Srv.asymmetricSigningKey = &ecdsa.PrivateKey{
|
||||
a.Srv().asymmetricSigningKey = &ecdsa.PrivateKey{
|
||||
PublicKey: ecdsa.PublicKey{
|
||||
Curve: curve,
|
||||
X: key.ECDSAKey.X,
|
||||
@@ -247,7 +247,7 @@ func (a *App) ensureInstallationDate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
installDate, err := a.Srv.Store.User().InferSystemInstallDate()
|
||||
installDate, err := a.Srv().Store.User().InferSystemInstallDate()
|
||||
var installationDate int64
|
||||
if err == nil && installDate > 0 {
|
||||
installationDate = installDate
|
||||
@@ -255,7 +255,7 @@ func (a *App) ensureInstallationDate() error {
|
||||
installationDate = utils.MillisFromTime(time.Now())
|
||||
}
|
||||
|
||||
err = a.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
err = a.Srv().Store.System().SaveOrUpdate(&model.System{
|
||||
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
|
||||
Value: strconv.FormatInt(installationDate, 10),
|
||||
})
|
||||
@@ -271,7 +271,7 @@ func (s *Server) AsymmetricSigningKey() *ecdsa.PrivateKey {
|
||||
}
|
||||
|
||||
func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey {
|
||||
return a.Srv.AsymmetricSigningKey()
|
||||
return a.Srv().AsymmetricSigningKey()
|
||||
}
|
||||
|
||||
func (s *Server) PostActionCookieSecret() []byte {
|
||||
@@ -279,7 +279,7 @@ func (s *Server) PostActionCookieSecret() []byte {
|
||||
}
|
||||
|
||||
func (a *App) PostActionCookieSecret() []byte {
|
||||
return a.Srv.PostActionCookieSecret()
|
||||
return a.Srv().PostActionCookieSecret()
|
||||
}
|
||||
|
||||
func (a *App) regenerateClientConfig() {
|
||||
@@ -303,9 +303,9 @@ func (a *App) regenerateClientConfig() {
|
||||
}
|
||||
|
||||
clientConfigJSON, _ := json.Marshal(clientConfig)
|
||||
a.Srv.clientConfig = clientConfig
|
||||
a.Srv.limitedClientConfig = limitedClientConfig
|
||||
a.Srv.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
a.Srv().clientConfig = clientConfig
|
||||
a.Srv().limitedClientConfig = limitedClientConfig
|
||||
a.Srv().clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
}
|
||||
|
||||
func (a *App) GetCookieDomain() string {
|
||||
@@ -356,7 +356,7 @@ func (a *App) LimitedClientConfigWithComputed() map[string]string {
|
||||
|
||||
// GetConfigFile proxies access to the given configuration file to the underlying config store.
|
||||
func (a *App) GetConfigFile(name string) ([]byte, error) {
|
||||
data, err := a.Srv.configStore.GetFile(name)
|
||||
data, err := a.Srv().configStore.GetFile(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get config file %s", name)
|
||||
}
|
||||
@@ -379,25 +379,25 @@ func (a *App) GetEnvironmentConfig() map[string]interface{} {
|
||||
|
||||
// SaveConfig replaces the active configuration, optionally notifying cluster peers.
|
||||
func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
|
||||
oldCfg, err := a.Srv.configStore.Set(newCfg)
|
||||
oldCfg, err := a.Srv().configStore.Set(newCfg)
|
||||
if errors.Cause(err) == config.ErrReadOnlyConfiguration {
|
||||
return model.NewAppError("saveConfig", "ent.cluster.save_config.error", nil, err.Error(), http.StatusForbidden)
|
||||
} else if err != nil {
|
||||
return model.NewAppError("saveConfig", "app.save_config.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if a.Metrics != nil {
|
||||
if a.Metrics() != nil {
|
||||
if *a.Config().MetricsSettings.Enable {
|
||||
a.Metrics.StartServer()
|
||||
a.Metrics().StartServer()
|
||||
} else {
|
||||
a.Metrics.StopServer()
|
||||
a.Metrics().StopServer()
|
||||
}
|
||||
}
|
||||
|
||||
if a.Cluster != nil {
|
||||
newCfg = a.Srv.configStore.RemoveEnvironmentOverrides(newCfg)
|
||||
oldCfg = a.Srv.configStore.RemoveEnvironmentOverrides(oldCfg)
|
||||
err := a.Cluster.ConfigChanged(oldCfg, newCfg, sendConfigChangeClusterMessage)
|
||||
if a.Cluster() != nil {
|
||||
newCfg = a.Srv().configStore.RemoveEnvironmentOverrides(newCfg)
|
||||
oldCfg = a.Srv().configStore.RemoveEnvironmentOverrides(oldCfg)
|
||||
err := a.Cluster().ConfigChanged(oldCfg, newCfg, sendConfigChangeClusterMessage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -407,17 +407,17 @@ func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bo
|
||||
}
|
||||
|
||||
func (a *App) IsESIndexingEnabled() bool {
|
||||
return a.Elasticsearch != nil && *a.Config().ElasticsearchSettings.EnableIndexing
|
||||
return a.Elasticsearch() != nil && *a.Config().ElasticsearchSettings.EnableIndexing
|
||||
}
|
||||
|
||||
func (a *App) IsESSearchEnabled() bool {
|
||||
esInterface := a.Elasticsearch
|
||||
esInterface := a.Elasticsearch()
|
||||
license := a.License()
|
||||
return esInterface != nil && *a.Config().ElasticsearchSettings.EnableSearching && license != nil && *license.Features.Elasticsearch
|
||||
}
|
||||
|
||||
func (a *App) IsESAutocompletionEnabled() bool {
|
||||
esInterface := a.Elasticsearch
|
||||
esInterface := a.Elasticsearch()
|
||||
license := a.License()
|
||||
return esInterface != nil && *a.Config().ElasticsearchSettings.EnableAutocomplete && license != nil && *license.Features.Elasticsearch
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user