Skip to main content

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