1use super::{Error, configuration};
12use crate::apis::ContentType;
13use crate::{apis::ResponseContent, models};
14use async_trait::async_trait;
15#[cfg(feature = "mockall")]
16use mockall::automock;
17use reqwest;
18use serde::{Deserialize, Serialize, de::Error as _};
19use std::sync::Arc;
20
21#[cfg_attr(feature = "mockall", automock)]
22#[async_trait]
23pub trait LoggingApi: Send + Sync {
24 async fn get_logger<'logger_name>(
28 &self,
29 logger_name: &'logger_name str,
30 ) -> Result<models::LoggerInfo, Error<GetLoggerError>>;
31
32 async fn get_logger1(&self) -> Result<models::LoggerBean, Error<GetLogger1Error>>;
36
37 async fn put_logger<'logger_name, 'logger_info>(
41 &self,
42 logger_name: &'logger_name str,
43 logger_info: models::LoggerInfo,
44 ) -> Result<(), Error<PutLoggerError>>;
45
46 async fn remove_logger<'logger_name>(
50 &self,
51 logger_name: &'logger_name str,
52 ) -> Result<(), Error<RemoveLoggerError>>;
53}
54
55pub struct LoggingApiClient {
56 configuration: Arc<configuration::Configuration>,
57}
58
59impl LoggingApiClient {
60 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
61 Self { configuration }
62 }
63}
64
65#[async_trait]
66impl LoggingApi for LoggingApiClient {
67 async fn get_logger<'logger_name>(
68 &self,
69 logger_name: &'logger_name str,
70 ) -> Result<models::LoggerInfo, Error<GetLoggerError>> {
71 let local_var_configuration = &self.configuration;
72
73 let local_var_client = &local_var_configuration.client;
74
75 let local_var_uri_str = format!(
76 "{}/logging/{loggerName}",
77 local_var_configuration.base_path,
78 loggerName = crate::apis::urlencode(logger_name)
79 );
80 let mut local_var_req_builder =
81 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
82
83 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
84 local_var_req_builder = local_var_req_builder
85 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86 }
87 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
88 local_var_req_builder = local_var_req_builder.basic_auth(
89 local_var_auth_conf.0.to_owned(),
90 local_var_auth_conf.1.to_owned(),
91 );
92 };
93 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
94 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
95 };
96
97 let local_var_req = local_var_req_builder.build()?;
98 let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100 let local_var_status = local_var_resp.status();
101 let local_var_content_type = local_var_resp
102 .headers()
103 .get("content-type")
104 .and_then(|v| v.to_str().ok())
105 .unwrap_or("application/octet-stream");
106 let local_var_content_type = super::ContentType::from(local_var_content_type);
107 let local_var_content = local_var_resp.text().await?;
108
109 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
110 match local_var_content_type {
111 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
112 ContentType::Text => {
113 return Err(Error::from(serde_json::Error::custom(
114 "Received `text/plain` content type response that cannot be converted to `models::LoggerInfo`",
115 )));
116 }
117 ContentType::Unsupported(local_var_unknown_type) => {
118 return Err(Error::from(serde_json::Error::custom(format!(
119 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::LoggerInfo`"
120 ))));
121 }
122 }
123 } else {
124 let local_var_entity: Option<GetLoggerError> =
125 serde_json::from_str(&local_var_content).ok();
126 let local_var_error = ResponseContent {
127 status: local_var_status,
128 content: local_var_content,
129 entity: local_var_entity,
130 };
131 Err(Error::ResponseError(local_var_error))
132 }
133 }
134
135 async fn get_logger1(&self) -> Result<models::LoggerBean, Error<GetLogger1Error>> {
136 let local_var_configuration = &self.configuration;
137
138 let local_var_client = &local_var_configuration.client;
139
140 let local_var_uri_str = format!("{}/logging", local_var_configuration.base_path);
141 let mut local_var_req_builder =
142 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
143
144 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145 local_var_req_builder = local_var_req_builder
146 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147 }
148 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
149 local_var_req_builder = local_var_req_builder.basic_auth(
150 local_var_auth_conf.0.to_owned(),
151 local_var_auth_conf.1.to_owned(),
152 );
153 };
154 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
155 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
156 };
157
158 let local_var_req = local_var_req_builder.build()?;
159 let local_var_resp = local_var_client.execute(local_var_req).await?;
160
161 let local_var_status = local_var_resp.status();
162 let local_var_content_type = local_var_resp
163 .headers()
164 .get("content-type")
165 .and_then(|v| v.to_str().ok())
166 .unwrap_or("application/octet-stream");
167 let local_var_content_type = super::ContentType::from(local_var_content_type);
168 let local_var_content = local_var_resp.text().await?;
169
170 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
171 match local_var_content_type {
172 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
173 ContentType::Text => {
174 return Err(Error::from(serde_json::Error::custom(
175 "Received `text/plain` content type response that cannot be converted to `models::LoggerBean`",
176 )));
177 }
178 ContentType::Unsupported(local_var_unknown_type) => {
179 return Err(Error::from(serde_json::Error::custom(format!(
180 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::LoggerBean`"
181 ))));
182 }
183 }
184 } else {
185 let local_var_entity: Option<GetLogger1Error> =
186 serde_json::from_str(&local_var_content).ok();
187 let local_var_error = ResponseContent {
188 status: local_var_status,
189 content: local_var_content,
190 entity: local_var_entity,
191 };
192 Err(Error::ResponseError(local_var_error))
193 }
194 }
195
196 async fn put_logger<'logger_name, 'logger_info>(
197 &self,
198 logger_name: &'logger_name str,
199 logger_info: models::LoggerInfo,
200 ) -> Result<(), Error<PutLoggerError>> {
201 let local_var_configuration = &self.configuration;
202
203 let local_var_client = &local_var_configuration.client;
204
205 let local_var_uri_str = format!(
206 "{}/logging/{loggerName}",
207 local_var_configuration.base_path,
208 loggerName = crate::apis::urlencode(logger_name)
209 );
210 let mut local_var_req_builder =
211 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
212
213 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
214 local_var_req_builder = local_var_req_builder
215 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
216 }
217 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
218 local_var_req_builder = local_var_req_builder.basic_auth(
219 local_var_auth_conf.0.to_owned(),
220 local_var_auth_conf.1.to_owned(),
221 );
222 };
223 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
224 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
225 };
226 local_var_req_builder = local_var_req_builder.json(&logger_info);
227
228 let local_var_req = local_var_req_builder.build()?;
229 let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231 let local_var_status = local_var_resp.status();
232 let local_var_content = local_var_resp.text().await?;
233
234 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235 Ok(())
236 } else {
237 let local_var_entity: Option<PutLoggerError> =
238 serde_json::from_str(&local_var_content).ok();
239 let local_var_error = ResponseContent {
240 status: local_var_status,
241 content: local_var_content,
242 entity: local_var_entity,
243 };
244 Err(Error::ResponseError(local_var_error))
245 }
246 }
247
248 async fn remove_logger<'logger_name>(
249 &self,
250 logger_name: &'logger_name str,
251 ) -> Result<(), Error<RemoveLoggerError>> {
252 let local_var_configuration = &self.configuration;
253
254 let local_var_client = &local_var_configuration.client;
255
256 let local_var_uri_str = format!(
257 "{}/logging/{loggerName}",
258 local_var_configuration.base_path,
259 loggerName = crate::apis::urlencode(logger_name)
260 );
261 let mut local_var_req_builder =
262 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
263
264 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
265 local_var_req_builder = local_var_req_builder
266 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
267 }
268 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
269 local_var_req_builder = local_var_req_builder.basic_auth(
270 local_var_auth_conf.0.to_owned(),
271 local_var_auth_conf.1.to_owned(),
272 );
273 };
274 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
275 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
276 };
277
278 let local_var_req = local_var_req_builder.build()?;
279 let local_var_resp = local_var_client.execute(local_var_req).await?;
280
281 let local_var_status = local_var_resp.status();
282 let local_var_content = local_var_resp.text().await?;
283
284 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
285 Ok(())
286 } else {
287 let local_var_entity: Option<RemoveLoggerError> =
288 serde_json::from_str(&local_var_content).ok();
289 let local_var_error = ResponseContent {
290 status: local_var_status,
291 content: local_var_content,
292 entity: local_var_entity,
293 };
294 Err(Error::ResponseError(local_var_error))
295 }
296 }
297}
298
299#[derive(Debug, Clone, Serialize, Deserialize)]
301#[serde(untagged)]
302pub enum GetLoggerError {
303 UnknownValue(serde_json::Value),
304}
305
306#[derive(Debug, Clone, Serialize, Deserialize)]
308#[serde(untagged)]
309pub enum GetLogger1Error {
310 UnknownValue(serde_json::Value),
311}
312
313#[derive(Debug, Clone, Serialize, Deserialize)]
315#[serde(untagged)]
316pub enum PutLoggerError {
317 Status400(),
318 UnknownValue(serde_json::Value),
319}
320
321#[derive(Debug, Clone, Serialize, Deserialize)]
323#[serde(untagged)]
324pub enum RemoveLoggerError {
325 UnknownValue(serde_json::Value),
326}