Skip to main content

clientapi_pbs/apis/
nodes_subscription_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_subscription_create_subscription`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum NodesSubscriptionCreateSubscriptionError {
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_subscription_delete_subscription`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum NodesSubscriptionDeleteSubscriptionError {
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/// struct for typed errors of method [`nodes_subscription_get_subscription`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum NodesSubscriptionGetSubscriptionError {
50    Status400(models::PbsError),
51    Status401(models::PbsError),
52    Status403(models::PbsError),
53    Status404(models::PbsError),
54    Status500(models::PbsError),
55    Status501(models::PbsError),
56    Status503(models::PbsError),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`nodes_subscription_update_subscription`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum NodesSubscriptionUpdateSubscriptionError {
64    Status400(models::PbsError),
65    Status401(models::PbsError),
66    Status403(models::PbsError),
67    Status404(models::PbsError),
68    Status500(models::PbsError),
69    Status501(models::PbsError),
70    Status503(models::PbsError),
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Check and update subscription status.
76pub async fn nodes_subscription_create_subscription(configuration: &configuration::Configuration, node: &str, nodes_subscription_create_subscription_request: Option<models::NodesSubscriptionCreateSubscriptionRequest>) -> Result<models::NodesSubscriptionCreateSubscriptionResponse, Error<NodesSubscriptionCreateSubscriptionError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_path_node = node;
79    let p_body_nodes_subscription_create_subscription_request = nodes_subscription_create_subscription_request;
80
81    let uri_str = format!("{}/nodes/{node}/subscription", configuration.base_path, node=crate::apis::urlencode(p_path_node));
82    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref apikey) = configuration.api_key {
88        let key = apikey.key.clone();
89        let value = match apikey.prefix {
90            Some(ref prefix) => format!("{} {}", prefix, key),
91            None => key,
92        };
93        req_builder = req_builder.header("Authorization", value);
94    };
95    if let Some(ref apikey) = configuration.api_key {
96        let key = apikey.key.clone();
97        let value = match apikey.prefix {
98            Some(ref prefix) => format!("{} {}", prefix, key),
99            None => key,
100        };
101        req_builder = req_builder.header("CSRFPreventionToken", value);
102    };
103    req_builder = req_builder.json(&p_body_nodes_subscription_create_subscription_request);
104
105    let req = req_builder.build()?;
106    let resp = configuration.client.execute(req).await?;
107
108    let status = resp.status();
109    let content_type = resp
110        .headers()
111        .get("content-type")
112        .and_then(|v| v.to_str().ok())
113        .unwrap_or("application/octet-stream");
114    let content_type = super::ContentType::from(content_type);
115
116    if !status.is_client_error() && !status.is_server_error() {
117        let content = resp.text().await?;
118        match content_type {
119            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesSubscriptionCreateSubscriptionResponse`"))),
121            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::NodesSubscriptionCreateSubscriptionResponse`")))),
122        }
123    } else {
124        let content = resp.text().await?;
125        let entity: Option<NodesSubscriptionCreateSubscriptionError> = serde_json::from_str(&content).ok();
126        Err(Error::ResponseError(ResponseContent { status, content, entity }))
127    }
128}
129
130/// Delete subscription info.
131pub async fn nodes_subscription_delete_subscription(configuration: &configuration::Configuration, node: &str) -> Result<models::NodesSubscriptionDeleteSubscriptionResponse, Error<NodesSubscriptionDeleteSubscriptionError>> {
132    // add a prefix to parameters to efficiently prevent name collisions
133    let p_path_node = node;
134
135    let uri_str = format!("{}/nodes/{node}/subscription", configuration.base_path, node=crate::apis::urlencode(p_path_node));
136    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
137
138    if let Some(ref user_agent) = configuration.user_agent {
139        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
140    }
141    if let Some(ref apikey) = configuration.api_key {
142        let key = apikey.key.clone();
143        let value = match apikey.prefix {
144            Some(ref prefix) => format!("{} {}", prefix, key),
145            None => key,
146        };
147        req_builder = req_builder.header("Authorization", value);
148    };
149    if let Some(ref apikey) = configuration.api_key {
150        let key = apikey.key.clone();
151        let value = match apikey.prefix {
152            Some(ref prefix) => format!("{} {}", prefix, key),
153            None => key,
154        };
155        req_builder = req_builder.header("CSRFPreventionToken", value);
156    };
157
158    let req = req_builder.build()?;
159    let resp = configuration.client.execute(req).await?;
160
161    let status = resp.status();
162    let content_type = resp
163        .headers()
164        .get("content-type")
165        .and_then(|v| v.to_str().ok())
166        .unwrap_or("application/octet-stream");
167    let content_type = super::ContentType::from(content_type);
168
169    if !status.is_client_error() && !status.is_server_error() {
170        let content = resp.text().await?;
171        match content_type {
172            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
173            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesSubscriptionDeleteSubscriptionResponse`"))),
174            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::NodesSubscriptionDeleteSubscriptionResponse`")))),
175        }
176    } else {
177        let content = resp.text().await?;
178        let entity: Option<NodesSubscriptionDeleteSubscriptionError> = serde_json::from_str(&content).ok();
179        Err(Error::ResponseError(ResponseContent { status, content, entity }))
180    }
181}
182
183/// Read subscription info.
184pub async fn nodes_subscription_get_subscription(configuration: &configuration::Configuration, node: &str) -> Result<models::NodesSubscriptionGetSubscriptionResponse, Error<NodesSubscriptionGetSubscriptionError>> {
185    // add a prefix to parameters to efficiently prevent name collisions
186    let p_path_node = node;
187
188    let uri_str = format!("{}/nodes/{node}/subscription", configuration.base_path, node=crate::apis::urlencode(p_path_node));
189    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
190
191    if let Some(ref user_agent) = configuration.user_agent {
192        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
193    }
194    if let Some(ref apikey) = configuration.api_key {
195        let key = apikey.key.clone();
196        let value = match apikey.prefix {
197            Some(ref prefix) => format!("{} {}", prefix, key),
198            None => key,
199        };
200        req_builder = req_builder.header("Authorization", value);
201    };
202    if let Some(ref apikey) = configuration.api_key {
203        let key = apikey.key.clone();
204        let value = match apikey.prefix {
205            Some(ref prefix) => format!("{} {}", prefix, key),
206            None => key,
207        };
208        req_builder = req_builder.header("CSRFPreventionToken", value);
209    };
210
211    let req = req_builder.build()?;
212    let resp = configuration.client.execute(req).await?;
213
214    let status = resp.status();
215    let content_type = resp
216        .headers()
217        .get("content-type")
218        .and_then(|v| v.to_str().ok())
219        .unwrap_or("application/octet-stream");
220    let content_type = super::ContentType::from(content_type);
221
222    if !status.is_client_error() && !status.is_server_error() {
223        let content = resp.text().await?;
224        match content_type {
225            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesSubscriptionGetSubscriptionResponse`"))),
227            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::NodesSubscriptionGetSubscriptionResponse`")))),
228        }
229    } else {
230        let content = resp.text().await?;
231        let entity: Option<NodesSubscriptionGetSubscriptionError> = serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent { status, content, entity }))
233    }
234}
235
236/// Set a subscription key and check it.
237pub async fn nodes_subscription_update_subscription(configuration: &configuration::Configuration, node: &str, nodes_subscription_update_subscription_request: models::NodesSubscriptionUpdateSubscriptionRequest) -> Result<models::NodesSubscriptionUpdateSubscriptionResponse, Error<NodesSubscriptionUpdateSubscriptionError>> {
238    // add a prefix to parameters to efficiently prevent name collisions
239    let p_path_node = node;
240    let p_body_nodes_subscription_update_subscription_request = nodes_subscription_update_subscription_request;
241
242    let uri_str = format!("{}/nodes/{node}/subscription", configuration.base_path, node=crate::apis::urlencode(p_path_node));
243    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
244
245    if let Some(ref user_agent) = configuration.user_agent {
246        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
247    }
248    if let Some(ref apikey) = configuration.api_key {
249        let key = apikey.key.clone();
250        let value = match apikey.prefix {
251            Some(ref prefix) => format!("{} {}", prefix, key),
252            None => key,
253        };
254        req_builder = req_builder.header("Authorization", value);
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("CSRFPreventionToken", value);
263    };
264    req_builder = req_builder.json(&p_body_nodes_subscription_update_subscription_request);
265
266    let req = req_builder.build()?;
267    let resp = configuration.client.execute(req).await?;
268
269    let status = resp.status();
270    let content_type = resp
271        .headers()
272        .get("content-type")
273        .and_then(|v| v.to_str().ok())
274        .unwrap_or("application/octet-stream");
275    let content_type = super::ContentType::from(content_type);
276
277    if !status.is_client_error() && !status.is_server_error() {
278        let content = resp.text().await?;
279        match content_type {
280            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
281            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesSubscriptionUpdateSubscriptionResponse`"))),
282            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::NodesSubscriptionUpdateSubscriptionResponse`")))),
283        }
284    } else {
285        let content = resp.text().await?;
286        let entity: Option<NodesSubscriptionUpdateSubscriptionError> = serde_json::from_str(&content).ok();
287        Err(Error::ResponseError(ResponseContent { status, content, entity }))
288    }
289}
290