2017-06-29 22:40:14 +01:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2017-09-06 23:05:10 -07:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
2017-06-29 22:40:14 +01:00
|
|
|
)
|
|
|
|
|
|
2017-09-19 18:31:35 -05:00
|
|
|
func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError {
|
2017-07-27 08:48:02 +01:00
|
|
|
if *cfg.ElasticsearchSettings.Password == model.FAKE_SETTING {
|
2017-10-18 15:36:43 -07:00
|
|
|
if *cfg.ElasticsearchSettings.ConnectionUrl == *a.Config().ElasticsearchSettings.ConnectionUrl && *cfg.ElasticsearchSettings.Username == *a.Config().ElasticsearchSettings.Username {
|
|
|
|
|
*cfg.ElasticsearchSettings.Password = *a.Config().ElasticsearchSettings.Password
|
2017-07-07 17:12:14 +01:00
|
|
|
} else {
|
|
|
|
|
return model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.reenter_password", nil, "", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 18:31:35 -05:00
|
|
|
if esI := a.Elasticsearch; esI != nil {
|
2017-07-07 17:12:14 +01:00
|
|
|
if err := esI.TestConfig(cfg); err != nil {
|
2017-06-29 22:40:14 +01:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
err := model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2017-07-19 09:43:05 +01:00
|
|
|
|
2017-09-19 18:31:35 -05:00
|
|
|
func (a *App) PurgeElasticsearchIndexes() *model.AppError {
|
|
|
|
|
if esI := a.Elasticsearch; esI != nil {
|
2017-07-19 09:43:05 +01:00
|
|
|
if err := esI.PurgeIndexes(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
err := model.NewAppError("PurgeElasticsearchIndexes", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|