hanzo_client/apis/
gateway_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 GatewayTrafficError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetGatewayConfigError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PutGatewayConfigError {
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn gateway_traffic(configuration: &configuration::Configuration, ) -> Result<models::TrafficView, Error<GatewayTrafficError>> {
42
43 let uri_str = format!("{}/v1/gateway/traffic", 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 `models::TrafficView`"))),
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::TrafficView`")))),
70 }
71 } else {
72 let content = resp.text().await?;
73 let entity: Option<GatewayTrafficError> = serde_json::from_str(&content).ok();
74 Err(Error::ResponseError(ResponseContent { status, content, entity }))
75 }
76}
77
78pub async fn get_gateway_config(configuration: &configuration::Configuration, ) -> Result<models::Policy, Error<GetGatewayConfigError>> {
80
81 let uri_str = format!("{}/v1/gateway/config", 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 if let Some(ref token) = configuration.bearer_access_token {
88 req_builder = req_builder.bearer_auth(token.to_owned());
89 };
90
91 let req = req_builder.build()?;
92 let resp = configuration.client.execute(req).await?;
93
94 let status = resp.status();
95 let content_type = resp
96 .headers()
97 .get("content-type")
98 .and_then(|v| v.to_str().ok())
99 .unwrap_or("application/octet-stream");
100 let content_type = super::ContentType::from(content_type);
101
102 if !status.is_client_error() && !status.is_server_error() {
103 let content = resp.text().await?;
104 match content_type {
105 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
106 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Policy`"))),
107 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::Policy`")))),
108 }
109 } else {
110 let content = resp.text().await?;
111 let entity: Option<GetGatewayConfigError> = serde_json::from_str(&content).ok();
112 Err(Error::ResponseError(ResponseContent { status, content, entity }))
113 }
114}
115
116pub async fn put_gateway_config(configuration: &configuration::Configuration, policy: models::Policy) -> Result<models::Policy, Error<PutGatewayConfigError>> {
118 let p_policy = policy;
120
121 let uri_str = format!("{}/v1/gateway/config", configuration.base_path);
122 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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 req_builder = req_builder.json(&p_policy);
131
132 let req = req_builder.build()?;
133 let resp = configuration.client.execute(req).await?;
134
135 let status = resp.status();
136 let content_type = resp
137 .headers()
138 .get("content-type")
139 .and_then(|v| v.to_str().ok())
140 .unwrap_or("application/octet-stream");
141 let content_type = super::ContentType::from(content_type);
142
143 if !status.is_client_error() && !status.is_server_error() {
144 let content = resp.text().await?;
145 match content_type {
146 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
147 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Policy`"))),
148 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::Policy`")))),
149 }
150 } else {
151 let content = resp.text().await?;
152 let entity: Option<PutGatewayConfigError> = serde_json::from_str(&content).ok();
153 Err(Error::ResponseError(ResponseContent { status, content, entity }))
154 }
155}
156