Skip to main content

tapis_apps/apis/
general_api.rs

1/*
2 * Tapis Applications API
3 *
4 * The Tapis Applications API provides for management of Tapis applications including permissions.
5 *
6 * The version of the OpenAPI document: 25Q4.0
7 * Contact: cicsupport@tacc.utexas.edu
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`health_check`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum HealthCheckError {
20    Status500(),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`ready_check`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum ReadyCheckError {
28    Status503(),
29    UnknownValue(serde_json::Value),
30}
31
32/// Health check. Lightweight non-authenticated check that service is alive.
33pub async fn health_check(
34    configuration: &configuration::Configuration,
35) -> Result<models::RespBasic, Error<HealthCheckError>> {
36    let uri_str = format!("{}/v3/apps/healthcheck", configuration.base_path);
37    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42
43    let req = req_builder.build()?;
44    let resp = configuration.client.execute(req).await?;
45
46    let status = resp.status();
47    let content_type = resp
48        .headers()
49        .get("content-type")
50        .and_then(|v| v.to_str().ok())
51        .unwrap_or("application/octet-stream");
52    let content_type = super::ContentType::from(content_type);
53
54    if !status.is_client_error() && !status.is_server_error() {
55        let content = resp.text().await?;
56        match content_type {
57            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
58            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
59            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
60        }
61    } else {
62        let content = resp.text().await?;
63        let entity: Option<HealthCheckError> = serde_json::from_str(&content).ok();
64        Err(Error::ResponseError(ResponseContent {
65            status,
66            content,
67            entity,
68        }))
69    }
70}
71
72/// Ready check. Non-authenticated check that service is ready to do work.
73pub async fn ready_check(
74    configuration: &configuration::Configuration,
75) -> Result<models::RespBasic, Error<ReadyCheckError>> {
76    let uri_str = format!("{}/v3/apps/readycheck", configuration.base_path);
77    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
78
79    if let Some(ref user_agent) = configuration.user_agent {
80        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
81    }
82
83    let req = req_builder.build()?;
84    let resp = configuration.client.execute(req).await?;
85
86    let status = resp.status();
87    let content_type = resp
88        .headers()
89        .get("content-type")
90        .and_then(|v| v.to_str().ok())
91        .unwrap_or("application/octet-stream");
92    let content_type = super::ContentType::from(content_type);
93
94    if !status.is_client_error() && !status.is_server_error() {
95        let content = resp.text().await?;
96        match content_type {
97            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
99            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
100        }
101    } else {
102        let content = resp.text().await?;
103        let entity: Option<ReadyCheckError> = serde_json::from_str(&content).ok();
104        Err(Error::ResponseError(ResponseContent {
105            status,
106            content,
107            entity,
108        }))
109    }
110}