Skip to main content

tapis_workflows/apis/
general_api.rs

1/*
2 * Tapis Workflows API
3 *
4 * Create and manage pipelines
5 *
6 * The version of the OpenAPI document: 1.6.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/// Health check.
25pub async fn health_check(
26    configuration: &configuration::Configuration,
27) -> Result<models::RespBase, Error<HealthCheckError>> {
28    let uri_str = format!("{}/v3/workflows/healthcheck", configuration.base_path);
29    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
30
31    if let Some(ref user_agent) = configuration.user_agent {
32        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
33    }
34    if let Some(ref apikey) = configuration.api_key {
35        let key = apikey.key.clone();
36        let value = match apikey.prefix {
37            Some(ref prefix) => format!("{} {}", prefix, key),
38            None => key,
39        };
40        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
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::RespBase`"))),
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::RespBase`")))),
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}