github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/app/searchengine.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package app 5 6 import ( 7 "net/http" 8 9 "github.com/vnforks/kid/v5/model" 10 "github.com/vnforks/kid/v5/services/searchengine" 11 ) 12 13 func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError { 14 if *cfg.ElasticsearchSettings.Password == model.FAKE_SETTING { 15 if *cfg.ElasticsearchSettings.ConnectionUrl == *a.Config().ElasticsearchSettings.ConnectionUrl && *cfg.ElasticsearchSettings.Username == *a.Config().ElasticsearchSettings.Username { 16 *cfg.ElasticsearchSettings.Password = *a.Config().ElasticsearchSettings.Password 17 } else { 18 return model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.reenter_password", nil, "", http.StatusBadRequest) 19 } 20 } 21 22 seI := a.SearchEngine().ElasticsearchEngine 23 if seI == nil { 24 err := model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented) 25 return err 26 } 27 if err := seI.TestConfig(cfg); err != nil { 28 return err 29 } 30 31 return nil 32 } 33 34 func (a *App) PurgeElasticsearchIndexes() *model.AppError { 35 seI := a.SearchEngine().ElasticsearchEngine 36 if seI == nil { 37 err := model.NewAppError("PurgeElasticsearchIndexes", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented) 38 return err 39 } 40 41 if err := seI.PurgeIndexes(); err != nil { 42 return err 43 } 44 45 return nil 46 } 47 48 func (a *App) SetSearchEngine(se *searchengine.Broker) { 49 a.searchEngine = se 50 }