diff options
author | George Goldberg <george@gberg.me> | 2017-07-19 09:43:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-19 09:43:05 +0100 |
commit | fe368a74565e736ad1fb1dfc20ab364379d83ae9 (patch) | |
tree | 56186c11129a4aadc068a6387af39288cc9802b7 /api4 | |
parent | 97f34e483b0fa8b2a8cfe75b72168cfa38cc9d80 (diff) | |
download | chat-fe368a74565e736ad1fb1dfc20ab364379d83ae9.tar.gz chat-fe368a74565e736ad1fb1dfc20ab364379d83ae9.tar.bz2 chat-fe368a74565e736ad1fb1dfc20ab364379d83ae9.zip |
PLT-6595: API to purge Elasticsearch indexes. (#6971)
Diffstat (limited to 'api4')
-rw-r--r-- | api4/elasticsearch.go | 15 | ||||
-rw-r--r-- | api4/elasticsearch_test.go | 11 |
2 files changed, 26 insertions, 0 deletions
diff --git a/api4/elasticsearch.go b/api4/elasticsearch.go index 9eafec48b..c8af8089b 100644 --- a/api4/elasticsearch.go +++ b/api4/elasticsearch.go @@ -16,6 +16,7 @@ func InitElasticsearch() { l4g.Debug(utils.T("api.elasticsearch.init.debug")) BaseRoutes.Elasticsearch.Handle("/test", ApiSessionRequired(testElasticsearch)).Methods("POST") + BaseRoutes.Elasticsearch.Handle("/purge_indexes", ApiSessionRequired(purgeElasticsearchIndexes)).Methods("POST") } func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) { @@ -36,3 +37,17 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) { ReturnStatusOK(w) } + +func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Request) { + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + if err := app.PurgeElasticsearchIndexes(); err != nil { + c.Err = err + return + } + + ReturnStatusOK(w) +} diff --git a/api4/elasticsearch_test.go b/api4/elasticsearch_test.go index 1478f052f..768a73ad7 100644 --- a/api4/elasticsearch_test.go +++ b/api4/elasticsearch_test.go @@ -17,3 +17,14 @@ func TestElasticsearchTest(t *testing.T) { _, resp = th.SystemAdminClient.TestElasticsearch() CheckNotImplementedStatus(t, resp) } + +func TestElasticsearchPurgeIndexes(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() + + _, resp := th.Client.PurgeElasticsearchIndexes() + CheckForbiddenStatus(t, resp) + + _, resp = th.SystemAdminClient.PurgeElasticsearchIndexes() + CheckNotImplementedStatus(t, resp) +} |