mattermost_rust_client/apis/
elasticsearch_api.rs

1/*
2 * Mattermost API Reference
3 *
4 * There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn). 
5 *
6 * The version of the OpenAPI document: 4.0.0
7 * Contact: feedback@mattermost.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`purge_elasticsearch_indexes`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum PurgeElasticsearchIndexesError {
22    Status500(crate::models::AppError),
23    Status501(crate::models::AppError),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`test_elasticsearch`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum TestElasticsearchError {
31    Status400(crate::models::AppError),
32    Status500(crate::models::AppError),
33    Status501(crate::models::AppError),
34    UnknownValue(serde_json::Value),
35}
36
37
38/// Deletes all Elasticsearch indexes and their contents. After calling this endpoint, it is necessary to schedule a new Elasticsearch indexing job to repopulate the indexes. __Minimum server version__: 4.1 ##### Permissions Must have `manage_system` permission. 
39pub async fn purge_elasticsearch_indexes(configuration: &configuration::Configuration, ) -> Result<crate::models::StatusOk, Error<PurgeElasticsearchIndexesError>> {
40    let local_var_configuration = configuration;
41
42    let local_var_client = &local_var_configuration.client;
43
44    let local_var_uri_str = format!("{}/elasticsearch/purge_indexes", local_var_configuration.base_path);
45    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
46
47    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
48        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
49    }
50    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
51        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
52    };
53
54    let local_var_req = local_var_req_builder.build()?;
55    let local_var_resp = local_var_client.execute(local_var_req).await?;
56
57    let local_var_status = local_var_resp.status();
58    let local_var_content = local_var_resp.text().await?;
59
60    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
61        serde_json::from_str(&local_var_content).map_err(Error::from)
62    } else {
63        let local_var_entity: Option<PurgeElasticsearchIndexesError> = serde_json::from_str(&local_var_content).ok();
64        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
65        Err(Error::ResponseError(local_var_error))
66    }
67}
68
69/// Test the current Elasticsearch configuration to see if the Elasticsearch server can be contacted successfully. Optionally provide a configuration in the request body to test. If no valid configuration is present in the request body the current server configuration will be tested.  __Minimum server version__: 4.1 ##### Permissions Must have `manage_system` permission. 
70pub async fn test_elasticsearch(configuration: &configuration::Configuration, ) -> Result<crate::models::StatusOk, Error<TestElasticsearchError>> {
71    let local_var_configuration = configuration;
72
73    let local_var_client = &local_var_configuration.client;
74
75    let local_var_uri_str = format!("{}/elasticsearch/test", local_var_configuration.base_path);
76    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
77
78    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
79        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
80    }
81    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
82        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
83    };
84
85    let local_var_req = local_var_req_builder.build()?;
86    let local_var_resp = local_var_client.execute(local_var_req).await?;
87
88    let local_var_status = local_var_resp.status();
89    let local_var_content = local_var_resp.text().await?;
90
91    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92        serde_json::from_str(&local_var_content).map_err(Error::from)
93    } else {
94        let local_var_entity: Option<TestElasticsearchError> = serde_json::from_str(&local_var_content).ok();
95        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
96        Err(Error::ResponseError(local_var_error))
97    }
98}
99