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