* Removing some other fake apps

* More FakeApp removed

* Removing entirely FakeApp

* Fixing some tests

* Fixing get Cluster id from get plugin status

* Fixing failing tests

* Fixing tests

* Fixing test initialization for web

* Fixing InitServer for server tests

* Fixing InitServer for server tests

* Reverting go.sum and go.mod

* Removing unneded HTMLTemplates function in App layer

* Moving back some functions to its old place to easy the review

* Moving back some functions to its old place to easy the review

* Using the last struct2interface version

* Generating store layers

* Fixing merge problems

* Addressing PR comments

* Small fix

* Fixing app tests build

* Fixing tests

* fixing tests

* Fix tests

* Fixing tests

* Fixing tests

* Fixing tests

* Moving license to server struct

* Adding some fixes to the test compilation

* Fixing cluster and some jobs initialization

* Fixing some license tests compilation problems

* Fixing recursive cache invalidation

* Regenerating app layers

* Fix test compilation

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2020-06-12 13:43:50 +02:00
коммит произвёл GitHub
родитель f3ac33e6dc
Коммит f5eab1271b
88 изменённых файлов: 973 добавлений и 1177 удалений

Просмотреть файл

@@ -76,7 +76,7 @@ func (a *App) ClientConfig() map[string]string {
}
func (a *App) ClientConfigHash() string {
return a.Srv().clientConfigHash.Load().(string)
return a.Srv().ClientConfigHash()
}
func (a *App) LimitedClientConfig() map[string]string {
@@ -106,14 +106,14 @@ func (a *App) RemoveConfigListener(id string) {
// 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 {
func (s *Server) ensurePostActionCookieSecret() error {
if s.postActionCookieSecret != nil {
return nil
}
var secret *model.SystemPostActionCookieSecret
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
value, err := s.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 := s.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 := s.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
s.postActionCookieSecret = secret.Secret
return nil
}
// EnsureAsymmetricSigningKey ensures that an asymmetric signing key exists and future calls to
// 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 {
func (s *Server) ensureAsymmetricSigningKey() error {
if s.asymmetricSigningKey != nil {
return nil
}
var key *model.SystemAsymmetricSigningKey
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
value, err := s.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 := s.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 := s.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{
s.asymmetricSigningKey = &ecdsa.PrivateKey{
PublicKey: ecdsa.PublicKey{
Curve: curve,
X: key.ECDSAKey.X,
@@ -237,17 +237,17 @@ func (a *App) ensureAsymmetricSigningKey() error {
},
D: key.ECDSAKey.D,
}
a.regenerateClientConfig()
s.regenerateClientConfig()
return nil
}
func (a *App) ensureInstallationDate() error {
_, err := a.getSystemInstallDate()
func (s *Server) ensureInstallationDate() error {
_, err := s.getSystemInstallDate()
if err == nil {
return nil
}
installDate, err := a.Srv().Store.User().InferSystemInstallDate()
installDate, err := s.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 = s.Store.System().SaveOrUpdate(&model.System{
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
Value: strconv.FormatInt(installationDate, 10),
})
@@ -265,13 +265,13 @@ func (a *App) ensureInstallationDate() error {
return nil
}
func (a *App) ensureFirstServerRunTimestamp() error {
_, err := a.getFirstServerRunTimestamp()
func (s *Server) ensureFirstServerRunTimestamp() error {
_, err := s.getFirstServerRunTimestamp()
if err == nil {
return nil
}
err = a.Srv().Store.System().SaveOrUpdate(&model.System{
err = s.Store.System().SaveOrUpdate(&model.System{
Name: model.SYSTEM_FIRST_SERVER_RUN_TIMESTAMP_KEY,
Value: strconv.FormatInt(utils.MillisFromTime(time.Now()), 10),
})
@@ -298,12 +298,12 @@ func (a *App) PostActionCookieSecret() []byte {
return a.Srv().PostActionCookieSecret()
}
func (a *App) regenerateClientConfig() {
clientConfig := config.GenerateClientConfig(a.Config(), a.DiagnosticId(), a.License())
limitedClientConfig := config.GenerateLimitedClientConfig(a.Config(), a.DiagnosticId(), a.License())
func (s *Server) regenerateClientConfig() {
clientConfig := config.GenerateClientConfig(s.Config(), s.diagnosticId, s.License())
limitedClientConfig := config.GenerateLimitedClientConfig(s.Config(), s.diagnosticId, s.License())
if clientConfig["EnableCustomTermsOfService"] == "true" {
termsOfService, err := a.GetLatestTermsOfService()
termsOfService, err := s.Store.TermsOfService().GetLatest(true)
if err != nil {
mlog.Err(err)
} else {
@@ -312,16 +312,16 @@ func (a *App) regenerateClientConfig() {
}
}
if key := a.AsymmetricSigningKey(); key != nil {
if key := s.AsymmetricSigningKey(); key != nil {
der, _ := x509.MarshalPKIXPublicKey(&key.PublicKey)
clientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
limitedClientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
}
clientConfigJSON, _ := json.Marshal(clientConfig)
a.Srv().clientConfig.Store(clientConfig)
a.Srv().limitedClientConfig.Store(limitedClientConfig)
a.Srv().clientConfigHash.Store(fmt.Sprintf("%x", md5.Sum(clientConfigJSON)))
s.clientConfig.Store(clientConfig)
s.limitedClientConfig.Store(limitedClientConfig)
s.clientConfigHash.Store(fmt.Sprintf("%x", md5.Sum(clientConfigJSON)))
}
func (a *App) GetCookieDomain() string {
@@ -338,24 +338,29 @@ func (a *App) GetSiteURL() string {
}
// ClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
func (a *App) ClientConfigWithComputed() map[string]string {
func (s *Server) ClientConfigWithComputed() map[string]string {
respCfg := map[string]string{}
for k, v := range a.ClientConfig() {
for k, v := range s.clientConfig.Load().(map[string]string) {
respCfg[k] = v
}
// These properties are not configurable, but nevertheless represent configuration expected
// by the client.
respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount())
respCfg["MaxPostSize"] = strconv.Itoa(a.MaxPostSize())
respCfg["NoAccounts"] = strconv.FormatBool(s.IsFirstUserAccount())
respCfg["MaxPostSize"] = strconv.Itoa(s.MaxPostSize())
respCfg["InstallationDate"] = ""
if installationDate, err := a.getSystemInstallDate(); err == nil {
if installationDate, err := s.getSystemInstallDate(); err == nil {
respCfg["InstallationDate"] = strconv.FormatInt(installationDate, 10)
}
return respCfg
}
// ClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
func (a *App) ClientConfigWithComputed() map[string]string {
return a.Srv().ClientConfigWithComputed()
}
// LimitedClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
func (a *App) LimitedClientConfigWithComputed() map[string]string {
respCfg := map[string]string{}
@@ -394,26 +399,26 @@ 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)
func (s *Server) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
oldCfg, err := s.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.Config().MetricsSettings.Enable {
a.Metrics().StartServer()
if s.Metrics != nil {
if *s.Config().MetricsSettings.Enable {
s.Metrics.StartServer()
} else {
a.Metrics().StopServer()
s.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 s.Cluster != nil {
newCfg = s.configStore.RemoveEnvironmentOverrides(newCfg)
oldCfg = s.configStore.RemoveEnvironmentOverrides(oldCfg)
err := s.Cluster.ConfigChanged(oldCfg, newCfg, sendConfigChangeClusterMessage)
if err != nil {
return err
}
@@ -422,6 +427,11 @@ func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bo
return nil
}
// SaveConfig replaces the active configuration, optionally notifying cluster peers.
func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
return a.Srv().SaveConfig(newCfg, sendConfigChangeClusterMessage)
}
func (a *App) HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config) {
// If the Message Export feature has been toggled in the System Console, rewrite the ExportFromTimestamp field to an
// appropriate value. The rewriting occurs here to ensure it doesn't affect values written to the config file