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 ConfigTrafficControlCreateTrafficControlError {
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 ConfigTrafficControlDeleteTrafficControlError {
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 ConfigTrafficControlGetConfigTrafficControlByNameError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ConfigTrafficControlGetTrafficControlError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ConfigTrafficControlUpdateTrafficControlError {
78 Status400(models::PbsError),
79 Status401(models::PbsError),
80 Status403(models::PbsError),
81 Status404(models::PbsError),
82 Status500(models::PbsError),
83 Status501(models::PbsError),
84 Status503(models::PbsError),
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn config_traffic_control_create_traffic_control(configuration: &configuration::Configuration, config_traffic_control_create_traffic_control_request: models::ConfigTrafficControlCreateTrafficControlRequest) -> Result<models::ConfigTrafficControlCreateTrafficControlResponse, Error<ConfigTrafficControlCreateTrafficControlError>> {
91 let p_body_config_traffic_control_create_traffic_control_request = config_traffic_control_create_traffic_control_request;
93
94 let uri_str = format!("{}/config/traffic-control", configuration.base_path);
95 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
96
97 if let Some(ref user_agent) = configuration.user_agent {
98 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99 }
100 if let Some(ref apikey) = configuration.api_key {
101 let key = apikey.key.clone();
102 let value = match apikey.prefix {
103 Some(ref prefix) => format!("{} {}", prefix, key),
104 None => key,
105 };
106 req_builder = req_builder.header("Authorization", value);
107 };
108 if let Some(ref apikey) = configuration.api_key {
109 let key = apikey.key.clone();
110 let value = match apikey.prefix {
111 Some(ref prefix) => format!("{} {}", prefix, key),
112 None => key,
113 };
114 req_builder = req_builder.header("CSRFPreventionToken", value);
115 };
116 req_builder = req_builder.json(&p_body_config_traffic_control_create_traffic_control_request);
117
118 let req = req_builder.build()?;
119 let resp = configuration.client.execute(req).await?;
120
121 let status = resp.status();
122 let content_type = resp
123 .headers()
124 .get("content-type")
125 .and_then(|v| v.to_str().ok())
126 .unwrap_or("application/octet-stream");
127 let content_type = super::ContentType::from(content_type);
128
129 if !status.is_client_error() && !status.is_server_error() {
130 let content = resp.text().await?;
131 match content_type {
132 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
133 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigTrafficControlCreateTrafficControlResponse`"))),
134 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::ConfigTrafficControlCreateTrafficControlResponse`")))),
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<ConfigTrafficControlCreateTrafficControlError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent { status, content, entity }))
140 }
141}
142
143pub async fn config_traffic_control_delete_traffic_control(configuration: &configuration::Configuration, name: &str, digest: Option<&str>) -> Result<models::ConfigTrafficControlDeleteTrafficControlResponse, Error<ConfigTrafficControlDeleteTrafficControlError>> {
145 let p_path_name = name;
147 let p_query_digest = digest;
148
149 let uri_str = format!("{}/config/traffic-control/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
150 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
151
152 if let Some(ref param_value) = p_query_digest {
153 req_builder = req_builder.query(&[("digest", ¶m_value.to_string())]);
154 }
155 if let Some(ref user_agent) = configuration.user_agent {
156 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157 }
158 if let Some(ref apikey) = configuration.api_key {
159 let key = apikey.key.clone();
160 let value = match apikey.prefix {
161 Some(ref prefix) => format!("{} {}", prefix, key),
162 None => key,
163 };
164 req_builder = req_builder.header("Authorization", value);
165 };
166 if let Some(ref apikey) = configuration.api_key {
167 let key = apikey.key.clone();
168 let value = match apikey.prefix {
169 Some(ref prefix) => format!("{} {}", prefix, key),
170 None => key,
171 };
172 req_builder = req_builder.header("CSRFPreventionToken", value);
173 };
174
175 let req = req_builder.build()?;
176 let resp = configuration.client.execute(req).await?;
177
178 let status = resp.status();
179 let content_type = resp
180 .headers()
181 .get("content-type")
182 .and_then(|v| v.to_str().ok())
183 .unwrap_or("application/octet-stream");
184 let content_type = super::ContentType::from(content_type);
185
186 if !status.is_client_error() && !status.is_server_error() {
187 let content = resp.text().await?;
188 match content_type {
189 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
190 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigTrafficControlDeleteTrafficControlResponse`"))),
191 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::ConfigTrafficControlDeleteTrafficControlResponse`")))),
192 }
193 } else {
194 let content = resp.text().await?;
195 let entity: Option<ConfigTrafficControlDeleteTrafficControlError> = serde_json::from_str(&content).ok();
196 Err(Error::ResponseError(ResponseContent { status, content, entity }))
197 }
198}
199
200pub async fn config_traffic_control_get_config_traffic_control_by_name(configuration: &configuration::Configuration, name: &str) -> Result<models::ConfigTrafficControlGetConfigTrafficControlByNameResponse, Error<ConfigTrafficControlGetConfigTrafficControlByNameError>> {
202 let p_path_name = name;
204
205 let uri_str = format!("{}/config/traffic-control/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
206 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
207
208 if let Some(ref user_agent) = configuration.user_agent {
209 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
210 }
211 if let Some(ref apikey) = configuration.api_key {
212 let key = apikey.key.clone();
213 let value = match apikey.prefix {
214 Some(ref prefix) => format!("{} {}", prefix, key),
215 None => key,
216 };
217 req_builder = req_builder.header("Authorization", value);
218 };
219 if let Some(ref apikey) = configuration.api_key {
220 let key = apikey.key.clone();
221 let value = match apikey.prefix {
222 Some(ref prefix) => format!("{} {}", prefix, key),
223 None => key,
224 };
225 req_builder = req_builder.header("CSRFPreventionToken", value);
226 };
227
228 let req = req_builder.build()?;
229 let resp = configuration.client.execute(req).await?;
230
231 let status = resp.status();
232 let content_type = resp
233 .headers()
234 .get("content-type")
235 .and_then(|v| v.to_str().ok())
236 .unwrap_or("application/octet-stream");
237 let content_type = super::ContentType::from(content_type);
238
239 if !status.is_client_error() && !status.is_server_error() {
240 let content = resp.text().await?;
241 match content_type {
242 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
243 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigTrafficControlGetConfigTrafficControlByNameResponse`"))),
244 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::ConfigTrafficControlGetConfigTrafficControlByNameResponse`")))),
245 }
246 } else {
247 let content = resp.text().await?;
248 let entity: Option<ConfigTrafficControlGetConfigTrafficControlByNameError> = serde_json::from_str(&content).ok();
249 Err(Error::ResponseError(ResponseContent { status, content, entity }))
250 }
251}
252
253pub async fn config_traffic_control_get_traffic_control(configuration: &configuration::Configuration, ) -> Result<models::ConfigTrafficControlGetTrafficControlResponse, Error<ConfigTrafficControlGetTrafficControlError>> {
255
256 let uri_str = format!("{}/config/traffic-control", configuration.base_path);
257 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
258
259 if let Some(ref user_agent) = configuration.user_agent {
260 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
261 }
262 if let Some(ref apikey) = configuration.api_key {
263 let key = apikey.key.clone();
264 let value = match apikey.prefix {
265 Some(ref prefix) => format!("{} {}", prefix, key),
266 None => key,
267 };
268 req_builder = req_builder.header("Authorization", value);
269 };
270 if let Some(ref apikey) = configuration.api_key {
271 let key = apikey.key.clone();
272 let value = match apikey.prefix {
273 Some(ref prefix) => format!("{} {}", prefix, key),
274 None => key,
275 };
276 req_builder = req_builder.header("CSRFPreventionToken", value);
277 };
278
279 let req = req_builder.build()?;
280 let resp = configuration.client.execute(req).await?;
281
282 let status = resp.status();
283 let content_type = resp
284 .headers()
285 .get("content-type")
286 .and_then(|v| v.to_str().ok())
287 .unwrap_or("application/octet-stream");
288 let content_type = super::ContentType::from(content_type);
289
290 if !status.is_client_error() && !status.is_server_error() {
291 let content = resp.text().await?;
292 match content_type {
293 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
294 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigTrafficControlGetTrafficControlResponse`"))),
295 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::ConfigTrafficControlGetTrafficControlResponse`")))),
296 }
297 } else {
298 let content = resp.text().await?;
299 let entity: Option<ConfigTrafficControlGetTrafficControlError> = serde_json::from_str(&content).ok();
300 Err(Error::ResponseError(ResponseContent { status, content, entity }))
301 }
302}
303
304pub async fn config_traffic_control_update_traffic_control(configuration: &configuration::Configuration, name: &str, config_traffic_control_update_traffic_control_request: Option<models::ConfigTrafficControlUpdateTrafficControlRequest>) -> Result<models::ConfigTrafficControlUpdateTrafficControlResponse, Error<ConfigTrafficControlUpdateTrafficControlError>> {
306 let p_path_name = name;
308 let p_body_config_traffic_control_update_traffic_control_request = config_traffic_control_update_traffic_control_request;
309
310 let uri_str = format!("{}/config/traffic-control/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
311 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
312
313 if let Some(ref user_agent) = configuration.user_agent {
314 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
315 }
316 if let Some(ref apikey) = configuration.api_key {
317 let key = apikey.key.clone();
318 let value = match apikey.prefix {
319 Some(ref prefix) => format!("{} {}", prefix, key),
320 None => key,
321 };
322 req_builder = req_builder.header("Authorization", value);
323 };
324 if let Some(ref apikey) = configuration.api_key {
325 let key = apikey.key.clone();
326 let value = match apikey.prefix {
327 Some(ref prefix) => format!("{} {}", prefix, key),
328 None => key,
329 };
330 req_builder = req_builder.header("CSRFPreventionToken", value);
331 };
332 req_builder = req_builder.json(&p_body_config_traffic_control_update_traffic_control_request);
333
334 let req = req_builder.build()?;
335 let resp = configuration.client.execute(req).await?;
336
337 let status = resp.status();
338 let content_type = resp
339 .headers()
340 .get("content-type")
341 .and_then(|v| v.to_str().ok())
342 .unwrap_or("application/octet-stream");
343 let content_type = super::ContentType::from(content_type);
344
345 if !status.is_client_error() && !status.is_server_error() {
346 let content = resp.text().await?;
347 match content_type {
348 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
349 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigTrafficControlUpdateTrafficControlResponse`"))),
350 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::ConfigTrafficControlUpdateTrafficControlResponse`")))),
351 }
352 } else {
353 let content = resp.text().await?;
354 let entity: Option<ConfigTrafficControlUpdateTrafficControlError> = serde_json::from_str(&content).ok();
355 Err(Error::ResponseError(ResponseContent { status, content, entity }))
356 }
357}
358