1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum TapeBackupCreateBackupError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum TapeBackupCreateTapeBackupByIdError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum TapeBackupGetBackupError {
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
61pub async fn tape_backup_create_backup(configuration: &configuration::Configuration, tape_backup_create_backup_request: models::TapeBackupCreateBackupRequest) -> Result<models::TapeBackupCreateBackupResponse, Error<TapeBackupCreateBackupError>> {
63 let p_body_tape_backup_create_backup_request = tape_backup_create_backup_request;
65
66 let uri_str = format!("{}/tape/backup", configuration.base_path);
67 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
68
69 if let Some(ref user_agent) = configuration.user_agent {
70 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71 }
72 if let Some(ref apikey) = configuration.api_key {
73 let key = apikey.key.clone();
74 let value = match apikey.prefix {
75 Some(ref prefix) => format!("{} {}", prefix, key),
76 None => key,
77 };
78 req_builder = req_builder.header("Authorization", value);
79 };
80 if let Some(ref apikey) = configuration.api_key {
81 let key = apikey.key.clone();
82 let value = match apikey.prefix {
83 Some(ref prefix) => format!("{} {}", prefix, key),
84 None => key,
85 };
86 req_builder = req_builder.header("CSRFPreventionToken", value);
87 };
88 req_builder = req_builder.json(&p_body_tape_backup_create_backup_request);
89
90 let req = req_builder.build()?;
91 let resp = configuration.client.execute(req).await?;
92
93 let status = resp.status();
94 let content_type = resp
95 .headers()
96 .get("content-type")
97 .and_then(|v| v.to_str().ok())
98 .unwrap_or("application/octet-stream");
99 let content_type = super::ContentType::from(content_type);
100
101 if !status.is_client_error() && !status.is_server_error() {
102 let content = resp.text().await?;
103 match content_type {
104 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TapeBackupCreateBackupResponse`"))),
106 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::TapeBackupCreateBackupResponse`")))),
107 }
108 } else {
109 let content = resp.text().await?;
110 let entity: Option<TapeBackupCreateBackupError> = serde_json::from_str(&content).ok();
111 Err(Error::ResponseError(ResponseContent { status, content, entity }))
112 }
113}
114
115pub async fn tape_backup_create_tape_backup_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::TapeBackupCreateTapeBackupByIdResponse, Error<TapeBackupCreateTapeBackupByIdError>> {
117 let p_path_id = id;
119
120 let uri_str = format!("{}/tape/backup/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
121 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
122
123 if let Some(ref user_agent) = configuration.user_agent {
124 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
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("Authorization", value);
133 };
134 if let Some(ref apikey) = configuration.api_key {
135 let key = apikey.key.clone();
136 let value = match apikey.prefix {
137 Some(ref prefix) => format!("{} {}", prefix, key),
138 None => key,
139 };
140 req_builder = req_builder.header("CSRFPreventionToken", value);
141 };
142
143 let req = req_builder.build()?;
144 let resp = configuration.client.execute(req).await?;
145
146 let status = resp.status();
147 let content_type = resp
148 .headers()
149 .get("content-type")
150 .and_then(|v| v.to_str().ok())
151 .unwrap_or("application/octet-stream");
152 let content_type = super::ContentType::from(content_type);
153
154 if !status.is_client_error() && !status.is_server_error() {
155 let content = resp.text().await?;
156 match content_type {
157 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TapeBackupCreateTapeBackupByIdResponse`"))),
159 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::TapeBackupCreateTapeBackupByIdResponse`")))),
160 }
161 } else {
162 let content = resp.text().await?;
163 let entity: Option<TapeBackupCreateTapeBackupByIdError> = serde_json::from_str(&content).ok();
164 Err(Error::ResponseError(ResponseContent { status, content, entity }))
165 }
166}
167
168pub async fn tape_backup_get_backup(configuration: &configuration::Configuration, ) -> Result<models::TapeBackupGetBackupResponse, Error<TapeBackupGetBackupError>> {
170
171 let uri_str = format!("{}/tape/backup", configuration.base_path);
172 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
173
174 if let Some(ref user_agent) = configuration.user_agent {
175 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176 }
177 if let Some(ref apikey) = configuration.api_key {
178 let key = apikey.key.clone();
179 let value = match apikey.prefix {
180 Some(ref prefix) => format!("{} {}", prefix, key),
181 None => key,
182 };
183 req_builder = req_builder.header("Authorization", value);
184 };
185 if let Some(ref apikey) = configuration.api_key {
186 let key = apikey.key.clone();
187 let value = match apikey.prefix {
188 Some(ref prefix) => format!("{} {}", prefix, key),
189 None => key,
190 };
191 req_builder = req_builder.header("CSRFPreventionToken", value);
192 };
193
194 let req = req_builder.build()?;
195 let resp = configuration.client.execute(req).await?;
196
197 let status = resp.status();
198 let content_type = resp
199 .headers()
200 .get("content-type")
201 .and_then(|v| v.to_str().ok())
202 .unwrap_or("application/octet-stream");
203 let content_type = super::ContentType::from(content_type);
204
205 if !status.is_client_error() && !status.is_server_error() {
206 let content = resp.text().await?;
207 match content_type {
208 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TapeBackupGetBackupResponse`"))),
210 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::TapeBackupGetBackupResponse`")))),
211 }
212 } else {
213 let content = resp.text().await?;
214 let entity: Option<TapeBackupGetBackupError> = serde_json::from_str(&content).ok();
215 Err(Error::ResponseError(ResponseContent { status, content, entity }))
216 }
217}
218