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 CreateDORADeploymentError {
17 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
18 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
19 UnknownValue(serde_json::Value),
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum CreateDORAFailureError {
26 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
27 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum CreateDORAIncidentError {
35 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
36 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetDORADeploymentError {
44 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
45 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum GetDORAFailureError {
53 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
54 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ListDORADeploymentsError {
62 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
63 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListDORAFailuresError {
71 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
72 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone)]
80pub struct DORAMetricsAPI {
81 config: datadog::Configuration,
82 client: reqwest_middleware::ClientWithMiddleware,
83}
84
85impl Default for DORAMetricsAPI {
86 fn default() -> Self {
87 Self::with_config(datadog::Configuration::default())
88 }
89}
90
91impl DORAMetricsAPI {
92 pub fn new() -> Self {
93 Self::default()
94 }
95 pub fn with_config(config: datadog::Configuration) -> Self {
96 let mut reqwest_client_builder = reqwest::Client::builder();
97
98 if let Some(proxy_url) = &config.proxy_url {
99 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
100 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
101 }
102
103 let mut middleware_client_builder =
104 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
105
106 if config.enable_retry {
107 struct RetryableStatus;
108 impl reqwest_retry::RetryableStrategy for RetryableStatus {
109 fn handle(
110 &self,
111 res: &Result<reqwest::Response, reqwest_middleware::Error>,
112 ) -> Option<reqwest_retry::Retryable> {
113 match res {
114 Ok(success) => reqwest_retry::default_on_request_success(success),
115 Err(_) => None,
116 }
117 }
118 }
119 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
120 .build_with_max_retries(config.max_retries);
121
122 let retry_middleware =
123 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
124 backoff_policy,
125 RetryableStatus,
126 );
127
128 middleware_client_builder = middleware_client_builder.with(retry_middleware);
129 }
130
131 let client = middleware_client_builder.build();
132
133 Self { config, client }
134 }
135
136 pub fn with_client_and_config(
137 config: datadog::Configuration,
138 client: reqwest_middleware::ClientWithMiddleware,
139 ) -> Self {
140 Self { config, client }
141 }
142
143 pub async fn create_dora_deployment(
150 &self,
151 body: crate::datadogV2::model::DORADeploymentRequest,
152 ) -> Result<
153 crate::datadogV2::model::DORADeploymentResponse,
154 datadog::Error<CreateDORADeploymentError>,
155 > {
156 match self.create_dora_deployment_with_http_info(body).await {
157 Ok(response_content) => {
158 if let Some(e) = response_content.entity {
159 Ok(e)
160 } else {
161 Err(datadog::Error::Serde(serde::de::Error::custom(
162 "response content was None",
163 )))
164 }
165 }
166 Err(err) => Err(err),
167 }
168 }
169
170 pub async fn create_dora_deployment_with_http_info(
177 &self,
178 body: crate::datadogV2::model::DORADeploymentRequest,
179 ) -> Result<
180 datadog::ResponseContent<crate::datadogV2::model::DORADeploymentResponse>,
181 datadog::Error<CreateDORADeploymentError>,
182 > {
183 let local_configuration = &self.config;
184 let operation_id = "v2.create_dora_deployment";
185
186 let local_client = &self.client;
187
188 let local_uri_str = format!(
189 "{}/api/v2/dora/deployment",
190 local_configuration.get_operation_host(operation_id)
191 );
192 let mut local_req_builder =
193 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
194
195 let mut headers = HeaderMap::new();
197 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
198 headers.insert("Accept", HeaderValue::from_static("application/json"));
199
200 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
202 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
203 Err(e) => {
204 log::warn!("Failed to parse user agent header: {e}, falling back to default");
205 headers.insert(
206 reqwest::header::USER_AGENT,
207 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
208 )
209 }
210 };
211
212 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
214 headers.insert(
215 "DD-API-KEY",
216 HeaderValue::from_str(local_key.key.as_str())
217 .expect("failed to parse DD-API-KEY header"),
218 );
219 };
220
221 let output = Vec::new();
223 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
224 if body.serialize(&mut ser).is_ok() {
225 if let Some(content_encoding) = headers.get("Content-Encoding") {
226 match content_encoding.to_str().unwrap_or_default() {
227 "gzip" => {
228 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
229 let _ = enc.write_all(ser.into_inner().as_slice());
230 match enc.finish() {
231 Ok(buf) => {
232 local_req_builder = local_req_builder.body(buf);
233 }
234 Err(e) => return Err(datadog::Error::Io(e)),
235 }
236 }
237 "deflate" => {
238 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
239 let _ = enc.write_all(ser.into_inner().as_slice());
240 match enc.finish() {
241 Ok(buf) => {
242 local_req_builder = local_req_builder.body(buf);
243 }
244 Err(e) => return Err(datadog::Error::Io(e)),
245 }
246 }
247 "zstd1" => {
248 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
249 let _ = enc.write_all(ser.into_inner().as_slice());
250 match enc.finish() {
251 Ok(buf) => {
252 local_req_builder = local_req_builder.body(buf);
253 }
254 Err(e) => return Err(datadog::Error::Io(e)),
255 }
256 }
257 _ => {
258 local_req_builder = local_req_builder.body(ser.into_inner());
259 }
260 }
261 } else {
262 local_req_builder = local_req_builder.body(ser.into_inner());
263 }
264 }
265
266 local_req_builder = local_req_builder.headers(headers);
267 let local_req = local_req_builder.build()?;
268 log::debug!("request content: {:?}", local_req.body());
269 let local_resp = local_client.execute(local_req).await?;
270
271 let local_status = local_resp.status();
272 let local_content = local_resp.text().await?;
273 log::debug!("response content: {}", local_content);
274
275 if !local_status.is_client_error() && !local_status.is_server_error() {
276 match serde_json::from_str::<crate::datadogV2::model::DORADeploymentResponse>(
277 &local_content,
278 ) {
279 Ok(e) => {
280 return Ok(datadog::ResponseContent {
281 status: local_status,
282 content: local_content,
283 entity: Some(e),
284 })
285 }
286 Err(e) => return Err(datadog::Error::Serde(e)),
287 };
288 } else {
289 let local_entity: Option<CreateDORADeploymentError> =
290 serde_json::from_str(&local_content).ok();
291 let local_error = datadog::ResponseContent {
292 status: local_status,
293 content: local_content,
294 entity: local_entity,
295 };
296 Err(datadog::Error::ResponseError(local_error))
297 }
298 }
299
300 pub async fn create_dora_failure(
306 &self,
307 body: crate::datadogV2::model::DORAFailureRequest,
308 ) -> Result<crate::datadogV2::model::DORAFailureResponse, datadog::Error<CreateDORAFailureError>>
309 {
310 match self.create_dora_failure_with_http_info(body).await {
311 Ok(response_content) => {
312 if let Some(e) = response_content.entity {
313 Ok(e)
314 } else {
315 Err(datadog::Error::Serde(serde::de::Error::custom(
316 "response content was None",
317 )))
318 }
319 }
320 Err(err) => Err(err),
321 }
322 }
323
324 pub async fn create_dora_failure_with_http_info(
330 &self,
331 body: crate::datadogV2::model::DORAFailureRequest,
332 ) -> Result<
333 datadog::ResponseContent<crate::datadogV2::model::DORAFailureResponse>,
334 datadog::Error<CreateDORAFailureError>,
335 > {
336 let local_configuration = &self.config;
337 let operation_id = "v2.create_dora_failure";
338
339 let local_client = &self.client;
340
341 let local_uri_str = format!(
342 "{}/api/v2/dora/failure",
343 local_configuration.get_operation_host(operation_id)
344 );
345 let mut local_req_builder =
346 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
347
348 let mut headers = HeaderMap::new();
350 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
351 headers.insert("Accept", HeaderValue::from_static("application/json"));
352
353 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
355 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
356 Err(e) => {
357 log::warn!("Failed to parse user agent header: {e}, falling back to default");
358 headers.insert(
359 reqwest::header::USER_AGENT,
360 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
361 )
362 }
363 };
364
365 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
367 headers.insert(
368 "DD-API-KEY",
369 HeaderValue::from_str(local_key.key.as_str())
370 .expect("failed to parse DD-API-KEY header"),
371 );
372 };
373
374 let output = Vec::new();
376 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
377 if body.serialize(&mut ser).is_ok() {
378 if let Some(content_encoding) = headers.get("Content-Encoding") {
379 match content_encoding.to_str().unwrap_or_default() {
380 "gzip" => {
381 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
382 let _ = enc.write_all(ser.into_inner().as_slice());
383 match enc.finish() {
384 Ok(buf) => {
385 local_req_builder = local_req_builder.body(buf);
386 }
387 Err(e) => return Err(datadog::Error::Io(e)),
388 }
389 }
390 "deflate" => {
391 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
392 let _ = enc.write_all(ser.into_inner().as_slice());
393 match enc.finish() {
394 Ok(buf) => {
395 local_req_builder = local_req_builder.body(buf);
396 }
397 Err(e) => return Err(datadog::Error::Io(e)),
398 }
399 }
400 "zstd1" => {
401 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
402 let _ = enc.write_all(ser.into_inner().as_slice());
403 match enc.finish() {
404 Ok(buf) => {
405 local_req_builder = local_req_builder.body(buf);
406 }
407 Err(e) => return Err(datadog::Error::Io(e)),
408 }
409 }
410 _ => {
411 local_req_builder = local_req_builder.body(ser.into_inner());
412 }
413 }
414 } else {
415 local_req_builder = local_req_builder.body(ser.into_inner());
416 }
417 }
418
419 local_req_builder = local_req_builder.headers(headers);
420 let local_req = local_req_builder.build()?;
421 log::debug!("request content: {:?}", local_req.body());
422 let local_resp = local_client.execute(local_req).await?;
423
424 let local_status = local_resp.status();
425 let local_content = local_resp.text().await?;
426 log::debug!("response content: {}", local_content);
427
428 if !local_status.is_client_error() && !local_status.is_server_error() {
429 match serde_json::from_str::<crate::datadogV2::model::DORAFailureResponse>(
430 &local_content,
431 ) {
432 Ok(e) => {
433 return Ok(datadog::ResponseContent {
434 status: local_status,
435 content: local_content,
436 entity: Some(e),
437 })
438 }
439 Err(e) => return Err(datadog::Error::Serde(e)),
440 };
441 } else {
442 let local_entity: Option<CreateDORAFailureError> =
443 serde_json::from_str(&local_content).ok();
444 let local_error = datadog::ResponseContent {
445 status: local_status,
446 content: local_content,
447 entity: local_entity,
448 };
449 Err(datadog::Error::ResponseError(local_error))
450 }
451 }
452
453 pub async fn create_dora_incident(
461 &self,
462 body: crate::datadogV2::model::DORAFailureRequest,
463 ) -> Result<crate::datadogV2::model::DORAFailureResponse, datadog::Error<CreateDORAIncidentError>>
464 {
465 match self.create_dora_incident_with_http_info(body).await {
466 Ok(response_content) => {
467 if let Some(e) = response_content.entity {
468 Ok(e)
469 } else {
470 Err(datadog::Error::Serde(serde::de::Error::custom(
471 "response content was None",
472 )))
473 }
474 }
475 Err(err) => Err(err),
476 }
477 }
478
479 pub async fn create_dora_incident_with_http_info(
487 &self,
488 body: crate::datadogV2::model::DORAFailureRequest,
489 ) -> Result<
490 datadog::ResponseContent<crate::datadogV2::model::DORAFailureResponse>,
491 datadog::Error<CreateDORAIncidentError>,
492 > {
493 let local_configuration = &self.config;
494 let operation_id = "v2.create_dora_incident";
495
496 let local_client = &self.client;
497
498 let local_uri_str = format!(
499 "{}/api/v2/dora/incident",
500 local_configuration.get_operation_host(operation_id)
501 );
502 let mut local_req_builder =
503 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
504
505 let mut headers = HeaderMap::new();
507 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
508 headers.insert("Accept", HeaderValue::from_static("application/json"));
509
510 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
512 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
513 Err(e) => {
514 log::warn!("Failed to parse user agent header: {e}, falling back to default");
515 headers.insert(
516 reqwest::header::USER_AGENT,
517 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
518 )
519 }
520 };
521
522 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
524 headers.insert(
525 "DD-API-KEY",
526 HeaderValue::from_str(local_key.key.as_str())
527 .expect("failed to parse DD-API-KEY header"),
528 );
529 };
530
531 let output = Vec::new();
533 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
534 if body.serialize(&mut ser).is_ok() {
535 if let Some(content_encoding) = headers.get("Content-Encoding") {
536 match content_encoding.to_str().unwrap_or_default() {
537 "gzip" => {
538 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
539 let _ = enc.write_all(ser.into_inner().as_slice());
540 match enc.finish() {
541 Ok(buf) => {
542 local_req_builder = local_req_builder.body(buf);
543 }
544 Err(e) => return Err(datadog::Error::Io(e)),
545 }
546 }
547 "deflate" => {
548 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
549 let _ = enc.write_all(ser.into_inner().as_slice());
550 match enc.finish() {
551 Ok(buf) => {
552 local_req_builder = local_req_builder.body(buf);
553 }
554 Err(e) => return Err(datadog::Error::Io(e)),
555 }
556 }
557 "zstd1" => {
558 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
559 let _ = enc.write_all(ser.into_inner().as_slice());
560 match enc.finish() {
561 Ok(buf) => {
562 local_req_builder = local_req_builder.body(buf);
563 }
564 Err(e) => return Err(datadog::Error::Io(e)),
565 }
566 }
567 _ => {
568 local_req_builder = local_req_builder.body(ser.into_inner());
569 }
570 }
571 } else {
572 local_req_builder = local_req_builder.body(ser.into_inner());
573 }
574 }
575
576 local_req_builder = local_req_builder.headers(headers);
577 let local_req = local_req_builder.build()?;
578 log::debug!("request content: {:?}", local_req.body());
579 let local_resp = local_client.execute(local_req).await?;
580
581 let local_status = local_resp.status();
582 let local_content = local_resp.text().await?;
583 log::debug!("response content: {}", local_content);
584
585 if !local_status.is_client_error() && !local_status.is_server_error() {
586 match serde_json::from_str::<crate::datadogV2::model::DORAFailureResponse>(
587 &local_content,
588 ) {
589 Ok(e) => {
590 return Ok(datadog::ResponseContent {
591 status: local_status,
592 content: local_content,
593 entity: Some(e),
594 })
595 }
596 Err(e) => return Err(datadog::Error::Serde(e)),
597 };
598 } else {
599 let local_entity: Option<CreateDORAIncidentError> =
600 serde_json::from_str(&local_content).ok();
601 let local_error = datadog::ResponseContent {
602 status: local_status,
603 content: local_content,
604 entity: local_entity,
605 };
606 Err(datadog::Error::ResponseError(local_error))
607 }
608 }
609
610 pub async fn get_dora_deployment(
612 &self,
613 deployment_id: String,
614 ) -> Result<crate::datadogV2::model::DORAFetchResponse, datadog::Error<GetDORADeploymentError>>
615 {
616 match self.get_dora_deployment_with_http_info(deployment_id).await {
617 Ok(response_content) => {
618 if let Some(e) = response_content.entity {
619 Ok(e)
620 } else {
621 Err(datadog::Error::Serde(serde::de::Error::custom(
622 "response content was None",
623 )))
624 }
625 }
626 Err(err) => Err(err),
627 }
628 }
629
630 pub async fn get_dora_deployment_with_http_info(
632 &self,
633 deployment_id: String,
634 ) -> Result<
635 datadog::ResponseContent<crate::datadogV2::model::DORAFetchResponse>,
636 datadog::Error<GetDORADeploymentError>,
637 > {
638 let local_configuration = &self.config;
639 let operation_id = "v2.get_dora_deployment";
640
641 let local_client = &self.client;
642
643 let local_uri_str = format!(
644 "{}/api/v2/dora/deployments/{deployment_id}",
645 local_configuration.get_operation_host(operation_id),
646 deployment_id = datadog::urlencode(deployment_id)
647 );
648 let mut local_req_builder =
649 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
650
651 let mut headers = HeaderMap::new();
653 headers.insert("Accept", HeaderValue::from_static("application/json"));
654
655 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
657 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
658 Err(e) => {
659 log::warn!("Failed to parse user agent header: {e}, falling back to default");
660 headers.insert(
661 reqwest::header::USER_AGENT,
662 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
663 )
664 }
665 };
666
667 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
669 headers.insert(
670 "DD-API-KEY",
671 HeaderValue::from_str(local_key.key.as_str())
672 .expect("failed to parse DD-API-KEY header"),
673 );
674 };
675 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
676 headers.insert(
677 "DD-APPLICATION-KEY",
678 HeaderValue::from_str(local_key.key.as_str())
679 .expect("failed to parse DD-APPLICATION-KEY header"),
680 );
681 };
682
683 local_req_builder = local_req_builder.headers(headers);
684 let local_req = local_req_builder.build()?;
685 log::debug!("request content: {:?}", local_req.body());
686 let local_resp = local_client.execute(local_req).await?;
687
688 let local_status = local_resp.status();
689 let local_content = local_resp.text().await?;
690 log::debug!("response content: {}", local_content);
691
692 if !local_status.is_client_error() && !local_status.is_server_error() {
693 match serde_json::from_str::<crate::datadogV2::model::DORAFetchResponse>(&local_content)
694 {
695 Ok(e) => {
696 return Ok(datadog::ResponseContent {
697 status: local_status,
698 content: local_content,
699 entity: Some(e),
700 })
701 }
702 Err(e) => return Err(datadog::Error::Serde(e)),
703 };
704 } else {
705 let local_entity: Option<GetDORADeploymentError> =
706 serde_json::from_str(&local_content).ok();
707 let local_error = datadog::ResponseContent {
708 status: local_status,
709 content: local_content,
710 entity: local_entity,
711 };
712 Err(datadog::Error::ResponseError(local_error))
713 }
714 }
715
716 pub async fn get_dora_failure(
718 &self,
719 failure_id: String,
720 ) -> Result<crate::datadogV2::model::DORAFetchResponse, datadog::Error<GetDORAFailureError>>
721 {
722 match self.get_dora_failure_with_http_info(failure_id).await {
723 Ok(response_content) => {
724 if let Some(e) = response_content.entity {
725 Ok(e)
726 } else {
727 Err(datadog::Error::Serde(serde::de::Error::custom(
728 "response content was None",
729 )))
730 }
731 }
732 Err(err) => Err(err),
733 }
734 }
735
736 pub async fn get_dora_failure_with_http_info(
738 &self,
739 failure_id: String,
740 ) -> Result<
741 datadog::ResponseContent<crate::datadogV2::model::DORAFetchResponse>,
742 datadog::Error<GetDORAFailureError>,
743 > {
744 let local_configuration = &self.config;
745 let operation_id = "v2.get_dora_failure";
746
747 let local_client = &self.client;
748
749 let local_uri_str = format!(
750 "{}/api/v2/dora/failures/{failure_id}",
751 local_configuration.get_operation_host(operation_id),
752 failure_id = datadog::urlencode(failure_id)
753 );
754 let mut local_req_builder =
755 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
756
757 let mut headers = HeaderMap::new();
759 headers.insert("Accept", HeaderValue::from_static("application/json"));
760
761 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
763 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
764 Err(e) => {
765 log::warn!("Failed to parse user agent header: {e}, falling back to default");
766 headers.insert(
767 reqwest::header::USER_AGENT,
768 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
769 )
770 }
771 };
772
773 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
775 headers.insert(
776 "DD-API-KEY",
777 HeaderValue::from_str(local_key.key.as_str())
778 .expect("failed to parse DD-API-KEY header"),
779 );
780 };
781 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
782 headers.insert(
783 "DD-APPLICATION-KEY",
784 HeaderValue::from_str(local_key.key.as_str())
785 .expect("failed to parse DD-APPLICATION-KEY header"),
786 );
787 };
788
789 local_req_builder = local_req_builder.headers(headers);
790 let local_req = local_req_builder.build()?;
791 log::debug!("request content: {:?}", local_req.body());
792 let local_resp = local_client.execute(local_req).await?;
793
794 let local_status = local_resp.status();
795 let local_content = local_resp.text().await?;
796 log::debug!("response content: {}", local_content);
797
798 if !local_status.is_client_error() && !local_status.is_server_error() {
799 match serde_json::from_str::<crate::datadogV2::model::DORAFetchResponse>(&local_content)
800 {
801 Ok(e) => {
802 return Ok(datadog::ResponseContent {
803 status: local_status,
804 content: local_content,
805 entity: Some(e),
806 })
807 }
808 Err(e) => return Err(datadog::Error::Serde(e)),
809 };
810 } else {
811 let local_entity: Option<GetDORAFailureError> =
812 serde_json::from_str(&local_content).ok();
813 let local_error = datadog::ResponseContent {
814 status: local_status,
815 content: local_content,
816 entity: local_entity,
817 };
818 Err(datadog::Error::ResponseError(local_error))
819 }
820 }
821
822 pub async fn list_dora_deployments(
824 &self,
825 body: crate::datadogV2::model::DORAListDeploymentsRequest,
826 ) -> Result<crate::datadogV2::model::DORAListResponse, datadog::Error<ListDORADeploymentsError>>
827 {
828 match self.list_dora_deployments_with_http_info(body).await {
829 Ok(response_content) => {
830 if let Some(e) = response_content.entity {
831 Ok(e)
832 } else {
833 Err(datadog::Error::Serde(serde::de::Error::custom(
834 "response content was None",
835 )))
836 }
837 }
838 Err(err) => Err(err),
839 }
840 }
841
842 pub async fn list_dora_deployments_with_http_info(
844 &self,
845 body: crate::datadogV2::model::DORAListDeploymentsRequest,
846 ) -> Result<
847 datadog::ResponseContent<crate::datadogV2::model::DORAListResponse>,
848 datadog::Error<ListDORADeploymentsError>,
849 > {
850 let local_configuration = &self.config;
851 let operation_id = "v2.list_dora_deployments";
852
853 let local_client = &self.client;
854
855 let local_uri_str = format!(
856 "{}/api/v2/dora/deployments",
857 local_configuration.get_operation_host(operation_id)
858 );
859 let mut local_req_builder =
860 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
861
862 let mut headers = HeaderMap::new();
864 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
865 headers.insert("Accept", HeaderValue::from_static("application/json"));
866
867 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
869 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
870 Err(e) => {
871 log::warn!("Failed to parse user agent header: {e}, falling back to default");
872 headers.insert(
873 reqwest::header::USER_AGENT,
874 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
875 )
876 }
877 };
878
879 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
881 headers.insert(
882 "DD-API-KEY",
883 HeaderValue::from_str(local_key.key.as_str())
884 .expect("failed to parse DD-API-KEY header"),
885 );
886 };
887 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
888 headers.insert(
889 "DD-APPLICATION-KEY",
890 HeaderValue::from_str(local_key.key.as_str())
891 .expect("failed to parse DD-APPLICATION-KEY header"),
892 );
893 };
894
895 let output = Vec::new();
897 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
898 if body.serialize(&mut ser).is_ok() {
899 if let Some(content_encoding) = headers.get("Content-Encoding") {
900 match content_encoding.to_str().unwrap_or_default() {
901 "gzip" => {
902 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
903 let _ = enc.write_all(ser.into_inner().as_slice());
904 match enc.finish() {
905 Ok(buf) => {
906 local_req_builder = local_req_builder.body(buf);
907 }
908 Err(e) => return Err(datadog::Error::Io(e)),
909 }
910 }
911 "deflate" => {
912 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
913 let _ = enc.write_all(ser.into_inner().as_slice());
914 match enc.finish() {
915 Ok(buf) => {
916 local_req_builder = local_req_builder.body(buf);
917 }
918 Err(e) => return Err(datadog::Error::Io(e)),
919 }
920 }
921 "zstd1" => {
922 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
923 let _ = enc.write_all(ser.into_inner().as_slice());
924 match enc.finish() {
925 Ok(buf) => {
926 local_req_builder = local_req_builder.body(buf);
927 }
928 Err(e) => return Err(datadog::Error::Io(e)),
929 }
930 }
931 _ => {
932 local_req_builder = local_req_builder.body(ser.into_inner());
933 }
934 }
935 } else {
936 local_req_builder = local_req_builder.body(ser.into_inner());
937 }
938 }
939
940 local_req_builder = local_req_builder.headers(headers);
941 let local_req = local_req_builder.build()?;
942 log::debug!("request content: {:?}", local_req.body());
943 let local_resp = local_client.execute(local_req).await?;
944
945 let local_status = local_resp.status();
946 let local_content = local_resp.text().await?;
947 log::debug!("response content: {}", local_content);
948
949 if !local_status.is_client_error() && !local_status.is_server_error() {
950 match serde_json::from_str::<crate::datadogV2::model::DORAListResponse>(&local_content)
951 {
952 Ok(e) => {
953 return Ok(datadog::ResponseContent {
954 status: local_status,
955 content: local_content,
956 entity: Some(e),
957 })
958 }
959 Err(e) => return Err(datadog::Error::Serde(e)),
960 };
961 } else {
962 let local_entity: Option<ListDORADeploymentsError> =
963 serde_json::from_str(&local_content).ok();
964 let local_error = datadog::ResponseContent {
965 status: local_status,
966 content: local_content,
967 entity: local_entity,
968 };
969 Err(datadog::Error::ResponseError(local_error))
970 }
971 }
972
973 pub async fn list_dora_failures(
975 &self,
976 body: crate::datadogV2::model::DORAListFailuresRequest,
977 ) -> Result<crate::datadogV2::model::DORAListResponse, datadog::Error<ListDORAFailuresError>>
978 {
979 match self.list_dora_failures_with_http_info(body).await {
980 Ok(response_content) => {
981 if let Some(e) = response_content.entity {
982 Ok(e)
983 } else {
984 Err(datadog::Error::Serde(serde::de::Error::custom(
985 "response content was None",
986 )))
987 }
988 }
989 Err(err) => Err(err),
990 }
991 }
992
993 pub async fn list_dora_failures_with_http_info(
995 &self,
996 body: crate::datadogV2::model::DORAListFailuresRequest,
997 ) -> Result<
998 datadog::ResponseContent<crate::datadogV2::model::DORAListResponse>,
999 datadog::Error<ListDORAFailuresError>,
1000 > {
1001 let local_configuration = &self.config;
1002 let operation_id = "v2.list_dora_failures";
1003
1004 let local_client = &self.client;
1005
1006 let local_uri_str = format!(
1007 "{}/api/v2/dora/failures",
1008 local_configuration.get_operation_host(operation_id)
1009 );
1010 let mut local_req_builder =
1011 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1012
1013 let mut headers = HeaderMap::new();
1015 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1016 headers.insert("Accept", HeaderValue::from_static("application/json"));
1017
1018 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1020 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1021 Err(e) => {
1022 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1023 headers.insert(
1024 reqwest::header::USER_AGENT,
1025 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1026 )
1027 }
1028 };
1029
1030 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1032 headers.insert(
1033 "DD-API-KEY",
1034 HeaderValue::from_str(local_key.key.as_str())
1035 .expect("failed to parse DD-API-KEY header"),
1036 );
1037 };
1038 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1039 headers.insert(
1040 "DD-APPLICATION-KEY",
1041 HeaderValue::from_str(local_key.key.as_str())
1042 .expect("failed to parse DD-APPLICATION-KEY header"),
1043 );
1044 };
1045
1046 let output = Vec::new();
1048 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1049 if body.serialize(&mut ser).is_ok() {
1050 if let Some(content_encoding) = headers.get("Content-Encoding") {
1051 match content_encoding.to_str().unwrap_or_default() {
1052 "gzip" => {
1053 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1054 let _ = enc.write_all(ser.into_inner().as_slice());
1055 match enc.finish() {
1056 Ok(buf) => {
1057 local_req_builder = local_req_builder.body(buf);
1058 }
1059 Err(e) => return Err(datadog::Error::Io(e)),
1060 }
1061 }
1062 "deflate" => {
1063 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1064 let _ = enc.write_all(ser.into_inner().as_slice());
1065 match enc.finish() {
1066 Ok(buf) => {
1067 local_req_builder = local_req_builder.body(buf);
1068 }
1069 Err(e) => return Err(datadog::Error::Io(e)),
1070 }
1071 }
1072 "zstd1" => {
1073 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1074 let _ = enc.write_all(ser.into_inner().as_slice());
1075 match enc.finish() {
1076 Ok(buf) => {
1077 local_req_builder = local_req_builder.body(buf);
1078 }
1079 Err(e) => return Err(datadog::Error::Io(e)),
1080 }
1081 }
1082 _ => {
1083 local_req_builder = local_req_builder.body(ser.into_inner());
1084 }
1085 }
1086 } else {
1087 local_req_builder = local_req_builder.body(ser.into_inner());
1088 }
1089 }
1090
1091 local_req_builder = local_req_builder.headers(headers);
1092 let local_req = local_req_builder.build()?;
1093 log::debug!("request content: {:?}", local_req.body());
1094 let local_resp = local_client.execute(local_req).await?;
1095
1096 let local_status = local_resp.status();
1097 let local_content = local_resp.text().await?;
1098 log::debug!("response content: {}", local_content);
1099
1100 if !local_status.is_client_error() && !local_status.is_server_error() {
1101 match serde_json::from_str::<crate::datadogV2::model::DORAListResponse>(&local_content)
1102 {
1103 Ok(e) => {
1104 return Ok(datadog::ResponseContent {
1105 status: local_status,
1106 content: local_content,
1107 entity: Some(e),
1108 })
1109 }
1110 Err(e) => return Err(datadog::Error::Serde(e)),
1111 };
1112 } else {
1113 let local_entity: Option<ListDORAFailuresError> =
1114 serde_json::from_str(&local_content).ok();
1115 let local_error = datadog::ResponseContent {
1116 status: local_status,
1117 content: local_content,
1118 entity: local_entity,
1119 };
1120 Err(datadog::Error::ResponseError(local_error))
1121 }
1122 }
1123}