hanzo_client/apis/
base_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 GetBaseBasesError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetBaseBasesByOrgError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetBaseHealthError {
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn get_base_bases(configuration: &configuration::Configuration, ) -> Result<Vec<models::BaseView>, Error<GetBaseBasesError>> {
42
43 let uri_str = format!("{}/v1/base/bases", configuration.base_path);
44 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46 if let Some(ref user_agent) = configuration.user_agent {
47 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
48 }
49 if let Some(ref token) = configuration.bearer_access_token {
50 req_builder = req_builder.bearer_auth(token.to_owned());
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 `Vec<models::BaseView>`"))),
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 `Vec<models::BaseView>`")))),
70 }
71 } else {
72 let content = resp.text().await?;
73 let entity: Option<GetBaseBasesError> = serde_json::from_str(&content).ok();
74 Err(Error::ResponseError(ResponseContent { status, content, entity }))
75 }
76}
77
78pub async fn get_base_bases_by_org(configuration: &configuration::Configuration, org: &str) -> Result<models::BaseView, Error<GetBaseBasesByOrgError>> {
80 let p_org = org;
82
83 let uri_str = format!("{}/v1/base/bases/{org}", configuration.base_path, org=crate::apis::urlencode(p_org));
84 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86 if let Some(ref user_agent) = configuration.user_agent {
87 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88 }
89 if let Some(ref token) = configuration.bearer_access_token {
90 req_builder = req_builder.bearer_auth(token.to_owned());
91 };
92
93 let req = req_builder.build()?;
94 let resp = configuration.client.execute(req).await?;
95
96 let status = resp.status();
97 let content_type = resp
98 .headers()
99 .get("content-type")
100 .and_then(|v| v.to_str().ok())
101 .unwrap_or("application/octet-stream");
102 let content_type = super::ContentType::from(content_type);
103
104 if !status.is_client_error() && !status.is_server_error() {
105 let content = resp.text().await?;
106 match content_type {
107 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseView`"))),
109 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::BaseView`")))),
110 }
111 } else {
112 let content = resp.text().await?;
113 let entity: Option<GetBaseBasesByOrgError> = serde_json::from_str(&content).ok();
114 Err(Error::ResponseError(ResponseContent { status, content, entity }))
115 }
116}
117
118pub async fn get_base_health(configuration: &configuration::Configuration, ) -> Result<models::BaseHealth, Error<GetBaseHealthError>> {
120
121 let uri_str = format!("{}/v1/base/health", configuration.base_path);
122 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
123
124 if let Some(ref user_agent) = configuration.user_agent {
125 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126 }
127 if let Some(ref token) = configuration.bearer_access_token {
128 req_builder = req_builder.bearer_auth(token.to_owned());
129 };
130
131 let req = req_builder.build()?;
132 let resp = configuration.client.execute(req).await?;
133
134 let status = resp.status();
135 let content_type = resp
136 .headers()
137 .get("content-type")
138 .and_then(|v| v.to_str().ok())
139 .unwrap_or("application/octet-stream");
140 let content_type = super::ContentType::from(content_type);
141
142 if !status.is_client_error() && !status.is_server_error() {
143 let content = resp.text().await?;
144 match content_type {
145 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
146 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseHealth`"))),
147 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::BaseHealth`")))),
148 }
149 } else {
150 let content = resp.text().await?;
151 let entity: Option<GetBaseHealthError> = serde_json::from_str(&content).ok();
152 Err(Error::ResponseError(ResponseContent { status, content, entity }))
153 }
154}
155