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