Skip to main content

clientapi_pve/apis/
access_domains_api.rs

1/*
2 * Proxmox Virtual Environment API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`access_domains_create_domains`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessDomainsCreateDomainsError {
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/// struct for typed errors of method [`access_domains_delete_domains`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessDomainsDeleteDomainsError {
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/// struct for typed errors of method [`access_domains_get_domains`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AccessDomainsGetDomainsError {
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/// struct for typed errors of method [`access_domains_read_get_domains`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum AccessDomainsReadGetDomainsError {
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/// struct for typed errors of method [`access_domains_sync`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum AccessDomainsSyncError {
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/// struct for typed errors of method [`access_domains_update_domains`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum AccessDomainsUpdateDomainsError {
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
103/// Add an authentication server.
104pub async fn access_domains_create_domains(configuration: &configuration::Configuration, access_domains_create_domains_request: models::AccessDomainsCreateDomainsRequest) -> Result<models::AccessDomainsCreateDomainsResponse, Error<AccessDomainsCreateDomainsError>> {
105    // add a prefix to parameters to efficiently prevent name collisions
106    let p_body_access_domains_create_domains_request = access_domains_create_domains_request;
107
108    let uri_str = format!("{}/access/domains", configuration.base_path);
109    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
110
111    if let Some(ref user_agent) = configuration.user_agent {
112        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113    }
114    if let Some(ref apikey) = configuration.api_key {
115        let key = apikey.key.clone();
116        let value = match apikey.prefix {
117            Some(ref prefix) => format!("{} {}", prefix, key),
118            None => key,
119        };
120        req_builder = req_builder.header("Authorization", value);
121    };
122    if let Some(ref apikey) = configuration.api_key {
123        let key = apikey.key.clone();
124        let value = match apikey.prefix {
125            Some(ref prefix) => format!("{} {}", prefix, key),
126            None => key,
127        };
128        req_builder = req_builder.header("CSRFPreventionToken", value);
129    };
130    req_builder = req_builder.json(&p_body_access_domains_create_domains_request);
131
132    let req = req_builder.build()?;
133    let resp = configuration.client.execute(req).await?;
134
135    let status = resp.status();
136    let content_type = resp
137        .headers()
138        .get("content-type")
139        .and_then(|v| v.to_str().ok())
140        .unwrap_or("application/octet-stream");
141    let content_type = super::ContentType::from(content_type);
142
143    if !status.is_client_error() && !status.is_server_error() {
144        let content = resp.text().await?;
145        match content_type {
146            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
147            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsCreateDomainsResponse`"))),
148            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::AccessDomainsCreateDomainsResponse`")))),
149        }
150    } else {
151        let content = resp.text().await?;
152        let entity: Option<AccessDomainsCreateDomainsError> = serde_json::from_str(&content).ok();
153        Err(Error::ResponseError(ResponseContent { status, content, entity }))
154    }
155}
156
157/// Delete an authentication server.
158pub async fn access_domains_delete_domains(configuration: &configuration::Configuration, realm: &str) -> Result<models::AccessDomainsDeleteDomainsResponse, Error<AccessDomainsDeleteDomainsError>> {
159    // add a prefix to parameters to efficiently prevent name collisions
160    let p_path_realm = realm;
161
162    let uri_str = format!("{}/access/domains/{realm}", configuration.base_path, realm=crate::apis::urlencode(p_path_realm));
163    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
164
165    if let Some(ref user_agent) = configuration.user_agent {
166        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
167    }
168    if let Some(ref apikey) = configuration.api_key {
169        let key = apikey.key.clone();
170        let value = match apikey.prefix {
171            Some(ref prefix) => format!("{} {}", prefix, key),
172            None => key,
173        };
174        req_builder = req_builder.header("Authorization", value);
175    };
176    if let Some(ref apikey) = configuration.api_key {
177        let key = apikey.key.clone();
178        let value = match apikey.prefix {
179            Some(ref prefix) => format!("{} {}", prefix, key),
180            None => key,
181        };
182        req_builder = req_builder.header("CSRFPreventionToken", value);
183    };
184
185    let req = req_builder.build()?;
186    let resp = configuration.client.execute(req).await?;
187
188    let status = resp.status();
189    let content_type = resp
190        .headers()
191        .get("content-type")
192        .and_then(|v| v.to_str().ok())
193        .unwrap_or("application/octet-stream");
194    let content_type = super::ContentType::from(content_type);
195
196    if !status.is_client_error() && !status.is_server_error() {
197        let content = resp.text().await?;
198        match content_type {
199            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
200            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsDeleteDomainsResponse`"))),
201            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::AccessDomainsDeleteDomainsResponse`")))),
202        }
203    } else {
204        let content = resp.text().await?;
205        let entity: Option<AccessDomainsDeleteDomainsError> = serde_json::from_str(&content).ok();
206        Err(Error::ResponseError(ResponseContent { status, content, entity }))
207    }
208}
209
210/// Authentication domain index.  Permissions: Anyone can access that, because we need that list for the login box (before the user is authenticated).
211pub async fn access_domains_get_domains(configuration: &configuration::Configuration, ) -> Result<models::AccessDomainsGetDomainsResponse, Error<AccessDomainsGetDomainsError>> {
212
213    let uri_str = format!("{}/access/domains", configuration.base_path);
214    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
215
216    if let Some(ref user_agent) = configuration.user_agent {
217        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
218    }
219
220    let req = req_builder.build()?;
221    let resp = configuration.client.execute(req).await?;
222
223    let status = resp.status();
224    let content_type = resp
225        .headers()
226        .get("content-type")
227        .and_then(|v| v.to_str().ok())
228        .unwrap_or("application/octet-stream");
229    let content_type = super::ContentType::from(content_type);
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        match content_type {
234            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsGetDomainsResponse`"))),
236            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::AccessDomainsGetDomainsResponse`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<AccessDomainsGetDomainsError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244
245/// Get auth server configuration.
246pub async fn access_domains_read_get_domains(configuration: &configuration::Configuration, realm: &str) -> Result<models::AccessDomainsReadGetDomainsResponse, Error<AccessDomainsReadGetDomainsError>> {
247    // add a prefix to parameters to efficiently prevent name collisions
248    let p_path_realm = realm;
249
250    let uri_str = format!("{}/access/domains/{realm}", configuration.base_path, realm=crate::apis::urlencode(p_path_realm));
251    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
252
253    if let Some(ref user_agent) = configuration.user_agent {
254        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
255    }
256    if let Some(ref apikey) = configuration.api_key {
257        let key = apikey.key.clone();
258        let value = match apikey.prefix {
259            Some(ref prefix) => format!("{} {}", prefix, key),
260            None => key,
261        };
262        req_builder = req_builder.header("Authorization", value);
263    };
264    if let Some(ref apikey) = configuration.api_key {
265        let key = apikey.key.clone();
266        let value = match apikey.prefix {
267            Some(ref prefix) => format!("{} {}", prefix, key),
268            None => key,
269        };
270        req_builder = req_builder.header("CSRFPreventionToken", value);
271    };
272
273    let req = req_builder.build()?;
274    let resp = configuration.client.execute(req).await?;
275
276    let status = resp.status();
277    let content_type = resp
278        .headers()
279        .get("content-type")
280        .and_then(|v| v.to_str().ok())
281        .unwrap_or("application/octet-stream");
282    let content_type = super::ContentType::from(content_type);
283
284    if !status.is_client_error() && !status.is_server_error() {
285        let content = resp.text().await?;
286        match content_type {
287            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
288            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsReadGetDomainsResponse`"))),
289            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::AccessDomainsReadGetDomainsResponse`")))),
290        }
291    } else {
292        let content = resp.text().await?;
293        let entity: Option<AccessDomainsReadGetDomainsError> = serde_json::from_str(&content).ok();
294        Err(Error::ResponseError(ResponseContent { status, content, entity }))
295    }
296}
297
298/// Syncs users and/or groups from the configured LDAP to user.cfg. NOTE: Synced groups will have the name 'name-$realm', so make sure those groups do not exist to prevent overwriting.  Permissions: 'Realm.AllocateUser' on '/access/realm/<realm>' and  'User.Modify' permissions to '/access/groups/'.
299pub async fn access_domains_sync(configuration: &configuration::Configuration, realm: &str, access_domains_sync_request: models::AccessDomainsSyncRequest) -> Result<models::AccessDomainsSyncResponse, Error<AccessDomainsSyncError>> {
300    // add a prefix to parameters to efficiently prevent name collisions
301    let p_path_realm = realm;
302    let p_body_access_domains_sync_request = access_domains_sync_request;
303
304    let uri_str = format!("{}/access/domains/{realm}/sync", configuration.base_path, realm=crate::apis::urlencode(p_path_realm));
305    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
306
307    if let Some(ref user_agent) = configuration.user_agent {
308        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
309    }
310    if let Some(ref apikey) = configuration.api_key {
311        let key = apikey.key.clone();
312        let value = match apikey.prefix {
313            Some(ref prefix) => format!("{} {}", prefix, key),
314            None => key,
315        };
316        req_builder = req_builder.header("Authorization", value);
317    };
318    if let Some(ref apikey) = configuration.api_key {
319        let key = apikey.key.clone();
320        let value = match apikey.prefix {
321            Some(ref prefix) => format!("{} {}", prefix, key),
322            None => key,
323        };
324        req_builder = req_builder.header("CSRFPreventionToken", value);
325    };
326    req_builder = req_builder.json(&p_body_access_domains_sync_request);
327
328    let req = req_builder.build()?;
329    let resp = configuration.client.execute(req).await?;
330
331    let status = resp.status();
332    let content_type = resp
333        .headers()
334        .get("content-type")
335        .and_then(|v| v.to_str().ok())
336        .unwrap_or("application/octet-stream");
337    let content_type = super::ContentType::from(content_type);
338
339    if !status.is_client_error() && !status.is_server_error() {
340        let content = resp.text().await?;
341        match content_type {
342            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
343            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsSyncResponse`"))),
344            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::AccessDomainsSyncResponse`")))),
345        }
346    } else {
347        let content = resp.text().await?;
348        let entity: Option<AccessDomainsSyncError> = serde_json::from_str(&content).ok();
349        Err(Error::ResponseError(ResponseContent { status, content, entity }))
350    }
351}
352
353/// Update authentication server settings.
354pub async fn access_domains_update_domains(configuration: &configuration::Configuration, realm: &str, access_domains_update_domains_request: Option<models::AccessDomainsUpdateDomainsRequest>) -> Result<models::AccessDomainsUpdateDomainsResponse, Error<AccessDomainsUpdateDomainsError>> {
355    // add a prefix to parameters to efficiently prevent name collisions
356    let p_path_realm = realm;
357    let p_body_access_domains_update_domains_request = access_domains_update_domains_request;
358
359    let uri_str = format!("{}/access/domains/{realm}", configuration.base_path, realm=crate::apis::urlencode(p_path_realm));
360    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
361
362    if let Some(ref user_agent) = configuration.user_agent {
363        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
364    }
365    if let Some(ref apikey) = configuration.api_key {
366        let key = apikey.key.clone();
367        let value = match apikey.prefix {
368            Some(ref prefix) => format!("{} {}", prefix, key),
369            None => key,
370        };
371        req_builder = req_builder.header("Authorization", value);
372    };
373    if let Some(ref apikey) = configuration.api_key {
374        let key = apikey.key.clone();
375        let value = match apikey.prefix {
376            Some(ref prefix) => format!("{} {}", prefix, key),
377            None => key,
378        };
379        req_builder = req_builder.header("CSRFPreventionToken", value);
380    };
381    req_builder = req_builder.json(&p_body_access_domains_update_domains_request);
382
383    let req = req_builder.build()?;
384    let resp = configuration.client.execute(req).await?;
385
386    let status = resp.status();
387    let content_type = resp
388        .headers()
389        .get("content-type")
390        .and_then(|v| v.to_str().ok())
391        .unwrap_or("application/octet-stream");
392    let content_type = super::ContentType::from(content_type);
393
394    if !status.is_client_error() && !status.is_server_error() {
395        let content = resp.text().await?;
396        match content_type {
397            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
398            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsUpdateDomainsResponse`"))),
399            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::AccessDomainsUpdateDomainsResponse`")))),
400        }
401    } else {
402        let content = resp.text().await?;
403        let entity: Option<AccessDomainsUpdateDomainsError> = serde_json::from_str(&content).ok();
404        Err(Error::ResponseError(ResponseContent { status, content, entity }))
405    }
406}
407