1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessTfaAddTfaEntryError {
22 Status400(models::PveError),
23 Status401(models::PveError),
24 Status403(models::PveError),
25 Status404(models::PveError),
26 Status500(models::PveError),
27 Status501(models::PveError),
28 Status503(models::PveError),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessTfaDeleteTfaError {
36 Status400(models::PveError),
37 Status401(models::PveError),
38 Status403(models::PveError),
39 Status404(models::PveError),
40 Status500(models::PveError),
41 Status501(models::PveError),
42 Status503(models::PveError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AccessTfaGetTfaEntryError {
50 Status400(models::PveError),
51 Status401(models::PveError),
52 Status403(models::PveError),
53 Status404(models::PveError),
54 Status500(models::PveError),
55 Status501(models::PveError),
56 Status503(models::PveError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum AccessTfaListTfaError {
64 Status400(models::PveError),
65 Status401(models::PveError),
66 Status403(models::PveError),
67 Status404(models::PveError),
68 Status500(models::PveError),
69 Status501(models::PveError),
70 Status503(models::PveError),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum AccessTfaListUserTfaError {
78 Status400(models::PveError),
79 Status401(models::PveError),
80 Status403(models::PveError),
81 Status404(models::PveError),
82 Status500(models::PveError),
83 Status501(models::PveError),
84 Status503(models::PveError),
85 UnknownValue(serde_json::Value),
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum AccessTfaUpdateTfaEntryError {
92 Status400(models::PveError),
93 Status401(models::PveError),
94 Status403(models::PveError),
95 Status404(models::PveError),
96 Status500(models::PveError),
97 Status501(models::PveError),
98 Status503(models::PveError),
99 UnknownValue(serde_json::Value),
100}
101
102
103pub async fn access_tfa_add_tfa_entry(configuration: &configuration::Configuration, userid: &str, access_tfa_add_tfa_entry_request: models::AccessTfaAddTfaEntryRequest) -> Result<models::AccessTfaAddTfaEntryResponse, Error<AccessTfaAddTfaEntryError>> {
105 let p_path_userid = userid;
107 let p_body_access_tfa_add_tfa_entry_request = access_tfa_add_tfa_entry_request;
108
109 let uri_str = format!("{}/access/tfa/{userid}", configuration.base_path, userid=crate::apis::urlencode(p_path_userid));
110 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
111
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 if let Some(ref apikey) = configuration.api_key {
116 let key = apikey.key.clone();
117 let value = match apikey.prefix {
118 Some(ref prefix) => format!("{} {}", prefix, key),
119 None => key,
120 };
121 req_builder = req_builder.header("CSRFPreventionToken", value);
122 };
123 req_builder = req_builder.json(&p_body_access_tfa_add_tfa_entry_request);
124
125 let req = req_builder.build()?;
126 let resp = configuration.client.execute(req).await?;
127
128 let status = resp.status();
129 let content_type = resp
130 .headers()
131 .get("content-type")
132 .and_then(|v| v.to_str().ok())
133 .unwrap_or("application/octet-stream");
134 let content_type = super::ContentType::from(content_type);
135
136 if !status.is_client_error() && !status.is_server_error() {
137 let content = resp.text().await?;
138 match content_type {
139 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
140 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaAddTfaEntryResponse`"))),
141 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::AccessTfaAddTfaEntryResponse`")))),
142 }
143 } else {
144 let content = resp.text().await?;
145 let entity: Option<AccessTfaAddTfaEntryError> = serde_json::from_str(&content).ok();
146 Err(Error::ResponseError(ResponseContent { status, content, entity }))
147 }
148}
149
150pub async fn access_tfa_delete_tfa(configuration: &configuration::Configuration, id: &str, userid: &str, password: Option<&str>) -> Result<models::AccessTfaDeleteTfaResponse, Error<AccessTfaDeleteTfaError>> {
152 let p_path_id = id;
154 let p_path_userid = userid;
155 let p_query_password = password;
156
157 let uri_str = format!("{}/access/tfa/{userid}/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), userid=crate::apis::urlencode(p_path_userid));
158 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
159
160 if let Some(ref param_value) = p_query_password {
161 req_builder = req_builder.query(&[("password", ¶m_value.to_string())]);
162 }
163 if let Some(ref user_agent) = configuration.user_agent {
164 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
165 }
166 if let Some(ref apikey) = configuration.api_key {
167 let key = apikey.key.clone();
168 let value = match apikey.prefix {
169 Some(ref prefix) => format!("{} {}", prefix, key),
170 None => key,
171 };
172 req_builder = req_builder.header("CSRFPreventionToken", value);
173 };
174
175 let req = req_builder.build()?;
176 let resp = configuration.client.execute(req).await?;
177
178 let status = resp.status();
179 let content_type = resp
180 .headers()
181 .get("content-type")
182 .and_then(|v| v.to_str().ok())
183 .unwrap_or("application/octet-stream");
184 let content_type = super::ContentType::from(content_type);
185
186 if !status.is_client_error() && !status.is_server_error() {
187 let content = resp.text().await?;
188 match content_type {
189 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
190 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaDeleteTfaResponse`"))),
191 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::AccessTfaDeleteTfaResponse`")))),
192 }
193 } else {
194 let content = resp.text().await?;
195 let entity: Option<AccessTfaDeleteTfaError> = serde_json::from_str(&content).ok();
196 Err(Error::ResponseError(ResponseContent { status, content, entity }))
197 }
198}
199
200pub async fn access_tfa_get_tfa_entry(configuration: &configuration::Configuration, id: &str, userid: &str) -> Result<models::AccessTfaGetTfaEntryResponse, Error<AccessTfaGetTfaEntryError>> {
202 let p_path_id = id;
204 let p_path_userid = userid;
205
206 let uri_str = format!("{}/access/tfa/{userid}/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), userid=crate::apis::urlencode(p_path_userid));
207 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
208
209 if let Some(ref user_agent) = configuration.user_agent {
210 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
211 }
212 if let Some(ref apikey) = configuration.api_key {
213 let key = apikey.key.clone();
214 let value = match apikey.prefix {
215 Some(ref prefix) => format!("{} {}", prefix, key),
216 None => key,
217 };
218 req_builder = req_builder.header("Authorization", value);
219 };
220 if let Some(ref apikey) = configuration.api_key {
221 let key = apikey.key.clone();
222 let value = match apikey.prefix {
223 Some(ref prefix) => format!("{} {}", prefix, key),
224 None => key,
225 };
226 req_builder = req_builder.header("CSRFPreventionToken", value);
227 };
228
229 let req = req_builder.build()?;
230 let resp = configuration.client.execute(req).await?;
231
232 let status = resp.status();
233 let content_type = resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let content_type = super::ContentType::from(content_type);
239
240 if !status.is_client_error() && !status.is_server_error() {
241 let content = resp.text().await?;
242 match content_type {
243 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaGetTfaEntryResponse`"))),
245 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::AccessTfaGetTfaEntryResponse`")))),
246 }
247 } else {
248 let content = resp.text().await?;
249 let entity: Option<AccessTfaGetTfaEntryError> = serde_json::from_str(&content).ok();
250 Err(Error::ResponseError(ResponseContent { status, content, entity }))
251 }
252}
253
254pub async fn access_tfa_list_tfa(configuration: &configuration::Configuration, ) -> Result<models::AccessTfaListTfaResponse, Error<AccessTfaListTfaError>> {
256
257 let uri_str = format!("{}/access/tfa", configuration.base_path);
258 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
259
260 if let Some(ref user_agent) = configuration.user_agent {
261 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
262 }
263 if let Some(ref apikey) = configuration.api_key {
264 let key = apikey.key.clone();
265 let value = match apikey.prefix {
266 Some(ref prefix) => format!("{} {}", prefix, key),
267 None => key,
268 };
269 req_builder = req_builder.header("Authorization", value);
270 };
271 if let Some(ref apikey) = configuration.api_key {
272 let key = apikey.key.clone();
273 let value = match apikey.prefix {
274 Some(ref prefix) => format!("{} {}", prefix, key),
275 None => key,
276 };
277 req_builder = req_builder.header("CSRFPreventionToken", value);
278 };
279
280 let req = req_builder.build()?;
281 let resp = configuration.client.execute(req).await?;
282
283 let status = resp.status();
284 let content_type = resp
285 .headers()
286 .get("content-type")
287 .and_then(|v| v.to_str().ok())
288 .unwrap_or("application/octet-stream");
289 let content_type = super::ContentType::from(content_type);
290
291 if !status.is_client_error() && !status.is_server_error() {
292 let content = resp.text().await?;
293 match content_type {
294 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
295 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaListTfaResponse`"))),
296 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::AccessTfaListTfaResponse`")))),
297 }
298 } else {
299 let content = resp.text().await?;
300 let entity: Option<AccessTfaListTfaError> = serde_json::from_str(&content).ok();
301 Err(Error::ResponseError(ResponseContent { status, content, entity }))
302 }
303}
304
305pub async fn access_tfa_list_user_tfa(configuration: &configuration::Configuration, userid: &str) -> Result<models::AccessTfaListUserTfaResponse, Error<AccessTfaListUserTfaError>> {
307 let p_path_userid = userid;
309
310 let uri_str = format!("{}/access/tfa/{userid}", configuration.base_path, userid=crate::apis::urlencode(p_path_userid));
311 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
312
313 if let Some(ref user_agent) = configuration.user_agent {
314 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
315 }
316 if let Some(ref apikey) = configuration.api_key {
317 let key = apikey.key.clone();
318 let value = match apikey.prefix {
319 Some(ref prefix) => format!("{} {}", prefix, key),
320 None => key,
321 };
322 req_builder = req_builder.header("Authorization", value);
323 };
324 if let Some(ref apikey) = configuration.api_key {
325 let key = apikey.key.clone();
326 let value = match apikey.prefix {
327 Some(ref prefix) => format!("{} {}", prefix, key),
328 None => key,
329 };
330 req_builder = req_builder.header("CSRFPreventionToken", value);
331 };
332
333 let req = req_builder.build()?;
334 let resp = configuration.client.execute(req).await?;
335
336 let status = resp.status();
337 let content_type = resp
338 .headers()
339 .get("content-type")
340 .and_then(|v| v.to_str().ok())
341 .unwrap_or("application/octet-stream");
342 let content_type = super::ContentType::from(content_type);
343
344 if !status.is_client_error() && !status.is_server_error() {
345 let content = resp.text().await?;
346 match content_type {
347 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
348 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaListUserTfaResponse`"))),
349 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::AccessTfaListUserTfaResponse`")))),
350 }
351 } else {
352 let content = resp.text().await?;
353 let entity: Option<AccessTfaListUserTfaError> = serde_json::from_str(&content).ok();
354 Err(Error::ResponseError(ResponseContent { status, content, entity }))
355 }
356}
357
358pub async fn access_tfa_update_tfa_entry(configuration: &configuration::Configuration, id: &str, userid: &str, access_tfa_update_tfa_entry_request: Option<models::AccessTfaUpdateTfaEntryRequest>) -> Result<models::AccessTfaUpdateTfaEntryResponse, Error<AccessTfaUpdateTfaEntryError>> {
360 let p_path_id = id;
362 let p_path_userid = userid;
363 let p_body_access_tfa_update_tfa_entry_request = access_tfa_update_tfa_entry_request;
364
365 let uri_str = format!("{}/access/tfa/{userid}/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), userid=crate::apis::urlencode(p_path_userid));
366 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
367
368 if let Some(ref user_agent) = configuration.user_agent {
369 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
370 }
371 if let Some(ref apikey) = configuration.api_key {
372 let key = apikey.key.clone();
373 let value = match apikey.prefix {
374 Some(ref prefix) => format!("{} {}", prefix, key),
375 None => key,
376 };
377 req_builder = req_builder.header("CSRFPreventionToken", value);
378 };
379 req_builder = req_builder.json(&p_body_access_tfa_update_tfa_entry_request);
380
381 let req = req_builder.build()?;
382 let resp = configuration.client.execute(req).await?;
383
384 let status = resp.status();
385 let content_type = resp
386 .headers()
387 .get("content-type")
388 .and_then(|v| v.to_str().ok())
389 .unwrap_or("application/octet-stream");
390 let content_type = super::ContentType::from(content_type);
391
392 if !status.is_client_error() && !status.is_server_error() {
393 let content = resp.text().await?;
394 match content_type {
395 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
396 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaUpdateTfaEntryResponse`"))),
397 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::AccessTfaUpdateTfaEntryResponse`")))),
398 }
399 } else {
400 let content = resp.text().await?;
401 let entity: Option<AccessTfaUpdateTfaEntryError> = serde_json::from_str(&content).ok();
402 Err(Error::ResponseError(ResponseContent { status, content, entity }))
403 }
404}
405