1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct ImportLdapUserParams {
20 pub uid_list: models::LdapImportUsers,
22 pub x_request_id: Option<String>
24}
25
26#[derive(Clone, Debug)]
28pub struct PingLdapParams {
29 pub x_request_id: Option<String>,
31 pub ldapconf: Option<models::LdapConf>
33}
34
35#[derive(Clone, Debug)]
37pub struct SearchLdapGroupParams {
38 pub x_request_id: Option<String>,
40 pub groupname: Option<String>,
42 pub groupdn: Option<String>
44}
45
46#[derive(Clone, Debug)]
48pub struct SearchLdapUserParams {
49 pub x_request_id: Option<String>,
51 pub username: Option<String>
53}
54
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum ImportLdapUserError {
60 Status400(models::Errors),
61 Status401(models::Errors),
62 Status403(models::Errors),
63 Status404(Vec<models::LdapFailedImportUser>),
64 Status500(models::Errors),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum PingLdapError {
72 Status400(models::Errors),
73 Status401(models::Errors),
74 Status403(models::Errors),
75 Status500(models::Errors),
76 UnknownValue(serde_json::Value),
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum SearchLdapGroupError {
83 Status400(models::Errors),
84 Status401(models::Errors),
85 Status403(models::Errors),
86 Status500(models::Errors),
87 UnknownValue(serde_json::Value),
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum SearchLdapUserError {
94 Status400(models::Errors),
95 Status401(models::Errors),
96 Status403(models::Errors),
97 Status500(models::Errors),
98 UnknownValue(serde_json::Value),
99}
100
101
102pub async fn import_ldap_user(configuration: &configuration::Configuration, params: ImportLdapUserParams) -> Result<(), Error<ImportLdapUserError>> {
104
105 let uri_str = format!("{}/ldap/users/import", configuration.base_path);
106 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
107
108 if let Some(ref user_agent) = configuration.user_agent {
109 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
110 }
111 if let Some(param_value) = params.x_request_id {
112 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
113 }
114 if let Some(ref auth_conf) = configuration.basic_auth {
115 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
116 };
117 req_builder = req_builder.json(¶ms.uid_list);
118
119 let req = req_builder.build()?;
120 let resp = configuration.client.execute(req).await?;
121
122 let status = resp.status();
123
124 if !status.is_client_error() && !status.is_server_error() {
125 Ok(())
126 } else {
127 let content = resp.text().await?;
128 let entity: Option<ImportLdapUserError> = serde_json::from_str(&content).ok();
129 Err(Error::ResponseError(ResponseContent { status, content, entity }))
130 }
131}
132
133pub async fn ping_ldap(configuration: &configuration::Configuration, params: PingLdapParams) -> Result<models::LdapPingResult, Error<PingLdapError>> {
135
136 let uri_str = format!("{}/ldap/ping", configuration.base_path);
137 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139 if let Some(ref user_agent) = configuration.user_agent {
140 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141 }
142 if let Some(param_value) = params.x_request_id {
143 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
144 }
145 if let Some(ref auth_conf) = configuration.basic_auth {
146 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
147 };
148 req_builder = req_builder.json(¶ms.ldapconf);
149
150 let req = req_builder.build()?;
151 let resp = configuration.client.execute(req).await?;
152
153 let status = resp.status();
154 let content_type = resp
155 .headers()
156 .get("content-type")
157 .and_then(|v| v.to_str().ok())
158 .unwrap_or("application/octet-stream");
159 let content_type = super::ContentType::from(content_type);
160
161 if !status.is_client_error() && !status.is_server_error() {
162 let content = resp.text().await?;
163 match content_type {
164 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
165 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LdapPingResult`"))),
166 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LdapPingResult`")))),
167 }
168 } else {
169 let content = resp.text().await?;
170 let entity: Option<PingLdapError> = serde_json::from_str(&content).ok();
171 Err(Error::ResponseError(ResponseContent { status, content, entity }))
172 }
173}
174
175pub async fn search_ldap_group(configuration: &configuration::Configuration, params: SearchLdapGroupParams) -> Result<Vec<models::UserGroup>, Error<SearchLdapGroupError>> {
177
178 let uri_str = format!("{}/ldap/groups/search", configuration.base_path);
179 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
180
181 if let Some(ref param_value) = params.groupname {
182 req_builder = req_builder.query(&[("groupname", ¶m_value.to_string())]);
183 }
184 if let Some(ref param_value) = params.groupdn {
185 req_builder = req_builder.query(&[("groupdn", ¶m_value.to_string())]);
186 }
187 if let Some(ref user_agent) = configuration.user_agent {
188 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189 }
190 if let Some(param_value) = params.x_request_id {
191 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
192 }
193 if let Some(ref auth_conf) = configuration.basic_auth {
194 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
195 };
196
197 let req = req_builder.build()?;
198 let resp = configuration.client.execute(req).await?;
199
200 let status = resp.status();
201 let content_type = resp
202 .headers()
203 .get("content-type")
204 .and_then(|v| v.to_str().ok())
205 .unwrap_or("application/octet-stream");
206 let content_type = super::ContentType::from(content_type);
207
208 if !status.is_client_error() && !status.is_server_error() {
209 let content = resp.text().await?;
210 match content_type {
211 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
212 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::UserGroup>`"))),
213 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::UserGroup>`")))),
214 }
215 } else {
216 let content = resp.text().await?;
217 let entity: Option<SearchLdapGroupError> = serde_json::from_str(&content).ok();
218 Err(Error::ResponseError(ResponseContent { status, content, entity }))
219 }
220}
221
222pub async fn search_ldap_user(configuration: &configuration::Configuration, params: SearchLdapUserParams) -> Result<Vec<models::LdapUser>, Error<SearchLdapUserError>> {
224
225 let uri_str = format!("{}/ldap/users/search", configuration.base_path);
226 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
227
228 if let Some(ref param_value) = params.username {
229 req_builder = req_builder.query(&[("username", ¶m_value.to_string())]);
230 }
231 if let Some(ref user_agent) = configuration.user_agent {
232 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233 }
234 if let Some(param_value) = params.x_request_id {
235 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
236 }
237 if let Some(ref auth_conf) = configuration.basic_auth {
238 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
239 };
240
241 let req = req_builder.build()?;
242 let resp = configuration.client.execute(req).await?;
243
244 let status = resp.status();
245 let content_type = resp
246 .headers()
247 .get("content-type")
248 .and_then(|v| v.to_str().ok())
249 .unwrap_or("application/octet-stream");
250 let content_type = super::ContentType::from(content_type);
251
252 if !status.is_client_error() && !status.is_server_error() {
253 let content = resp.text().await?;
254 match content_type {
255 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::LdapUser>`"))),
257 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::LdapUser>`")))),
258 }
259 } else {
260 let content = resp.text().await?;
261 let entity: Option<SearchLdapUserError> = serde_json::from_str(&content).ok();
262 Err(Error::ResponseError(ResponseContent { status, content, entity }))
263 }
264}
265