1use crate::datadog;
5use flate2::{
6 write::{GzEncoder, ZlibEncoder},
7 Compression,
8};
9use reqwest::header::{HeaderMap, HeaderValue};
10use serde::{Deserialize, Serialize};
11use std::io::Write;
12
13#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct ListAuthNMappingsOptionalParams {
17 pub page_size: Option<i64>,
19 pub page_number: Option<i64>,
21 pub sort: Option<crate::datadogV2::model::AuthNMappingsSort>,
23 pub filter: Option<String>,
25 pub resource_type: Option<crate::datadogV2::model::AuthNMappingResourceType>,
27}
28
29impl ListAuthNMappingsOptionalParams {
30 pub fn page_size(mut self, value: i64) -> Self {
32 self.page_size = Some(value);
33 self
34 }
35 pub fn page_number(mut self, value: i64) -> Self {
37 self.page_number = Some(value);
38 self
39 }
40 pub fn sort(mut self, value: crate::datadogV2::model::AuthNMappingsSort) -> Self {
42 self.sort = Some(value);
43 self
44 }
45 pub fn filter(mut self, value: String) -> Self {
47 self.filter = Some(value);
48 self
49 }
50 pub fn resource_type(
52 mut self,
53 value: crate::datadogV2::model::AuthNMappingResourceType,
54 ) -> Self {
55 self.resource_type = Some(value);
56 self
57 }
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum CreateAuthNMappingError {
64 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum DeleteAuthNMappingError {
72 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum GetAuthNMappingError {
80 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
81 UnknownValue(serde_json::Value),
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum ListAuthNMappingsError {
88 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum UpdateAuthNMappingError {
96 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
97 UnknownValue(serde_json::Value),
98}
99
100#[derive(Debug, Clone)]
104pub struct AuthNMappingsAPI {
105 config: datadog::Configuration,
106 client: reqwest_middleware::ClientWithMiddleware,
107}
108
109impl Default for AuthNMappingsAPI {
110 fn default() -> Self {
111 Self::with_config(datadog::Configuration::default())
112 }
113}
114
115impl AuthNMappingsAPI {
116 pub fn new() -> Self {
117 Self::default()
118 }
119 pub fn with_config(config: datadog::Configuration) -> Self {
120 let mut reqwest_client_builder = reqwest::Client::builder();
121
122 if let Some(proxy_url) = &config.proxy_url {
123 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
124 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
125 }
126
127 let mut middleware_client_builder =
128 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
129
130 if config.enable_retry {
131 struct RetryableStatus;
132 impl reqwest_retry::RetryableStrategy for RetryableStatus {
133 fn handle(
134 &self,
135 res: &Result<reqwest::Response, reqwest_middleware::Error>,
136 ) -> Option<reqwest_retry::Retryable> {
137 match res {
138 Ok(success) => reqwest_retry::default_on_request_success(success),
139 Err(_) => None,
140 }
141 }
142 }
143 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
144 .build_with_max_retries(config.max_retries);
145
146 let retry_middleware =
147 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
148 backoff_policy,
149 RetryableStatus,
150 );
151
152 middleware_client_builder = middleware_client_builder.with(retry_middleware);
153 }
154
155 let client = middleware_client_builder.build();
156
157 Self { config, client }
158 }
159
160 pub fn with_client_and_config(
161 config: datadog::Configuration,
162 client: reqwest_middleware::ClientWithMiddleware,
163 ) -> Self {
164 Self { config, client }
165 }
166
167 pub async fn create_authn_mapping(
169 &self,
170 body: crate::datadogV2::model::AuthNMappingCreateRequest,
171 ) -> Result<
172 crate::datadogV2::model::AuthNMappingResponse,
173 datadog::Error<CreateAuthNMappingError>,
174 > {
175 match self.create_authn_mapping_with_http_info(body).await {
176 Ok(response_content) => {
177 if let Some(e) = response_content.entity {
178 Ok(e)
179 } else {
180 Err(datadog::Error::Serde(serde::de::Error::custom(
181 "response content was None",
182 )))
183 }
184 }
185 Err(err) => Err(err),
186 }
187 }
188
189 pub async fn create_authn_mapping_with_http_info(
191 &self,
192 body: crate::datadogV2::model::AuthNMappingCreateRequest,
193 ) -> Result<
194 datadog::ResponseContent<crate::datadogV2::model::AuthNMappingResponse>,
195 datadog::Error<CreateAuthNMappingError>,
196 > {
197 let local_configuration = &self.config;
198 let operation_id = "v2.create_authn_mapping";
199
200 let local_client = &self.client;
201
202 let local_uri_str = format!(
203 "{}/api/v2/authn_mappings",
204 local_configuration.get_operation_host(operation_id)
205 );
206 let mut local_req_builder =
207 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
208
209 let mut headers = HeaderMap::new();
211 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
212 headers.insert("Accept", HeaderValue::from_static("application/json"));
213
214 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
216 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
217 Err(e) => {
218 log::warn!("Failed to parse user agent header: {e}, falling back to default");
219 headers.insert(
220 reqwest::header::USER_AGENT,
221 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
222 )
223 }
224 };
225
226 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
228 headers.insert(
229 "DD-API-KEY",
230 HeaderValue::from_str(local_key.key.as_str())
231 .expect("failed to parse DD-API-KEY header"),
232 );
233 };
234 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
235 headers.insert(
236 "DD-APPLICATION-KEY",
237 HeaderValue::from_str(local_key.key.as_str())
238 .expect("failed to parse DD-APPLICATION-KEY header"),
239 );
240 };
241
242 let output = Vec::new();
244 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
245 if body.serialize(&mut ser).is_ok() {
246 if let Some(content_encoding) = headers.get("Content-Encoding") {
247 match content_encoding.to_str().unwrap_or_default() {
248 "gzip" => {
249 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
250 let _ = enc.write_all(ser.into_inner().as_slice());
251 match enc.finish() {
252 Ok(buf) => {
253 local_req_builder = local_req_builder.body(buf);
254 }
255 Err(e) => return Err(datadog::Error::Io(e)),
256 }
257 }
258 "deflate" => {
259 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
260 let _ = enc.write_all(ser.into_inner().as_slice());
261 match enc.finish() {
262 Ok(buf) => {
263 local_req_builder = local_req_builder.body(buf);
264 }
265 Err(e) => return Err(datadog::Error::Io(e)),
266 }
267 }
268 "zstd1" => {
269 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
270 let _ = enc.write_all(ser.into_inner().as_slice());
271 match enc.finish() {
272 Ok(buf) => {
273 local_req_builder = local_req_builder.body(buf);
274 }
275 Err(e) => return Err(datadog::Error::Io(e)),
276 }
277 }
278 _ => {
279 local_req_builder = local_req_builder.body(ser.into_inner());
280 }
281 }
282 } else {
283 local_req_builder = local_req_builder.body(ser.into_inner());
284 }
285 }
286
287 local_req_builder = local_req_builder.headers(headers);
288 let local_req = local_req_builder.build()?;
289 log::debug!("request content: {:?}", local_req.body());
290 let local_resp = local_client.execute(local_req).await?;
291
292 let local_status = local_resp.status();
293 let local_content = local_resp.text().await?;
294 log::debug!("response content: {}", local_content);
295
296 if !local_status.is_client_error() && !local_status.is_server_error() {
297 match serde_json::from_str::<crate::datadogV2::model::AuthNMappingResponse>(
298 &local_content,
299 ) {
300 Ok(e) => {
301 return Ok(datadog::ResponseContent {
302 status: local_status,
303 content: local_content,
304 entity: Some(e),
305 })
306 }
307 Err(e) => return Err(datadog::Error::Serde(e)),
308 };
309 } else {
310 let local_entity: Option<CreateAuthNMappingError> =
311 serde_json::from_str(&local_content).ok();
312 let local_error = datadog::ResponseContent {
313 status: local_status,
314 content: local_content,
315 entity: local_entity,
316 };
317 Err(datadog::Error::ResponseError(local_error))
318 }
319 }
320
321 pub async fn delete_authn_mapping(
323 &self,
324 authn_mapping_id: String,
325 ) -> Result<(), datadog::Error<DeleteAuthNMappingError>> {
326 match self
327 .delete_authn_mapping_with_http_info(authn_mapping_id)
328 .await
329 {
330 Ok(_) => Ok(()),
331 Err(err) => Err(err),
332 }
333 }
334
335 pub async fn delete_authn_mapping_with_http_info(
337 &self,
338 authn_mapping_id: String,
339 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteAuthNMappingError>> {
340 let local_configuration = &self.config;
341 let operation_id = "v2.delete_authn_mapping";
342
343 let local_client = &self.client;
344
345 let local_uri_str = format!(
346 "{}/api/v2/authn_mappings/{authn_mapping_id}",
347 local_configuration.get_operation_host(operation_id),
348 authn_mapping_id = datadog::urlencode(authn_mapping_id)
349 );
350 let mut local_req_builder =
351 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
352
353 let mut headers = HeaderMap::new();
355 headers.insert("Accept", HeaderValue::from_static("*/*"));
356
357 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
359 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
360 Err(e) => {
361 log::warn!("Failed to parse user agent header: {e}, falling back to default");
362 headers.insert(
363 reqwest::header::USER_AGENT,
364 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
365 )
366 }
367 };
368
369 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
371 headers.insert(
372 "DD-API-KEY",
373 HeaderValue::from_str(local_key.key.as_str())
374 .expect("failed to parse DD-API-KEY header"),
375 );
376 };
377 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
378 headers.insert(
379 "DD-APPLICATION-KEY",
380 HeaderValue::from_str(local_key.key.as_str())
381 .expect("failed to parse DD-APPLICATION-KEY header"),
382 );
383 };
384
385 local_req_builder = local_req_builder.headers(headers);
386 let local_req = local_req_builder.build()?;
387 log::debug!("request content: {:?}", local_req.body());
388 let local_resp = local_client.execute(local_req).await?;
389
390 let local_status = local_resp.status();
391 let local_content = local_resp.text().await?;
392 log::debug!("response content: {}", local_content);
393
394 if !local_status.is_client_error() && !local_status.is_server_error() {
395 Ok(datadog::ResponseContent {
396 status: local_status,
397 content: local_content,
398 entity: None,
399 })
400 } else {
401 let local_entity: Option<DeleteAuthNMappingError> =
402 serde_json::from_str(&local_content).ok();
403 let local_error = datadog::ResponseContent {
404 status: local_status,
405 content: local_content,
406 entity: local_entity,
407 };
408 Err(datadog::Error::ResponseError(local_error))
409 }
410 }
411
412 pub async fn get_authn_mapping(
414 &self,
415 authn_mapping_id: String,
416 ) -> Result<crate::datadogV2::model::AuthNMappingResponse, datadog::Error<GetAuthNMappingError>>
417 {
418 match self
419 .get_authn_mapping_with_http_info(authn_mapping_id)
420 .await
421 {
422 Ok(response_content) => {
423 if let Some(e) = response_content.entity {
424 Ok(e)
425 } else {
426 Err(datadog::Error::Serde(serde::de::Error::custom(
427 "response content was None",
428 )))
429 }
430 }
431 Err(err) => Err(err),
432 }
433 }
434
435 pub async fn get_authn_mapping_with_http_info(
437 &self,
438 authn_mapping_id: String,
439 ) -> Result<
440 datadog::ResponseContent<crate::datadogV2::model::AuthNMappingResponse>,
441 datadog::Error<GetAuthNMappingError>,
442 > {
443 let local_configuration = &self.config;
444 let operation_id = "v2.get_authn_mapping";
445
446 let local_client = &self.client;
447
448 let local_uri_str = format!(
449 "{}/api/v2/authn_mappings/{authn_mapping_id}",
450 local_configuration.get_operation_host(operation_id),
451 authn_mapping_id = datadog::urlencode(authn_mapping_id)
452 );
453 let mut local_req_builder =
454 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
455
456 let mut headers = HeaderMap::new();
458 headers.insert("Accept", HeaderValue::from_static("application/json"));
459
460 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
462 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
463 Err(e) => {
464 log::warn!("Failed to parse user agent header: {e}, falling back to default");
465 headers.insert(
466 reqwest::header::USER_AGENT,
467 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
468 )
469 }
470 };
471
472 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
474 headers.insert(
475 "DD-API-KEY",
476 HeaderValue::from_str(local_key.key.as_str())
477 .expect("failed to parse DD-API-KEY header"),
478 );
479 };
480 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
481 headers.insert(
482 "DD-APPLICATION-KEY",
483 HeaderValue::from_str(local_key.key.as_str())
484 .expect("failed to parse DD-APPLICATION-KEY header"),
485 );
486 };
487
488 local_req_builder = local_req_builder.headers(headers);
489 let local_req = local_req_builder.build()?;
490 log::debug!("request content: {:?}", local_req.body());
491 let local_resp = local_client.execute(local_req).await?;
492
493 let local_status = local_resp.status();
494 let local_content = local_resp.text().await?;
495 log::debug!("response content: {}", local_content);
496
497 if !local_status.is_client_error() && !local_status.is_server_error() {
498 match serde_json::from_str::<crate::datadogV2::model::AuthNMappingResponse>(
499 &local_content,
500 ) {
501 Ok(e) => {
502 return Ok(datadog::ResponseContent {
503 status: local_status,
504 content: local_content,
505 entity: Some(e),
506 })
507 }
508 Err(e) => return Err(datadog::Error::Serde(e)),
509 };
510 } else {
511 let local_entity: Option<GetAuthNMappingError> =
512 serde_json::from_str(&local_content).ok();
513 let local_error = datadog::ResponseContent {
514 status: local_status,
515 content: local_content,
516 entity: local_entity,
517 };
518 Err(datadog::Error::ResponseError(local_error))
519 }
520 }
521
522 pub async fn list_authn_mappings(
524 &self,
525 params: ListAuthNMappingsOptionalParams,
526 ) -> Result<
527 crate::datadogV2::model::AuthNMappingsResponse,
528 datadog::Error<ListAuthNMappingsError>,
529 > {
530 match self.list_authn_mappings_with_http_info(params).await {
531 Ok(response_content) => {
532 if let Some(e) = response_content.entity {
533 Ok(e)
534 } else {
535 Err(datadog::Error::Serde(serde::de::Error::custom(
536 "response content was None",
537 )))
538 }
539 }
540 Err(err) => Err(err),
541 }
542 }
543
544 pub async fn list_authn_mappings_with_http_info(
546 &self,
547 params: ListAuthNMappingsOptionalParams,
548 ) -> Result<
549 datadog::ResponseContent<crate::datadogV2::model::AuthNMappingsResponse>,
550 datadog::Error<ListAuthNMappingsError>,
551 > {
552 let local_configuration = &self.config;
553 let operation_id = "v2.list_authn_mappings";
554
555 let page_size = params.page_size;
557 let page_number = params.page_number;
558 let sort = params.sort;
559 let filter = params.filter;
560 let resource_type = params.resource_type;
561
562 let local_client = &self.client;
563
564 let local_uri_str = format!(
565 "{}/api/v2/authn_mappings",
566 local_configuration.get_operation_host(operation_id)
567 );
568 let mut local_req_builder =
569 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
570
571 if let Some(ref local_query_param) = page_size {
572 local_req_builder =
573 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
574 };
575 if let Some(ref local_query_param) = page_number {
576 local_req_builder =
577 local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
578 };
579 if let Some(ref local_query_param) = sort {
580 local_req_builder =
581 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
582 };
583 if let Some(ref local_query_param) = filter {
584 local_req_builder =
585 local_req_builder.query(&[("filter", &local_query_param.to_string())]);
586 };
587 if let Some(ref local_query_param) = resource_type {
588 local_req_builder =
589 local_req_builder.query(&[("resource_type", &local_query_param.to_string())]);
590 };
591
592 let mut headers = HeaderMap::new();
594 headers.insert("Accept", HeaderValue::from_static("application/json"));
595
596 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
598 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
599 Err(e) => {
600 log::warn!("Failed to parse user agent header: {e}, falling back to default");
601 headers.insert(
602 reqwest::header::USER_AGENT,
603 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
604 )
605 }
606 };
607
608 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
610 headers.insert(
611 "DD-API-KEY",
612 HeaderValue::from_str(local_key.key.as_str())
613 .expect("failed to parse DD-API-KEY header"),
614 );
615 };
616 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
617 headers.insert(
618 "DD-APPLICATION-KEY",
619 HeaderValue::from_str(local_key.key.as_str())
620 .expect("failed to parse DD-APPLICATION-KEY header"),
621 );
622 };
623
624 local_req_builder = local_req_builder.headers(headers);
625 let local_req = local_req_builder.build()?;
626 log::debug!("request content: {:?}", local_req.body());
627 let local_resp = local_client.execute(local_req).await?;
628
629 let local_status = local_resp.status();
630 let local_content = local_resp.text().await?;
631 log::debug!("response content: {}", local_content);
632
633 if !local_status.is_client_error() && !local_status.is_server_error() {
634 match serde_json::from_str::<crate::datadogV2::model::AuthNMappingsResponse>(
635 &local_content,
636 ) {
637 Ok(e) => {
638 return Ok(datadog::ResponseContent {
639 status: local_status,
640 content: local_content,
641 entity: Some(e),
642 })
643 }
644 Err(e) => return Err(datadog::Error::Serde(e)),
645 };
646 } else {
647 let local_entity: Option<ListAuthNMappingsError> =
648 serde_json::from_str(&local_content).ok();
649 let local_error = datadog::ResponseContent {
650 status: local_status,
651 content: local_content,
652 entity: local_entity,
653 };
654 Err(datadog::Error::ResponseError(local_error))
655 }
656 }
657
658 pub async fn update_authn_mapping(
660 &self,
661 authn_mapping_id: String,
662 body: crate::datadogV2::model::AuthNMappingUpdateRequest,
663 ) -> Result<
664 crate::datadogV2::model::AuthNMappingResponse,
665 datadog::Error<UpdateAuthNMappingError>,
666 > {
667 match self
668 .update_authn_mapping_with_http_info(authn_mapping_id, body)
669 .await
670 {
671 Ok(response_content) => {
672 if let Some(e) = response_content.entity {
673 Ok(e)
674 } else {
675 Err(datadog::Error::Serde(serde::de::Error::custom(
676 "response content was None",
677 )))
678 }
679 }
680 Err(err) => Err(err),
681 }
682 }
683
684 pub async fn update_authn_mapping_with_http_info(
686 &self,
687 authn_mapping_id: String,
688 body: crate::datadogV2::model::AuthNMappingUpdateRequest,
689 ) -> Result<
690 datadog::ResponseContent<crate::datadogV2::model::AuthNMappingResponse>,
691 datadog::Error<UpdateAuthNMappingError>,
692 > {
693 let local_configuration = &self.config;
694 let operation_id = "v2.update_authn_mapping";
695
696 let local_client = &self.client;
697
698 let local_uri_str = format!(
699 "{}/api/v2/authn_mappings/{authn_mapping_id}",
700 local_configuration.get_operation_host(operation_id),
701 authn_mapping_id = datadog::urlencode(authn_mapping_id)
702 );
703 let mut local_req_builder =
704 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
705
706 let mut headers = HeaderMap::new();
708 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
709 headers.insert("Accept", HeaderValue::from_static("application/json"));
710
711 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
713 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
714 Err(e) => {
715 log::warn!("Failed to parse user agent header: {e}, falling back to default");
716 headers.insert(
717 reqwest::header::USER_AGENT,
718 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
719 )
720 }
721 };
722
723 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
725 headers.insert(
726 "DD-API-KEY",
727 HeaderValue::from_str(local_key.key.as_str())
728 .expect("failed to parse DD-API-KEY header"),
729 );
730 };
731 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
732 headers.insert(
733 "DD-APPLICATION-KEY",
734 HeaderValue::from_str(local_key.key.as_str())
735 .expect("failed to parse DD-APPLICATION-KEY header"),
736 );
737 };
738
739 let output = Vec::new();
741 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
742 if body.serialize(&mut ser).is_ok() {
743 if let Some(content_encoding) = headers.get("Content-Encoding") {
744 match content_encoding.to_str().unwrap_or_default() {
745 "gzip" => {
746 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
747 let _ = enc.write_all(ser.into_inner().as_slice());
748 match enc.finish() {
749 Ok(buf) => {
750 local_req_builder = local_req_builder.body(buf);
751 }
752 Err(e) => return Err(datadog::Error::Io(e)),
753 }
754 }
755 "deflate" => {
756 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
757 let _ = enc.write_all(ser.into_inner().as_slice());
758 match enc.finish() {
759 Ok(buf) => {
760 local_req_builder = local_req_builder.body(buf);
761 }
762 Err(e) => return Err(datadog::Error::Io(e)),
763 }
764 }
765 "zstd1" => {
766 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
767 let _ = enc.write_all(ser.into_inner().as_slice());
768 match enc.finish() {
769 Ok(buf) => {
770 local_req_builder = local_req_builder.body(buf);
771 }
772 Err(e) => return Err(datadog::Error::Io(e)),
773 }
774 }
775 _ => {
776 local_req_builder = local_req_builder.body(ser.into_inner());
777 }
778 }
779 } else {
780 local_req_builder = local_req_builder.body(ser.into_inner());
781 }
782 }
783
784 local_req_builder = local_req_builder.headers(headers);
785 let local_req = local_req_builder.build()?;
786 log::debug!("request content: {:?}", local_req.body());
787 let local_resp = local_client.execute(local_req).await?;
788
789 let local_status = local_resp.status();
790 let local_content = local_resp.text().await?;
791 log::debug!("response content: {}", local_content);
792
793 if !local_status.is_client_error() && !local_status.is_server_error() {
794 match serde_json::from_str::<crate::datadogV2::model::AuthNMappingResponse>(
795 &local_content,
796 ) {
797 Ok(e) => {
798 return Ok(datadog::ResponseContent {
799 status: local_status,
800 content: local_content,
801 entity: Some(e),
802 })
803 }
804 Err(e) => return Err(datadog::Error::Serde(e)),
805 };
806 } else {
807 let local_entity: Option<UpdateAuthNMappingError> =
808 serde_json::from_str(&local_content).ok();
809 let local_error = datadog::ResponseContent {
810 status: local_status,
811 content: local_content,
812 entity: local_entity,
813 };
814 Err(datadog::Error::ResponseError(local_error))
815 }
816 }
817}