mattermost_rust_client/apis/
ldap_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 [`get_ldap_groups`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetLdapGroupsError {
22    Status400(crate::models::AppError),
23    Status401(crate::models::AppError),
24    Status403(crate::models::AppError),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`link_ldap_group`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum LinkLdapGroupError {
32    Status400(crate::models::AppError),
33    Status401(crate::models::AppError),
34    Status403(crate::models::AppError),
35    UnknownValue(serde_json::Value),
36}
37
38
39/// ##### Permissions Must have `manage_system` permission. __Minimum server version__: 5.11 
40pub async fn get_ldap_groups(configuration: &configuration::Configuration, q: Option<&str>, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::LdapGroupsPaged>, Error<GetLdapGroupsError>> {
41    let local_var_configuration = configuration;
42
43    let local_var_client = &local_var_configuration.client;
44
45    let local_var_uri_str = format!("{}/ldap/groups", local_var_configuration.base_path);
46    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
47
48    if let Some(ref local_var_str) = q {
49        local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
50    }
51    if let Some(ref local_var_str) = page {
52        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
53    }
54    if let Some(ref local_var_str) = per_page {
55        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
56    }
57    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
58        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
59    }
60    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
61        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
62    };
63
64    let local_var_req = local_var_req_builder.build()?;
65    let local_var_resp = local_var_client.execute(local_var_req).await?;
66
67    let local_var_status = local_var_resp.status();
68    let local_var_content = local_var_resp.text().await?;
69
70    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
71        serde_json::from_str(&local_var_content).map_err(Error::from)
72    } else {
73        let local_var_entity: Option<GetLdapGroupsError> = serde_json::from_str(&local_var_content).ok();
74        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
75        Err(Error::ResponseError(local_var_error))
76    }
77}
78
79/// ##### Permissions Must have `manage_system` permission. __Minimum server version__: 5.11 
80pub async fn link_ldap_group(configuration: &configuration::Configuration, remote_id: &str) -> Result<crate::models::StatusOk, Error<LinkLdapGroupError>> {
81    let local_var_configuration = configuration;
82
83    let local_var_client = &local_var_configuration.client;
84
85    let local_var_uri_str = format!("{}/ldap/groups/{remote_id}/link", local_var_configuration.base_path, remote_id=crate::apis::urlencode(remote_id));
86    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
87
88    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
90    }
91    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
92        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
93    };
94
95    let local_var_req = local_var_req_builder.build()?;
96    let local_var_resp = local_var_client.execute(local_var_req).await?;
97
98    let local_var_status = local_var_resp.status();
99    let local_var_content = local_var_resp.text().await?;
100
101    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
102        serde_json::from_str(&local_var_content).map_err(Error::from)
103    } else {
104        let local_var_entity: Option<LinkLdapGroupError> = serde_json::from_str(&local_var_content).ok();
105        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
106        Err(Error::ResponseError(local_var_error))
107    }
108}
109