summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-07-07 17:12:14 +0100
committerJoram Wilander <jwawilander@gmail.com>2017-07-07 12:12:14 -0400
commit39b071bc0e620b24a9dc8b13fcd6ccf5f6732ea5 (patch)
tree6bc32b749d4aeffdb349297055a9b54411e2bf9c
parentdb2f6cf0766543b6d9e9fb4ecd10947ce60b46b9 (diff)
downloadchat-39b071bc0e620b24a9dc8b13fcd6ccf5f6732ea5.tar.gz
chat-39b071bc0e620b24a9dc8b13fcd6ccf5f6732ea5.tar.bz2
chat-39b071bc0e620b24a9dc8b13fcd6ccf5f6732ea5.zip
Add optional config parameter to test elasticsearch endpoint. (#6877)
-rw-r--r--api4/elasticsearch.go7
-rw-r--r--app/elasticsearch.go13
-rw-r--r--einterfaces/elasticsearch.go2
-rw-r--r--i18n/en.json4
4 files changed, 22 insertions, 4 deletions
diff --git a/api4/elasticsearch.go b/api4/elasticsearch.go
index 05ef1f539..9eafec48b 100644
--- a/api4/elasticsearch.go
+++ b/api4/elasticsearch.go
@@ -19,12 +19,17 @@ func InitElasticsearch() {
}
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
+ cfg := model.ConfigFromJson(r.Body)
+ if cfg == nil {
+ cfg = utils.Cfg
+ }
+
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
- if err := app.TestElasticsearch(); err != nil {
+ if err := app.TestElasticsearch(cfg); err != nil {
c.Err = err
return
}
diff --git a/app/elasticsearch.go b/app/elasticsearch.go
index 87687ddcc..ef34a6074 100644
--- a/app/elasticsearch.go
+++ b/app/elasticsearch.go
@@ -8,11 +8,20 @@ import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/einterfaces"
+ "github.com/mattermost/platform/utils"
)
-func TestElasticsearch() *model.AppError {
+func TestElasticsearch(cfg *model.Config) *model.AppError {
+ if *cfg.ElasticSearchSettings.Password == model.FAKE_SETTING {
+ if *cfg.ElasticSearchSettings.ConnectionUrl == *utils.Cfg.ElasticSearchSettings.ConnectionUrl && *cfg.ElasticSearchSettings.Username == *utils.Cfg.ElasticSearchSettings.Username {
+ *cfg.ElasticSearchSettings.Password = *utils.Cfg.ElasticSearchSettings.Password
+ } else {
+ return model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.reenter_password", nil, "", http.StatusBadRequest)
+ }
+ }
+
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
- if err := esI.TestConfig(); err != nil {
+ if err := esI.TestConfig(cfg); err != nil {
return err
}
} else {
diff --git a/einterfaces/elasticsearch.go b/einterfaces/elasticsearch.go
index e4803aa88..f5babffe0 100644
--- a/einterfaces/elasticsearch.go
+++ b/einterfaces/elasticsearch.go
@@ -10,7 +10,7 @@ type ElasticsearchInterface interface {
IndexPost(post *model.Post, teamId string) *model.AppError
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
DeletePost(postId string) *model.AppError
- TestConfig() *model.AppError
+ TestConfig(cfg *model.Config) *model.AppError
}
var theElasticsearchInterface ElasticsearchInterface
diff --git a/i18n/en.json b/i18n/en.json
index 88ada5ba4..d6eaffc7f 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -3548,6 +3548,10 @@
"translation": "License does not support Elasticsearch."
},
{
+ "id": "ent.elasticsearch.test_config.reenter_password",
+ "translation": "The Elasticsearch Server URL or Username has changed. Please re-enter the Elasticsearch password to test connection."
+ },
+ {
"id": "ent.emoji.licence_disable.app_error",
"translation": "Custom emoji restrictions disabled by current license. Please contact your system administrator about upgrading your enterprise license."
},