qcs_api_client_openapi/apis/
default_api.rs1use super::{configuration, Error};
26use crate::apis::ResponseContent;
27use ::qcs_api_client_common::backoff::{
28 duration_from_io_error, duration_from_reqwest_error, duration_from_response, ExponentialBackoff,
29};
30#[cfg(feature = "tracing")]
31use qcs_api_client_common::configuration::TokenRefresher;
32use reqwest::StatusCode;
33use serde::{Deserialize, Serialize};
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetHealthError {
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum HealthCheckError {
46 Status422(crate::models::ValidationError),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum HealthCheckDeprecatedError {
54 Status422(crate::models::ValidationError),
55 UnknownValue(serde_json::Value),
56}
57
58async fn get_health_inner(
59 configuration: &configuration::Configuration,
60 backoff: &mut ExponentialBackoff,
61) -> Result<crate::models::Health, Error<GetHealthError>> {
62 let local_var_configuration = configuration;
63
64 let local_var_client = &local_var_configuration.client;
65
66 let local_var_uri_str = format!("{}/", local_var_configuration.qcs_config.api_url());
67 let mut local_var_req_builder =
68 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
69
70 #[cfg(feature = "tracing")]
71 {
72 let local_var_do_tracing =
75 local_var_uri_str
76 .parse::<::url::Url>()
77 .ok()
78 .map_or(true, |url| {
79 configuration
80 .qcs_config
81 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
82 });
83
84 if local_var_do_tracing {
85 ::tracing::debug!(
86 url=%local_var_uri_str,
87 method="GET",
88 "making get_health request",
89 );
90 }
91 }
92
93 {
96 use qcs_api_client_common::configuration::TokenError;
97
98 #[allow(
99 clippy::nonminimal_bool,
100 clippy::eq_op,
101 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
102 )]
103 let is_jwt_bearer_optional: bool = false;
104
105 let token = local_var_configuration
106 .qcs_config
107 .get_bearer_access_token()
108 .await;
109
110 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
111 #[cfg(feature = "tracing")]
113 tracing::debug!(
114 "No client credentials found, but this call does not require authentication."
115 );
116 } else {
117 local_var_req_builder = local_var_req_builder.bearer_auth(token?);
118 }
119 }
120
121 let local_var_req = local_var_req_builder.build()?;
122 let local_var_resp = local_var_client.execute(local_var_req).await?;
123
124 let local_var_status = local_var_resp.status();
125
126 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127 let local_var_content = local_var_resp.text().await?;
128 serde_json::from_str(&local_var_content).map_err(Error::from)
129 } else {
130 let local_var_retry_delay =
131 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
132 let local_var_content = local_var_resp.text().await?;
133 let local_var_entity: Option<GetHealthError> =
134 serde_json::from_str(&local_var_content).ok();
135 let local_var_error = ResponseContent {
136 status: local_var_status,
137 content: local_var_content,
138 entity: local_var_entity,
139 retry_delay: local_var_retry_delay,
140 };
141 Err(Error::ResponseError(local_var_error))
142 }
143}
144
145pub async fn get_health(
147 configuration: &configuration::Configuration,
148) -> Result<crate::models::Health, Error<GetHealthError>> {
149 let mut backoff = configuration.backoff.clone();
150 let mut refreshed_credentials = false;
151 let method = reqwest::Method::GET;
152 loop {
153 let result = get_health_inner(configuration, &mut backoff).await;
154
155 match result {
156 Ok(result) => return Ok(result),
157 Err(Error::ResponseError(response)) => {
158 if !refreshed_credentials
159 && matches!(
160 response.status,
161 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
162 )
163 {
164 configuration.qcs_config.refresh().await?;
165 refreshed_credentials = true;
166 continue;
167 } else if let Some(duration) = response.retry_delay {
168 tokio::time::sleep(duration).await;
169 continue;
170 }
171
172 return Err(Error::ResponseError(response));
173 }
174 Err(Error::Reqwest(error)) => {
175 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
176 tokio::time::sleep(duration).await;
177 continue;
178 }
179
180 return Err(Error::Reqwest(error));
181 }
182 Err(Error::Io(error)) => {
183 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
184 tokio::time::sleep(duration).await;
185 continue;
186 }
187
188 return Err(Error::Io(error));
189 }
190 Err(error) => return Err(error),
191 }
192 }
193}
194async fn health_check_inner(
195 configuration: &configuration::Configuration,
196 backoff: &mut ExponentialBackoff,
197) -> Result<serde_json::Value, Error<HealthCheckError>> {
198 let local_var_configuration = configuration;
199
200 let local_var_client = &local_var_configuration.client;
201
202 let local_var_uri_str = format!(
203 "{}/v1/healthcheck",
204 local_var_configuration.qcs_config.api_url()
205 );
206 let mut local_var_req_builder =
207 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
208
209 #[cfg(feature = "tracing")]
210 {
211 let local_var_do_tracing =
214 local_var_uri_str
215 .parse::<::url::Url>()
216 .ok()
217 .map_or(true, |url| {
218 configuration
219 .qcs_config
220 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
221 });
222
223 if local_var_do_tracing {
224 ::tracing::debug!(
225 url=%local_var_uri_str,
226 method="GET",
227 "making health_check request",
228 );
229 }
230 }
231
232 {
235 use qcs_api_client_common::configuration::TokenError;
236
237 #[allow(
238 clippy::nonminimal_bool,
239 clippy::eq_op,
240 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
241 )]
242 let is_jwt_bearer_optional: bool = false;
243
244 let token = local_var_configuration
245 .qcs_config
246 .get_bearer_access_token()
247 .await;
248
249 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
250 #[cfg(feature = "tracing")]
252 tracing::debug!(
253 "No client credentials found, but this call does not require authentication."
254 );
255 } else {
256 local_var_req_builder = local_var_req_builder.bearer_auth(token?);
257 }
258 }
259
260 let local_var_req = local_var_req_builder.build()?;
261 let local_var_resp = local_var_client.execute(local_var_req).await?;
262
263 let local_var_status = local_var_resp.status();
264
265 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
266 let local_var_content = local_var_resp.text().await?;
267 serde_json::from_str(&local_var_content).map_err(Error::from)
268 } else {
269 let local_var_retry_delay =
270 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
271 let local_var_content = local_var_resp.text().await?;
272 let local_var_entity: Option<HealthCheckError> =
273 serde_json::from_str(&local_var_content).ok();
274 let local_var_error = ResponseContent {
275 status: local_var_status,
276 content: local_var_content,
277 entity: local_var_entity,
278 retry_delay: local_var_retry_delay,
279 };
280 Err(Error::ResponseError(local_var_error))
281 }
282}
283
284pub async fn health_check(
286 configuration: &configuration::Configuration,
287) -> Result<serde_json::Value, Error<HealthCheckError>> {
288 let mut backoff = configuration.backoff.clone();
289 let mut refreshed_credentials = false;
290 let method = reqwest::Method::GET;
291 loop {
292 let result = health_check_inner(configuration, &mut backoff).await;
293
294 match result {
295 Ok(result) => return Ok(result),
296 Err(Error::ResponseError(response)) => {
297 if !refreshed_credentials
298 && matches!(
299 response.status,
300 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
301 )
302 {
303 configuration.qcs_config.refresh().await?;
304 refreshed_credentials = true;
305 continue;
306 } else if let Some(duration) = response.retry_delay {
307 tokio::time::sleep(duration).await;
308 continue;
309 }
310
311 return Err(Error::ResponseError(response));
312 }
313 Err(Error::Reqwest(error)) => {
314 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
315 tokio::time::sleep(duration).await;
316 continue;
317 }
318
319 return Err(Error::Reqwest(error));
320 }
321 Err(Error::Io(error)) => {
322 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
323 tokio::time::sleep(duration).await;
324 continue;
325 }
326
327 return Err(Error::Io(error));
328 }
329 Err(error) => return Err(error),
330 }
331 }
332}
333async fn health_check_deprecated_inner(
334 configuration: &configuration::Configuration,
335 backoff: &mut ExponentialBackoff,
336) -> Result<serde_json::Value, Error<HealthCheckDeprecatedError>> {
337 let local_var_configuration = configuration;
338
339 let local_var_client = &local_var_configuration.client;
340
341 let local_var_uri_str = format!("{}/v1/", local_var_configuration.qcs_config.api_url());
342 let mut local_var_req_builder =
343 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
344
345 #[cfg(feature = "tracing")]
346 {
347 let local_var_do_tracing =
350 local_var_uri_str
351 .parse::<::url::Url>()
352 .ok()
353 .map_or(true, |url| {
354 configuration
355 .qcs_config
356 .should_trace(&::urlpattern::UrlPatternMatchInput::Url(url))
357 });
358
359 if local_var_do_tracing {
360 ::tracing::debug!(
361 url=%local_var_uri_str,
362 method="GET",
363 "making health_check_deprecated request",
364 );
365 }
366 }
367
368 {
371 use qcs_api_client_common::configuration::TokenError;
372
373 #[allow(
374 clippy::nonminimal_bool,
375 clippy::eq_op,
376 reason = "Logic must be done at runtime since it cannot be handled by the mustache template engine."
377 )]
378 let is_jwt_bearer_optional: bool = false;
379
380 let token = local_var_configuration
381 .qcs_config
382 .get_bearer_access_token()
383 .await;
384
385 if is_jwt_bearer_optional && matches!(token, Err(TokenError::NoCredentials)) {
386 #[cfg(feature = "tracing")]
388 tracing::debug!(
389 "No client credentials found, but this call does not require authentication."
390 );
391 } else {
392 local_var_req_builder = local_var_req_builder.bearer_auth(token?);
393 }
394 }
395
396 let local_var_req = local_var_req_builder.build()?;
397 let local_var_resp = local_var_client.execute(local_var_req).await?;
398
399 let local_var_status = local_var_resp.status();
400
401 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
402 let local_var_content = local_var_resp.text().await?;
403 serde_json::from_str(&local_var_content).map_err(Error::from)
404 } else {
405 let local_var_retry_delay =
406 duration_from_response(local_var_resp.status(), local_var_resp.headers(), backoff);
407 let local_var_content = local_var_resp.text().await?;
408 let local_var_entity: Option<HealthCheckDeprecatedError> =
409 serde_json::from_str(&local_var_content).ok();
410 let local_var_error = ResponseContent {
411 status: local_var_status,
412 content: local_var_content,
413 entity: local_var_entity,
414 retry_delay: local_var_retry_delay,
415 };
416 Err(Error::ResponseError(local_var_error))
417 }
418}
419
420pub async fn health_check_deprecated(
422 configuration: &configuration::Configuration,
423) -> Result<serde_json::Value, Error<HealthCheckDeprecatedError>> {
424 let mut backoff = configuration.backoff.clone();
425 let mut refreshed_credentials = false;
426 let method = reqwest::Method::GET;
427 loop {
428 let result = health_check_deprecated_inner(configuration, &mut backoff).await;
429
430 match result {
431 Ok(result) => return Ok(result),
432 Err(Error::ResponseError(response)) => {
433 if !refreshed_credentials
434 && matches!(
435 response.status,
436 StatusCode::FORBIDDEN | StatusCode::UNAUTHORIZED
437 )
438 {
439 configuration.qcs_config.refresh().await?;
440 refreshed_credentials = true;
441 continue;
442 } else if let Some(duration) = response.retry_delay {
443 tokio::time::sleep(duration).await;
444 continue;
445 }
446
447 return Err(Error::ResponseError(response));
448 }
449 Err(Error::Reqwest(error)) => {
450 if let Some(duration) = duration_from_reqwest_error(&method, &error, &mut backoff) {
451 tokio::time::sleep(duration).await;
452 continue;
453 }
454
455 return Err(Error::Reqwest(error));
456 }
457 Err(Error::Io(error)) => {
458 if let Some(duration) = duration_from_io_error(&method, &error, &mut backoff) {
459 tokio::time::sleep(duration).await;
460 continue;
461 }
462
463 return Err(Error::Io(error));
464 }
465 Err(error) => return Err(error),
466 }
467 }
468}