hanzo_client/apis/
network_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 GetNetworkError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetNetworkByIdError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetNetworkRoutersError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetNetworkServicesError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn get_network(configuration: &configuration::Configuration, ) -> Result<models::NetworkList, Error<GetNetworkError>> {
49
50 let uri_str = format!("{}/v1/network", configuration.base_path);
51 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53 if let Some(ref user_agent) = configuration.user_agent {
54 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55 }
56 if let Some(ref token) = configuration.bearer_access_token {
57 req_builder = req_builder.bearer_auth(token.to_owned());
58 };
59
60 let req = req_builder.build()?;
61 let resp = configuration.client.execute(req).await?;
62
63 let status = resp.status();
64 let content_type = resp
65 .headers()
66 .get("content-type")
67 .and_then(|v| v.to_str().ok())
68 .unwrap_or("application/octet-stream");
69 let content_type = super::ContentType::from(content_type);
70
71 if !status.is_client_error() && !status.is_server_error() {
72 let content = resp.text().await?;
73 match content_type {
74 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NetworkList`"))),
76 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::NetworkList`")))),
77 }
78 } else {
79 let content = resp.text().await?;
80 let entity: Option<GetNetworkError> = serde_json::from_str(&content).ok();
81 Err(Error::ResponseError(ResponseContent { status, content, entity }))
82 }
83}
84
85pub async fn get_network_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::NetworkView, Error<GetNetworkByIdError>> {
87 let p_id = id;
89
90 let uri_str = format!("{}/v1/network/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
91 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93 if let Some(ref user_agent) = configuration.user_agent {
94 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95 }
96 if let Some(ref token) = configuration.bearer_access_token {
97 req_builder = req_builder.bearer_auth(token.to_owned());
98 };
99
100 let req = req_builder.build()?;
101 let resp = configuration.client.execute(req).await?;
102
103 let status = resp.status();
104 let content_type = resp
105 .headers()
106 .get("content-type")
107 .and_then(|v| v.to_str().ok())
108 .unwrap_or("application/octet-stream");
109 let content_type = super::ContentType::from(content_type);
110
111 if !status.is_client_error() && !status.is_server_error() {
112 let content = resp.text().await?;
113 match content_type {
114 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NetworkView`"))),
116 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::NetworkView`")))),
117 }
118 } else {
119 let content = resp.text().await?;
120 let entity: Option<GetNetworkByIdError> = serde_json::from_str(&content).ok();
121 Err(Error::ResponseError(ResponseContent { status, content, entity }))
122 }
123}
124
125pub async fn get_network_routers(configuration: &configuration::Configuration, ) -> Result<models::RouterList, Error<GetNetworkRoutersError>> {
127
128 let uri_str = format!("{}/v1/network/routers", configuration.base_path);
129 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
130
131 if let Some(ref user_agent) = configuration.user_agent {
132 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133 }
134 if let Some(ref token) = configuration.bearer_access_token {
135 req_builder = req_builder.bearer_auth(token.to_owned());
136 };
137
138 let req = req_builder.build()?;
139 let resp = configuration.client.execute(req).await?;
140
141 let status = resp.status();
142 let content_type = resp
143 .headers()
144 .get("content-type")
145 .and_then(|v| v.to_str().ok())
146 .unwrap_or("application/octet-stream");
147 let content_type = super::ContentType::from(content_type);
148
149 if !status.is_client_error() && !status.is_server_error() {
150 let content = resp.text().await?;
151 match content_type {
152 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
153 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RouterList`"))),
154 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::RouterList`")))),
155 }
156 } else {
157 let content = resp.text().await?;
158 let entity: Option<GetNetworkRoutersError> = serde_json::from_str(&content).ok();
159 Err(Error::ResponseError(ResponseContent { status, content, entity }))
160 }
161}
162
163pub async fn get_network_services(configuration: &configuration::Configuration, ) -> Result<models::MeshServiceList, Error<GetNetworkServicesError>> {
165
166 let uri_str = format!("{}/v1/network/services", configuration.base_path);
167 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
168
169 if let Some(ref user_agent) = configuration.user_agent {
170 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171 }
172 if let Some(ref token) = configuration.bearer_access_token {
173 req_builder = req_builder.bearer_auth(token.to_owned());
174 };
175
176 let req = req_builder.build()?;
177 let resp = configuration.client.execute(req).await?;
178
179 let status = resp.status();
180 let content_type = resp
181 .headers()
182 .get("content-type")
183 .and_then(|v| v.to_str().ok())
184 .unwrap_or("application/octet-stream");
185 let content_type = super::ContentType::from(content_type);
186
187 if !status.is_client_error() && !status.is_server_error() {
188 let content = resp.text().await?;
189 match content_type {
190 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
191 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MeshServiceList`"))),
192 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::MeshServiceList`")))),
193 }
194 } else {
195 let content = resp.text().await?;
196 let entity: Option<GetNetworkServicesError> = serde_json::from_str(&content).ok();
197 Err(Error::ResponseError(ResponseContent { status, content, entity }))
198 }
199}
200