Skip to main content

clientapi_pve/apis/
access_acl_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_acl_read_acl`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessAclReadAclError {
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_acl_update_acl`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessAclUpdateAclError {
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
47/// Get Access Control List (ACLs).  Permissions: The returned list is restricted to objects where you have rights to modify permissions.
48pub async fn access_acl_read_acl(configuration: &configuration::Configuration, ) -> Result<models::AccessAclReadAclResponse, Error<AccessAclReadAclError>> {
49
50    let uri_str = format!("{}/access/acl", configuration.base_path);
51    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53    if let Some(ref user_agent) = configuration.user_agent {
54        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55    }
56    if let Some(ref apikey) = configuration.api_key {
57        let key = apikey.key.clone();
58        let value = match apikey.prefix {
59            Some(ref prefix) => format!("{} {}", prefix, key),
60            None => key,
61        };
62        req_builder = req_builder.header("Authorization", value);
63    };
64    if let Some(ref apikey) = configuration.api_key {
65        let key = apikey.key.clone();
66        let value = match apikey.prefix {
67            Some(ref prefix) => format!("{} {}", prefix, key),
68            None => key,
69        };
70        req_builder = req_builder.header("CSRFPreventionToken", value);
71    };
72
73    let req = req_builder.build()?;
74    let resp = configuration.client.execute(req).await?;
75
76    let status = resp.status();
77    let content_type = resp
78        .headers()
79        .get("content-type")
80        .and_then(|v| v.to_str().ok())
81        .unwrap_or("application/octet-stream");
82    let content_type = super::ContentType::from(content_type);
83
84    if !status.is_client_error() && !status.is_server_error() {
85        let content = resp.text().await?;
86        match content_type {
87            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessAclReadAclResponse`"))),
89            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::AccessAclReadAclResponse`")))),
90        }
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<AccessAclReadAclError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent { status, content, entity }))
95    }
96}
97
98/// Update Access Control List (add or remove permissions).
99pub async fn access_acl_update_acl(configuration: &configuration::Configuration, access_acl_update_acl_request: models::AccessAclUpdateAclRequest) -> Result<models::AccessAclUpdateAclResponse, Error<AccessAclUpdateAclError>> {
100    // add a prefix to parameters to efficiently prevent name collisions
101    let p_body_access_acl_update_acl_request = access_acl_update_acl_request;
102
103    let uri_str = format!("{}/access/acl", configuration.base_path);
104    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
105
106    if let Some(ref user_agent) = configuration.user_agent {
107        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108    }
109    if let Some(ref apikey) = configuration.api_key {
110        let key = apikey.key.clone();
111        let value = match apikey.prefix {
112            Some(ref prefix) => format!("{} {}", prefix, key),
113            None => key,
114        };
115        req_builder = req_builder.header("Authorization", value);
116    };
117    if let Some(ref apikey) = configuration.api_key {
118        let key = apikey.key.clone();
119        let value = match apikey.prefix {
120            Some(ref prefix) => format!("{} {}", prefix, key),
121            None => key,
122        };
123        req_builder = req_builder.header("CSRFPreventionToken", value);
124    };
125    req_builder = req_builder.json(&p_body_access_acl_update_acl_request);
126
127    let req = req_builder.build()?;
128    let resp = configuration.client.execute(req).await?;
129
130    let status = resp.status();
131    let content_type = resp
132        .headers()
133        .get("content-type")
134        .and_then(|v| v.to_str().ok())
135        .unwrap_or("application/octet-stream");
136    let content_type = super::ContentType::from(content_type);
137
138    if !status.is_client_error() && !status.is_server_error() {
139        let content = resp.text().await?;
140        match content_type {
141            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
142            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessAclUpdateAclResponse`"))),
143            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`")))),
144        }
145    } else {
146        let content = resp.text().await?;
147        let entity: Option<AccessAclUpdateAclError> = serde_json::from_str(&content).ok();
148        Err(Error::ResponseError(ResponseContent { status, content, entity }))
149    }
150}
151