Skip to main content

clientapi_pbs/apis/
access_domains_api.rs

1/*
2 * Proxmox Backup Server API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pbs.proxmox.com/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_sync`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessDomainsCreateSyncError {
22    Status400(models::PbsError),
23    Status401(models::PbsError),
24    Status403(models::PbsError),
25    Status404(models::PbsError),
26    Status500(models::PbsError),
27    Status501(models::PbsError),
28    Status503(models::PbsError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`access_domains_get_domains`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessDomainsGetDomainsError {
36    Status400(models::PbsError),
37    Status401(models::PbsError),
38    Status403(models::PbsError),
39    Status404(models::PbsError),
40    Status500(models::PbsError),
41    Status501(models::PbsError),
42    Status503(models::PbsError),
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Synchronize users of a given realm
48pub async fn access_domains_create_sync(configuration: &configuration::Configuration, realm: &str, access_domains_create_sync_request: Option<models::AccessDomainsCreateSyncRequest>) -> Result<models::AccessDomainsCreateSyncResponse, Error<AccessDomainsCreateSyncError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_path_realm = realm;
51    let p_body_access_domains_create_sync_request = access_domains_create_sync_request;
52
53    let uri_str = format!("{}/access/domains/{realm}/sync", configuration.base_path, realm=crate::apis::urlencode(p_path_realm));
54    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
55
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref apikey) = configuration.api_key {
60        let key = apikey.key.clone();
61        let value = match apikey.prefix {
62            Some(ref prefix) => format!("{} {}", prefix, key),
63            None => key,
64        };
65        req_builder = req_builder.header("Authorization", value);
66    };
67    if let Some(ref apikey) = configuration.api_key {
68        let key = apikey.key.clone();
69        let value = match apikey.prefix {
70            Some(ref prefix) => format!("{} {}", prefix, key),
71            None => key,
72        };
73        req_builder = req_builder.header("CSRFPreventionToken", value);
74    };
75    req_builder = req_builder.json(&p_body_access_domains_create_sync_request);
76
77    let req = req_builder.build()?;
78    let resp = configuration.client.execute(req).await?;
79
80    let status = resp.status();
81    let content_type = resp
82        .headers()
83        .get("content-type")
84        .and_then(|v| v.to_str().ok())
85        .unwrap_or("application/octet-stream");
86    let content_type = super::ContentType::from(content_type);
87
88    if !status.is_client_error() && !status.is_server_error() {
89        let content = resp.text().await?;
90        match content_type {
91            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
92            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsCreateSyncResponse`"))),
93            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::AccessDomainsCreateSyncResponse`")))),
94        }
95    } else {
96        let content = resp.text().await?;
97        let entity: Option<AccessDomainsCreateSyncError> = serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent { status, content, entity }))
99    }
100}
101
102/// Authentication domain/realm index.  Permissions: Anyone can access this, because we need that list for the login box (before the user is authenticated).
103pub async fn access_domains_get_domains(configuration: &configuration::Configuration, ) -> Result<models::AccessDomainsGetDomainsResponse, Error<AccessDomainsGetDomainsError>> {
104
105    let uri_str = format!("{}/access/domains", configuration.base_path);
106    let mut req_builder = configuration.client.request(reqwest::Method::GET, &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
112    let req = req_builder.build()?;
113    let resp = configuration.client.execute(req).await?;
114
115    let status = resp.status();
116    let content_type = resp
117        .headers()
118        .get("content-type")
119        .and_then(|v| v.to_str().ok())
120        .unwrap_or("application/octet-stream");
121    let content_type = super::ContentType::from(content_type);
122
123    if !status.is_client_error() && !status.is_server_error() {
124        let content = resp.text().await?;
125        match content_type {
126            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
127            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessDomainsGetDomainsResponse`"))),
128            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`")))),
129        }
130    } else {
131        let content = resp.text().await?;
132        let entity: Option<AccessDomainsGetDomainsError> = serde_json::from_str(&content).ok();
133        Err(Error::ResponseError(ResponseContent { status, content, entity }))
134    }
135}
136