Skip to main content

clientapi_pbs/apis/
access_acl_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_acl_get_acl`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessAclGetAclError {
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_acl_update_acl`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessAclUpdateAclError {
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/// Read Access Control List (ACLs).  Permissions: Returns all ACLs if user has Sys.Audit on '/access/acl', or just the ACLs containing the user's API tokens.
48pub async fn access_acl_get_acl(configuration: &configuration::Configuration, exact: Option<bool>, path: Option<&str>) -> Result<models::AccessAclGetAclResponse, Error<AccessAclGetAclError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_query_exact = exact;
51    let p_query_path = path;
52
53    let uri_str = format!("{}/access/acl", configuration.base_path);
54    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
55
56    if let Some(ref param_value) = p_query_exact {
57        req_builder = req_builder.query(&[("exact", &param_value.to_string())]);
58    }
59    if let Some(ref param_value) = p_query_path {
60        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
61    }
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65    if let Some(ref apikey) = configuration.api_key {
66        let key = apikey.key.clone();
67        let value = match apikey.prefix {
68            Some(ref prefix) => format!("{} {}", prefix, key),
69            None => key,
70        };
71        req_builder = req_builder.header("Authorization", value);
72    };
73    if let Some(ref apikey) = configuration.api_key {
74        let key = apikey.key.clone();
75        let value = match apikey.prefix {
76            Some(ref prefix) => format!("{} {}", prefix, key),
77            None => key,
78        };
79        req_builder = req_builder.header("CSRFPreventionToken", value);
80    };
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessAclGetAclResponse`"))),
98            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::AccessAclGetAclResponse`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<AccessAclGetAclError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
104    }
105}
106
107/// Update Access Control List (ACLs).  Permissions: Requires Permissions.Modify on '/access/acl', limited to updating ACLs of the user's API tokens otherwise.
108pub async fn access_acl_update_acl(configuration: &configuration::Configuration, access_acl_update_acl_request: models::AccessAclUpdateAclRequest) -> Result<models::AccessAclUpdateAclResponse, Error<AccessAclUpdateAclError>> {
109    // add a prefix to parameters to efficiently prevent name collisions
110    let p_body_access_acl_update_acl_request = access_acl_update_acl_request;
111
112    let uri_str = format!("{}/access/acl", configuration.base_path);
113    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
114
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref apikey) = configuration.api_key {
119        let key = apikey.key.clone();
120        let value = match apikey.prefix {
121            Some(ref prefix) => format!("{} {}", prefix, key),
122            None => key,
123        };
124        req_builder = req_builder.header("Authorization", value);
125    };
126    if let Some(ref apikey) = configuration.api_key {
127        let key = apikey.key.clone();
128        let value = match apikey.prefix {
129            Some(ref prefix) => format!("{} {}", prefix, key),
130            None => key,
131        };
132        req_builder = req_builder.header("CSRFPreventionToken", value);
133    };
134    req_builder = req_builder.json(&p_body_access_acl_update_acl_request);
135
136    let req = req_builder.build()?;
137    let resp = configuration.client.execute(req).await?;
138
139    let status = resp.status();
140    let content_type = resp
141        .headers()
142        .get("content-type")
143        .and_then(|v| v.to_str().ok())
144        .unwrap_or("application/octet-stream");
145    let content_type = super::ContentType::from(content_type);
146
147    if !status.is_client_error() && !status.is_server_error() {
148        let content = resp.text().await?;
149        match content_type {
150            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessAclUpdateAclResponse`"))),
152            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::AccessAclUpdateAclResponse`")))),
153        }
154    } else {
155        let content = resp.text().await?;
156        let entity: Option<AccessAclUpdateAclError> = serde_json::from_str(&content).ok();
157        Err(Error::ResponseError(ResponseContent { status, content, entity }))
158    }
159}
160