cortex_client/apis/
status_api.rs1use 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 GetHealthStatusError {
22 Status503(models::HealthResponse),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetStatusError {
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetStatusAlertsError {
37 Status401(models::Error),
38 Status403(models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_health_status(configuration: &configuration::Configuration, ) -> Result<models::HealthResponse, Error<GetHealthStatusError>> {
44
45 let uri_str = format!("{}/status/health", configuration.base_path);
46 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
47
48 if let Some(ref user_agent) = configuration.user_agent {
49 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50 }
51 if let Some(ref token) = configuration.bearer_access_token {
52 req_builder = req_builder.bearer_auth(token.to_owned());
53 };
54
55 let req = req_builder.build()?;
56 let resp = configuration.client.execute(req).await?;
57
58 let status = resp.status();
59 let content_type = resp
60 .headers()
61 .get("content-type")
62 .and_then(|v| v.to_str().ok())
63 .unwrap_or("application/octet-stream");
64 let content_type = super::ContentType::from(content_type);
65
66 if !status.is_client_error() && !status.is_server_error() {
67 let content = resp.text().await?;
68 match content_type {
69 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
70 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::HealthResponse`"))),
71 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::HealthResponse`")))),
72 }
73 } else {
74 let content = resp.text().await?;
75 let entity: Option<GetHealthStatusError> = serde_json::from_str(&content).ok();
76 Err(Error::ResponseError(ResponseContent { status, content, entity }))
77 }
78}
79
80pub async fn get_status(configuration: &configuration::Configuration, ) -> Result<models::StatusResponse, Error<GetStatusError>> {
81
82 let uri_str = format!("{}/status", configuration.base_path);
83 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
84
85 if let Some(ref user_agent) = configuration.user_agent {
86 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87 }
88 if let Some(ref token) = configuration.bearer_access_token {
89 req_builder = req_builder.bearer_auth(token.to_owned());
90 };
91
92 let req = req_builder.build()?;
93 let resp = configuration.client.execute(req).await?;
94
95 let status = resp.status();
96 let content_type = resp
97 .headers()
98 .get("content-type")
99 .and_then(|v| v.to_str().ok())
100 .unwrap_or("application/octet-stream");
101 let content_type = super::ContentType::from(content_type);
102
103 if !status.is_client_error() && !status.is_server_error() {
104 let content = resp.text().await?;
105 match content_type {
106 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StatusResponse`"))),
108 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::StatusResponse`")))),
109 }
110 } else {
111 let content = resp.text().await?;
112 let entity: Option<GetStatusError> = serde_json::from_str(&content).ok();
113 Err(Error::ResponseError(ResponseContent { status, content, entity }))
114 }
115}
116
117pub async fn get_status_alerts(configuration: &configuration::Configuration, ) -> Result<Vec<String>, Error<GetStatusAlertsError>> {
118
119 let uri_str = format!("{}/status/alerts", configuration.base_path);
120 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
121
122 if let Some(ref user_agent) = configuration.user_agent {
123 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124 }
125 if let Some(ref token) = configuration.bearer_access_token {
126 req_builder = req_builder.bearer_auth(token.to_owned());
127 };
128
129 let req = req_builder.build()?;
130 let resp = configuration.client.execute(req).await?;
131
132 let status = resp.status();
133 let content_type = resp
134 .headers()
135 .get("content-type")
136 .and_then(|v| v.to_str().ok())
137 .unwrap_or("application/octet-stream");
138 let content_type = super::ContentType::from(content_type);
139
140 if !status.is_client_error() && !status.is_server_error() {
141 let content = resp.text().await?;
142 match content_type {
143 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
144 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<String>`"))),
145 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<String>`")))),
146 }
147 } else {
148 let content = resp.text().await?;
149 let entity: Option<GetStatusAlertsError> = serde_json::from_str(&content).ok();
150 Err(Error::ResponseError(ResponseContent { status, content, entity }))
151 }
152}
153