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 DeleteDORADeploymentError {
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 DeleteDORAFailureError {
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 GetDORADeploymentError {
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 GetDORAFailureError {
71 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
72 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum ListDORADeploymentsError {
80 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
81 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ListDORAFailuresError {
89 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
90 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
91 UnknownValue(serde_json::Value),
92}
93
94#[derive(Debug, Clone)]
98pub struct DORAMetricsAPI {
99 config: datadog::Configuration,
100 client: reqwest_middleware::ClientWithMiddleware,
101}
102
103impl Default for DORAMetricsAPI {
104 fn default() -> Self {
105 Self::with_config(datadog::Configuration::default())
106 }
107}
108
109impl DORAMetricsAPI {
110 pub fn new() -> Self {
111 Self::default()
112 }
113 pub fn with_config(config: datadog::Configuration) -> Self {
114 let mut reqwest_client_builder = reqwest::Client::builder();
115
116 if let Some(proxy_url) = &config.proxy_url {
117 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
118 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
119 }
120
121 let mut middleware_client_builder =
122 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
123
124 if config.enable_retry {
125 struct RetryableStatus;
126 impl reqwest_retry::RetryableStrategy for RetryableStatus {
127 fn handle(
128 &self,
129 res: &Result<reqwest::Response, reqwest_middleware::Error>,
130 ) -> Option<reqwest_retry::Retryable> {
131 match res {
132 Ok(success) => reqwest_retry::default_on_request_success(success),
133 Err(_) => None,
134 }
135 }
136 }
137 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
138 .build_with_max_retries(config.max_retries);
139
140 let retry_middleware =
141 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
142 backoff_policy,
143 RetryableStatus,
144 );
145
146 middleware_client_builder = middleware_client_builder.with(retry_middleware);
147 }
148
149 let client = middleware_client_builder.build();
150
151 Self { config, client }
152 }
153
154 pub fn with_client_and_config(
155 config: datadog::Configuration,
156 client: reqwest_middleware::ClientWithMiddleware,
157 ) -> Self {
158 Self { config, client }
159 }
160
161 pub async fn create_dora_deployment(
168 &self,
169 body: crate::datadogV2::model::DORADeploymentRequest,
170 ) -> Result<
171 crate::datadogV2::model::DORADeploymentResponse,
172 datadog::Error<CreateDORADeploymentError>,
173 > {
174 match self.create_dora_deployment_with_http_info(body).await {
175 Ok(response_content) => {
176 if let Some(e) = response_content.entity {
177 Ok(e)
178 } else {
179 Err(datadog::Error::Serde(serde::de::Error::custom(
180 "response content was None",
181 )))
182 }
183 }
184 Err(err) => Err(err),
185 }
186 }
187
188 pub async fn create_dora_deployment_with_http_info(
195 &self,
196 body: crate::datadogV2::model::DORADeploymentRequest,
197 ) -> Result<
198 datadog::ResponseContent<crate::datadogV2::model::DORADeploymentResponse>,
199 datadog::Error<CreateDORADeploymentError>,
200 > {
201 let local_configuration = &self.config;
202 let operation_id = "v2.create_dora_deployment";
203
204 let local_client = &self.client;
205
206 let local_uri_str = format!(
207 "{}/api/v2/dora/deployment",
208 local_configuration.get_operation_host(operation_id)
209 );
210 let mut local_req_builder =
211 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
212
213 let mut headers = HeaderMap::new();
215 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
216 headers.insert("Accept", HeaderValue::from_static("application/json"));
217
218 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
220 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
221 Err(e) => {
222 log::warn!("Failed to parse user agent header: {e}, falling back to default");
223 headers.insert(
224 reqwest::header::USER_AGENT,
225 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
226 )
227 }
228 };
229
230 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
232 headers.insert(
233 "DD-API-KEY",
234 HeaderValue::from_str(local_key.key.as_str())
235 .expect("failed to parse DD-API-KEY header"),
236 );
237 };
238
239 let output = Vec::new();
241 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
242 if body.serialize(&mut ser).is_ok() {
243 if let Some(content_encoding) = headers.get("Content-Encoding") {
244 match content_encoding.to_str().unwrap_or_default() {
245 "gzip" => {
246 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
247 let _ = enc.write_all(ser.into_inner().as_slice());
248 match enc.finish() {
249 Ok(buf) => {
250 local_req_builder = local_req_builder.body(buf);
251 }
252 Err(e) => return Err(datadog::Error::Io(e)),
253 }
254 }
255 "deflate" => {
256 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
257 let _ = enc.write_all(ser.into_inner().as_slice());
258 match enc.finish() {
259 Ok(buf) => {
260 local_req_builder = local_req_builder.body(buf);
261 }
262 Err(e) => return Err(datadog::Error::Io(e)),
263 }
264 }
265 "zstd1" => {
266 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
267 let _ = enc.write_all(ser.into_inner().as_slice());
268 match enc.finish() {
269 Ok(buf) => {
270 local_req_builder = local_req_builder.body(buf);
271 }
272 Err(e) => return Err(datadog::Error::Io(e)),
273 }
274 }
275 _ => {
276 local_req_builder = local_req_builder.body(ser.into_inner());
277 }
278 }
279 } else {
280 local_req_builder = local_req_builder.body(ser.into_inner());
281 }
282 }
283
284 local_req_builder = local_req_builder.headers(headers);
285 let local_req = local_req_builder.build()?;
286 log::debug!("request content: {:?}", local_req.body());
287 let local_resp = local_client.execute(local_req).await?;
288
289 let local_status = local_resp.status();
290 let local_content = local_resp.text().await?;
291 log::debug!("response content: {}", local_content);
292
293 if !local_status.is_client_error() && !local_status.is_server_error() {
294 match serde_json::from_str::<crate::datadogV2::model::DORADeploymentResponse>(
295 &local_content,
296 ) {
297 Ok(e) => {
298 return Ok(datadog::ResponseContent {
299 status: local_status,
300 content: local_content,
301 entity: Some(e),
302 })
303 }
304 Err(e) => return Err(datadog::Error::Serde(e)),
305 };
306 } else {
307 let local_entity: Option<CreateDORADeploymentError> =
308 serde_json::from_str(&local_content).ok();
309 let local_error = datadog::ResponseContent {
310 status: local_status,
311 content: local_content,
312 entity: local_entity,
313 };
314 Err(datadog::Error::ResponseError(local_error))
315 }
316 }
317
318 pub async fn create_dora_failure(
324 &self,
325 body: crate::datadogV2::model::DORAFailureRequest,
326 ) -> Result<crate::datadogV2::model::DORAFailureResponse, datadog::Error<CreateDORAFailureError>>
327 {
328 match self.create_dora_failure_with_http_info(body).await {
329 Ok(response_content) => {
330 if let Some(e) = response_content.entity {
331 Ok(e)
332 } else {
333 Err(datadog::Error::Serde(serde::de::Error::custom(
334 "response content was None",
335 )))
336 }
337 }
338 Err(err) => Err(err),
339 }
340 }
341
342 pub async fn create_dora_failure_with_http_info(
348 &self,
349 body: crate::datadogV2::model::DORAFailureRequest,
350 ) -> Result<
351 datadog::ResponseContent<crate::datadogV2::model::DORAFailureResponse>,
352 datadog::Error<CreateDORAFailureError>,
353 > {
354 let local_configuration = &self.config;
355 let operation_id = "v2.create_dora_failure";
356
357 let local_client = &self.client;
358
359 let local_uri_str = format!(
360 "{}/api/v2/dora/failure",
361 local_configuration.get_operation_host(operation_id)
362 );
363 let mut local_req_builder =
364 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
365
366 let mut headers = HeaderMap::new();
368 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
369 headers.insert("Accept", HeaderValue::from_static("application/json"));
370
371 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
373 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
374 Err(e) => {
375 log::warn!("Failed to parse user agent header: {e}, falling back to default");
376 headers.insert(
377 reqwest::header::USER_AGENT,
378 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
379 )
380 }
381 };
382
383 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
385 headers.insert(
386 "DD-API-KEY",
387 HeaderValue::from_str(local_key.key.as_str())
388 .expect("failed to parse DD-API-KEY header"),
389 );
390 };
391
392 let output = Vec::new();
394 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
395 if body.serialize(&mut ser).is_ok() {
396 if let Some(content_encoding) = headers.get("Content-Encoding") {
397 match content_encoding.to_str().unwrap_or_default() {
398 "gzip" => {
399 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
400 let _ = enc.write_all(ser.into_inner().as_slice());
401 match enc.finish() {
402 Ok(buf) => {
403 local_req_builder = local_req_builder.body(buf);
404 }
405 Err(e) => return Err(datadog::Error::Io(e)),
406 }
407 }
408 "deflate" => {
409 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
410 let _ = enc.write_all(ser.into_inner().as_slice());
411 match enc.finish() {
412 Ok(buf) => {
413 local_req_builder = local_req_builder.body(buf);
414 }
415 Err(e) => return Err(datadog::Error::Io(e)),
416 }
417 }
418 "zstd1" => {
419 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
420 let _ = enc.write_all(ser.into_inner().as_slice());
421 match enc.finish() {
422 Ok(buf) => {
423 local_req_builder = local_req_builder.body(buf);
424 }
425 Err(e) => return Err(datadog::Error::Io(e)),
426 }
427 }
428 _ => {
429 local_req_builder = local_req_builder.body(ser.into_inner());
430 }
431 }
432 } else {
433 local_req_builder = local_req_builder.body(ser.into_inner());
434 }
435 }
436
437 local_req_builder = local_req_builder.headers(headers);
438 let local_req = local_req_builder.build()?;
439 log::debug!("request content: {:?}", local_req.body());
440 let local_resp = local_client.execute(local_req).await?;
441
442 let local_status = local_resp.status();
443 let local_content = local_resp.text().await?;
444 log::debug!("response content: {}", local_content);
445
446 if !local_status.is_client_error() && !local_status.is_server_error() {
447 match serde_json::from_str::<crate::datadogV2::model::DORAFailureResponse>(
448 &local_content,
449 ) {
450 Ok(e) => {
451 return Ok(datadog::ResponseContent {
452 status: local_status,
453 content: local_content,
454 entity: Some(e),
455 })
456 }
457 Err(e) => return Err(datadog::Error::Serde(e)),
458 };
459 } else {
460 let local_entity: Option<CreateDORAFailureError> =
461 serde_json::from_str(&local_content).ok();
462 let local_error = datadog::ResponseContent {
463 status: local_status,
464 content: local_content,
465 entity: local_entity,
466 };
467 Err(datadog::Error::ResponseError(local_error))
468 }
469 }
470
471 pub async fn create_dora_incident(
479 &self,
480 body: crate::datadogV2::model::DORAFailureRequest,
481 ) -> Result<crate::datadogV2::model::DORAFailureResponse, datadog::Error<CreateDORAIncidentError>>
482 {
483 match self.create_dora_incident_with_http_info(body).await {
484 Ok(response_content) => {
485 if let Some(e) = response_content.entity {
486 Ok(e)
487 } else {
488 Err(datadog::Error::Serde(serde::de::Error::custom(
489 "response content was None",
490 )))
491 }
492 }
493 Err(err) => Err(err),
494 }
495 }
496
497 pub async fn create_dora_incident_with_http_info(
505 &self,
506 body: crate::datadogV2::model::DORAFailureRequest,
507 ) -> Result<
508 datadog::ResponseContent<crate::datadogV2::model::DORAFailureResponse>,
509 datadog::Error<CreateDORAIncidentError>,
510 > {
511 let local_configuration = &self.config;
512 let operation_id = "v2.create_dora_incident";
513
514 let local_client = &self.client;
515
516 let local_uri_str = format!(
517 "{}/api/v2/dora/incident",
518 local_configuration.get_operation_host(operation_id)
519 );
520 let mut local_req_builder =
521 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
522
523 let mut headers = HeaderMap::new();
525 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
526 headers.insert("Accept", HeaderValue::from_static("application/json"));
527
528 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
530 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
531 Err(e) => {
532 log::warn!("Failed to parse user agent header: {e}, falling back to default");
533 headers.insert(
534 reqwest::header::USER_AGENT,
535 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
536 )
537 }
538 };
539
540 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
542 headers.insert(
543 "DD-API-KEY",
544 HeaderValue::from_str(local_key.key.as_str())
545 .expect("failed to parse DD-API-KEY header"),
546 );
547 };
548
549 let output = Vec::new();
551 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
552 if body.serialize(&mut ser).is_ok() {
553 if let Some(content_encoding) = headers.get("Content-Encoding") {
554 match content_encoding.to_str().unwrap_or_default() {
555 "gzip" => {
556 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
557 let _ = enc.write_all(ser.into_inner().as_slice());
558 match enc.finish() {
559 Ok(buf) => {
560 local_req_builder = local_req_builder.body(buf);
561 }
562 Err(e) => return Err(datadog::Error::Io(e)),
563 }
564 }
565 "deflate" => {
566 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
567 let _ = enc.write_all(ser.into_inner().as_slice());
568 match enc.finish() {
569 Ok(buf) => {
570 local_req_builder = local_req_builder.body(buf);
571 }
572 Err(e) => return Err(datadog::Error::Io(e)),
573 }
574 }
575 "zstd1" => {
576 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
577 let _ = enc.write_all(ser.into_inner().as_slice());
578 match enc.finish() {
579 Ok(buf) => {
580 local_req_builder = local_req_builder.body(buf);
581 }
582 Err(e) => return Err(datadog::Error::Io(e)),
583 }
584 }
585 _ => {
586 local_req_builder = local_req_builder.body(ser.into_inner());
587 }
588 }
589 } else {
590 local_req_builder = local_req_builder.body(ser.into_inner());
591 }
592 }
593
594 local_req_builder = local_req_builder.headers(headers);
595 let local_req = local_req_builder.build()?;
596 log::debug!("request content: {:?}", local_req.body());
597 let local_resp = local_client.execute(local_req).await?;
598
599 let local_status = local_resp.status();
600 let local_content = local_resp.text().await?;
601 log::debug!("response content: {}", local_content);
602
603 if !local_status.is_client_error() && !local_status.is_server_error() {
604 match serde_json::from_str::<crate::datadogV2::model::DORAFailureResponse>(
605 &local_content,
606 ) {
607 Ok(e) => {
608 return Ok(datadog::ResponseContent {
609 status: local_status,
610 content: local_content,
611 entity: Some(e),
612 })
613 }
614 Err(e) => return Err(datadog::Error::Serde(e)),
615 };
616 } else {
617 let local_entity: Option<CreateDORAIncidentError> =
618 serde_json::from_str(&local_content).ok();
619 let local_error = datadog::ResponseContent {
620 status: local_status,
621 content: local_content,
622 entity: local_entity,
623 };
624 Err(datadog::Error::ResponseError(local_error))
625 }
626 }
627
628 pub async fn delete_dora_deployment(
630 &self,
631 deployment_id: String,
632 ) -> Result<(), datadog::Error<DeleteDORADeploymentError>> {
633 match self
634 .delete_dora_deployment_with_http_info(deployment_id)
635 .await
636 {
637 Ok(_) => Ok(()),
638 Err(err) => Err(err),
639 }
640 }
641
642 pub async fn delete_dora_deployment_with_http_info(
644 &self,
645 deployment_id: String,
646 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteDORADeploymentError>> {
647 let local_configuration = &self.config;
648 let operation_id = "v2.delete_dora_deployment";
649
650 let local_client = &self.client;
651
652 let local_uri_str = format!(
653 "{}/api/v2/dora/deployment/{deployment_id}",
654 local_configuration.get_operation_host(operation_id),
655 deployment_id = datadog::urlencode(deployment_id)
656 );
657 let mut local_req_builder =
658 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
659
660 let mut headers = HeaderMap::new();
662 headers.insert("Accept", HeaderValue::from_static("*/*"));
663
664 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
666 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
667 Err(e) => {
668 log::warn!("Failed to parse user agent header: {e}, falling back to default");
669 headers.insert(
670 reqwest::header::USER_AGENT,
671 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
672 )
673 }
674 };
675
676 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
678 headers.insert(
679 "DD-API-KEY",
680 HeaderValue::from_str(local_key.key.as_str())
681 .expect("failed to parse DD-API-KEY header"),
682 );
683 };
684 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
685 headers.insert(
686 "DD-APPLICATION-KEY",
687 HeaderValue::from_str(local_key.key.as_str())
688 .expect("failed to parse DD-APPLICATION-KEY header"),
689 );
690 };
691
692 local_req_builder = local_req_builder.headers(headers);
693 let local_req = local_req_builder.build()?;
694 log::debug!("request content: {:?}", local_req.body());
695 let local_resp = local_client.execute(local_req).await?;
696
697 let local_status = local_resp.status();
698 let local_content = local_resp.text().await?;
699 log::debug!("response content: {}", local_content);
700
701 if !local_status.is_client_error() && !local_status.is_server_error() {
702 Ok(datadog::ResponseContent {
703 status: local_status,
704 content: local_content,
705 entity: None,
706 })
707 } else {
708 let local_entity: Option<DeleteDORADeploymentError> =
709 serde_json::from_str(&local_content).ok();
710 let local_error = datadog::ResponseContent {
711 status: local_status,
712 content: local_content,
713 entity: local_entity,
714 };
715 Err(datadog::Error::ResponseError(local_error))
716 }
717 }
718
719 pub async fn delete_dora_failure(
721 &self,
722 failure_id: String,
723 ) -> Result<(), datadog::Error<DeleteDORAFailureError>> {
724 match self.delete_dora_failure_with_http_info(failure_id).await {
725 Ok(_) => Ok(()),
726 Err(err) => Err(err),
727 }
728 }
729
730 pub async fn delete_dora_failure_with_http_info(
732 &self,
733 failure_id: String,
734 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteDORAFailureError>> {
735 let local_configuration = &self.config;
736 let operation_id = "v2.delete_dora_failure";
737
738 let local_client = &self.client;
739
740 let local_uri_str = format!(
741 "{}/api/v2/dora/failure/{failure_id}",
742 local_configuration.get_operation_host(operation_id),
743 failure_id = datadog::urlencode(failure_id)
744 );
745 let mut local_req_builder =
746 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
747
748 let mut headers = HeaderMap::new();
750 headers.insert("Accept", HeaderValue::from_static("*/*"));
751
752 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
754 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
755 Err(e) => {
756 log::warn!("Failed to parse user agent header: {e}, falling back to default");
757 headers.insert(
758 reqwest::header::USER_AGENT,
759 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
760 )
761 }
762 };
763
764 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
766 headers.insert(
767 "DD-API-KEY",
768 HeaderValue::from_str(local_key.key.as_str())
769 .expect("failed to parse DD-API-KEY header"),
770 );
771 };
772 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
773 headers.insert(
774 "DD-APPLICATION-KEY",
775 HeaderValue::from_str(local_key.key.as_str())
776 .expect("failed to parse DD-APPLICATION-KEY header"),
777 );
778 };
779
780 local_req_builder = local_req_builder.headers(headers);
781 let local_req = local_req_builder.build()?;
782 log::debug!("request content: {:?}", local_req.body());
783 let local_resp = local_client.execute(local_req).await?;
784
785 let local_status = local_resp.status();
786 let local_content = local_resp.text().await?;
787 log::debug!("response content: {}", local_content);
788
789 if !local_status.is_client_error() && !local_status.is_server_error() {
790 Ok(datadog::ResponseContent {
791 status: local_status,
792 content: local_content,
793 entity: None,
794 })
795 } else {
796 let local_entity: Option<DeleteDORAFailureError> =
797 serde_json::from_str(&local_content).ok();
798 let local_error = datadog::ResponseContent {
799 status: local_status,
800 content: local_content,
801 entity: local_entity,
802 };
803 Err(datadog::Error::ResponseError(local_error))
804 }
805 }
806
807 pub async fn get_dora_deployment(
809 &self,
810 deployment_id: String,
811 ) -> Result<crate::datadogV2::model::DORAFetchResponse, datadog::Error<GetDORADeploymentError>>
812 {
813 match self.get_dora_deployment_with_http_info(deployment_id).await {
814 Ok(response_content) => {
815 if let Some(e) = response_content.entity {
816 Ok(e)
817 } else {
818 Err(datadog::Error::Serde(serde::de::Error::custom(
819 "response content was None",
820 )))
821 }
822 }
823 Err(err) => Err(err),
824 }
825 }
826
827 pub async fn get_dora_deployment_with_http_info(
829 &self,
830 deployment_id: String,
831 ) -> Result<
832 datadog::ResponseContent<crate::datadogV2::model::DORAFetchResponse>,
833 datadog::Error<GetDORADeploymentError>,
834 > {
835 let local_configuration = &self.config;
836 let operation_id = "v2.get_dora_deployment";
837
838 let local_client = &self.client;
839
840 let local_uri_str = format!(
841 "{}/api/v2/dora/deployments/{deployment_id}",
842 local_configuration.get_operation_host(operation_id),
843 deployment_id = datadog::urlencode(deployment_id)
844 );
845 let mut local_req_builder =
846 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
847
848 let mut headers = HeaderMap::new();
850 headers.insert("Accept", HeaderValue::from_static("application/json"));
851
852 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
854 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
855 Err(e) => {
856 log::warn!("Failed to parse user agent header: {e}, falling back to default");
857 headers.insert(
858 reqwest::header::USER_AGENT,
859 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
860 )
861 }
862 };
863
864 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
866 headers.insert(
867 "DD-API-KEY",
868 HeaderValue::from_str(local_key.key.as_str())
869 .expect("failed to parse DD-API-KEY header"),
870 );
871 };
872 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
873 headers.insert(
874 "DD-APPLICATION-KEY",
875 HeaderValue::from_str(local_key.key.as_str())
876 .expect("failed to parse DD-APPLICATION-KEY header"),
877 );
878 };
879
880 local_req_builder = local_req_builder.headers(headers);
881 let local_req = local_req_builder.build()?;
882 log::debug!("request content: {:?}", local_req.body());
883 let local_resp = local_client.execute(local_req).await?;
884
885 let local_status = local_resp.status();
886 let local_content = local_resp.text().await?;
887 log::debug!("response content: {}", local_content);
888
889 if !local_status.is_client_error() && !local_status.is_server_error() {
890 match serde_json::from_str::<crate::datadogV2::model::DORAFetchResponse>(&local_content)
891 {
892 Ok(e) => {
893 return Ok(datadog::ResponseContent {
894 status: local_status,
895 content: local_content,
896 entity: Some(e),
897 })
898 }
899 Err(e) => return Err(datadog::Error::Serde(e)),
900 };
901 } else {
902 let local_entity: Option<GetDORADeploymentError> =
903 serde_json::from_str(&local_content).ok();
904 let local_error = datadog::ResponseContent {
905 status: local_status,
906 content: local_content,
907 entity: local_entity,
908 };
909 Err(datadog::Error::ResponseError(local_error))
910 }
911 }
912
913 pub async fn get_dora_failure(
915 &self,
916 failure_id: String,
917 ) -> Result<crate::datadogV2::model::DORAFetchResponse, datadog::Error<GetDORAFailureError>>
918 {
919 match self.get_dora_failure_with_http_info(failure_id).await {
920 Ok(response_content) => {
921 if let Some(e) = response_content.entity {
922 Ok(e)
923 } else {
924 Err(datadog::Error::Serde(serde::de::Error::custom(
925 "response content was None",
926 )))
927 }
928 }
929 Err(err) => Err(err),
930 }
931 }
932
933 pub async fn get_dora_failure_with_http_info(
935 &self,
936 failure_id: String,
937 ) -> Result<
938 datadog::ResponseContent<crate::datadogV2::model::DORAFetchResponse>,
939 datadog::Error<GetDORAFailureError>,
940 > {
941 let local_configuration = &self.config;
942 let operation_id = "v2.get_dora_failure";
943
944 let local_client = &self.client;
945
946 let local_uri_str = format!(
947 "{}/api/v2/dora/failures/{failure_id}",
948 local_configuration.get_operation_host(operation_id),
949 failure_id = datadog::urlencode(failure_id)
950 );
951 let mut local_req_builder =
952 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
953
954 let mut headers = HeaderMap::new();
956 headers.insert("Accept", HeaderValue::from_static("application/json"));
957
958 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
960 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
961 Err(e) => {
962 log::warn!("Failed to parse user agent header: {e}, falling back to default");
963 headers.insert(
964 reqwest::header::USER_AGENT,
965 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
966 )
967 }
968 };
969
970 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
972 headers.insert(
973 "DD-API-KEY",
974 HeaderValue::from_str(local_key.key.as_str())
975 .expect("failed to parse DD-API-KEY header"),
976 );
977 };
978 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
979 headers.insert(
980 "DD-APPLICATION-KEY",
981 HeaderValue::from_str(local_key.key.as_str())
982 .expect("failed to parse DD-APPLICATION-KEY header"),
983 );
984 };
985
986 local_req_builder = local_req_builder.headers(headers);
987 let local_req = local_req_builder.build()?;
988 log::debug!("request content: {:?}", local_req.body());
989 let local_resp = local_client.execute(local_req).await?;
990
991 let local_status = local_resp.status();
992 let local_content = local_resp.text().await?;
993 log::debug!("response content: {}", local_content);
994
995 if !local_status.is_client_error() && !local_status.is_server_error() {
996 match serde_json::from_str::<crate::datadogV2::model::DORAFetchResponse>(&local_content)
997 {
998 Ok(e) => {
999 return Ok(datadog::ResponseContent {
1000 status: local_status,
1001 content: local_content,
1002 entity: Some(e),
1003 })
1004 }
1005 Err(e) => return Err(datadog::Error::Serde(e)),
1006 };
1007 } else {
1008 let local_entity: Option<GetDORAFailureError> =
1009 serde_json::from_str(&local_content).ok();
1010 let local_error = datadog::ResponseContent {
1011 status: local_status,
1012 content: local_content,
1013 entity: local_entity,
1014 };
1015 Err(datadog::Error::ResponseError(local_error))
1016 }
1017 }
1018
1019 pub async fn list_dora_deployments(
1021 &self,
1022 body: crate::datadogV2::model::DORAListDeploymentsRequest,
1023 ) -> Result<crate::datadogV2::model::DORAListResponse, datadog::Error<ListDORADeploymentsError>>
1024 {
1025 match self.list_dora_deployments_with_http_info(body).await {
1026 Ok(response_content) => {
1027 if let Some(e) = response_content.entity {
1028 Ok(e)
1029 } else {
1030 Err(datadog::Error::Serde(serde::de::Error::custom(
1031 "response content was None",
1032 )))
1033 }
1034 }
1035 Err(err) => Err(err),
1036 }
1037 }
1038
1039 pub async fn list_dora_deployments_with_http_info(
1041 &self,
1042 body: crate::datadogV2::model::DORAListDeploymentsRequest,
1043 ) -> Result<
1044 datadog::ResponseContent<crate::datadogV2::model::DORAListResponse>,
1045 datadog::Error<ListDORADeploymentsError>,
1046 > {
1047 let local_configuration = &self.config;
1048 let operation_id = "v2.list_dora_deployments";
1049
1050 let local_client = &self.client;
1051
1052 let local_uri_str = format!(
1053 "{}/api/v2/dora/deployments",
1054 local_configuration.get_operation_host(operation_id)
1055 );
1056 let mut local_req_builder =
1057 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1058
1059 let mut headers = HeaderMap::new();
1061 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1062 headers.insert("Accept", HeaderValue::from_static("application/json"));
1063
1064 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1066 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1067 Err(e) => {
1068 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1069 headers.insert(
1070 reqwest::header::USER_AGENT,
1071 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1072 )
1073 }
1074 };
1075
1076 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1078 headers.insert(
1079 "DD-API-KEY",
1080 HeaderValue::from_str(local_key.key.as_str())
1081 .expect("failed to parse DD-API-KEY header"),
1082 );
1083 };
1084 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1085 headers.insert(
1086 "DD-APPLICATION-KEY",
1087 HeaderValue::from_str(local_key.key.as_str())
1088 .expect("failed to parse DD-APPLICATION-KEY header"),
1089 );
1090 };
1091
1092 let output = Vec::new();
1094 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1095 if body.serialize(&mut ser).is_ok() {
1096 if let Some(content_encoding) = headers.get("Content-Encoding") {
1097 match content_encoding.to_str().unwrap_or_default() {
1098 "gzip" => {
1099 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1100 let _ = enc.write_all(ser.into_inner().as_slice());
1101 match enc.finish() {
1102 Ok(buf) => {
1103 local_req_builder = local_req_builder.body(buf);
1104 }
1105 Err(e) => return Err(datadog::Error::Io(e)),
1106 }
1107 }
1108 "deflate" => {
1109 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1110 let _ = enc.write_all(ser.into_inner().as_slice());
1111 match enc.finish() {
1112 Ok(buf) => {
1113 local_req_builder = local_req_builder.body(buf);
1114 }
1115 Err(e) => return Err(datadog::Error::Io(e)),
1116 }
1117 }
1118 "zstd1" => {
1119 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1120 let _ = enc.write_all(ser.into_inner().as_slice());
1121 match enc.finish() {
1122 Ok(buf) => {
1123 local_req_builder = local_req_builder.body(buf);
1124 }
1125 Err(e) => return Err(datadog::Error::Io(e)),
1126 }
1127 }
1128 _ => {
1129 local_req_builder = local_req_builder.body(ser.into_inner());
1130 }
1131 }
1132 } else {
1133 local_req_builder = local_req_builder.body(ser.into_inner());
1134 }
1135 }
1136
1137 local_req_builder = local_req_builder.headers(headers);
1138 let local_req = local_req_builder.build()?;
1139 log::debug!("request content: {:?}", local_req.body());
1140 let local_resp = local_client.execute(local_req).await?;
1141
1142 let local_status = local_resp.status();
1143 let local_content = local_resp.text().await?;
1144 log::debug!("response content: {}", local_content);
1145
1146 if !local_status.is_client_error() && !local_status.is_server_error() {
1147 match serde_json::from_str::<crate::datadogV2::model::DORAListResponse>(&local_content)
1148 {
1149 Ok(e) => {
1150 return Ok(datadog::ResponseContent {
1151 status: local_status,
1152 content: local_content,
1153 entity: Some(e),
1154 })
1155 }
1156 Err(e) => return Err(datadog::Error::Serde(e)),
1157 };
1158 } else {
1159 let local_entity: Option<ListDORADeploymentsError> =
1160 serde_json::from_str(&local_content).ok();
1161 let local_error = datadog::ResponseContent {
1162 status: local_status,
1163 content: local_content,
1164 entity: local_entity,
1165 };
1166 Err(datadog::Error::ResponseError(local_error))
1167 }
1168 }
1169
1170 pub async fn list_dora_failures(
1172 &self,
1173 body: crate::datadogV2::model::DORAListFailuresRequest,
1174 ) -> Result<crate::datadogV2::model::DORAListResponse, datadog::Error<ListDORAFailuresError>>
1175 {
1176 match self.list_dora_failures_with_http_info(body).await {
1177 Ok(response_content) => {
1178 if let Some(e) = response_content.entity {
1179 Ok(e)
1180 } else {
1181 Err(datadog::Error::Serde(serde::de::Error::custom(
1182 "response content was None",
1183 )))
1184 }
1185 }
1186 Err(err) => Err(err),
1187 }
1188 }
1189
1190 pub async fn list_dora_failures_with_http_info(
1192 &self,
1193 body: crate::datadogV2::model::DORAListFailuresRequest,
1194 ) -> Result<
1195 datadog::ResponseContent<crate::datadogV2::model::DORAListResponse>,
1196 datadog::Error<ListDORAFailuresError>,
1197 > {
1198 let local_configuration = &self.config;
1199 let operation_id = "v2.list_dora_failures";
1200
1201 let local_client = &self.client;
1202
1203 let local_uri_str = format!(
1204 "{}/api/v2/dora/failures",
1205 local_configuration.get_operation_host(operation_id)
1206 );
1207 let mut local_req_builder =
1208 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1209
1210 let mut headers = HeaderMap::new();
1212 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1213 headers.insert("Accept", HeaderValue::from_static("application/json"));
1214
1215 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1217 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1218 Err(e) => {
1219 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1220 headers.insert(
1221 reqwest::header::USER_AGENT,
1222 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1223 )
1224 }
1225 };
1226
1227 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1229 headers.insert(
1230 "DD-API-KEY",
1231 HeaderValue::from_str(local_key.key.as_str())
1232 .expect("failed to parse DD-API-KEY header"),
1233 );
1234 };
1235 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1236 headers.insert(
1237 "DD-APPLICATION-KEY",
1238 HeaderValue::from_str(local_key.key.as_str())
1239 .expect("failed to parse DD-APPLICATION-KEY header"),
1240 );
1241 };
1242
1243 let output = Vec::new();
1245 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1246 if body.serialize(&mut ser).is_ok() {
1247 if let Some(content_encoding) = headers.get("Content-Encoding") {
1248 match content_encoding.to_str().unwrap_or_default() {
1249 "gzip" => {
1250 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1251 let _ = enc.write_all(ser.into_inner().as_slice());
1252 match enc.finish() {
1253 Ok(buf) => {
1254 local_req_builder = local_req_builder.body(buf);
1255 }
1256 Err(e) => return Err(datadog::Error::Io(e)),
1257 }
1258 }
1259 "deflate" => {
1260 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1261 let _ = enc.write_all(ser.into_inner().as_slice());
1262 match enc.finish() {
1263 Ok(buf) => {
1264 local_req_builder = local_req_builder.body(buf);
1265 }
1266 Err(e) => return Err(datadog::Error::Io(e)),
1267 }
1268 }
1269 "zstd1" => {
1270 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1271 let _ = enc.write_all(ser.into_inner().as_slice());
1272 match enc.finish() {
1273 Ok(buf) => {
1274 local_req_builder = local_req_builder.body(buf);
1275 }
1276 Err(e) => return Err(datadog::Error::Io(e)),
1277 }
1278 }
1279 _ => {
1280 local_req_builder = local_req_builder.body(ser.into_inner());
1281 }
1282 }
1283 } else {
1284 local_req_builder = local_req_builder.body(ser.into_inner());
1285 }
1286 }
1287
1288 local_req_builder = local_req_builder.headers(headers);
1289 let local_req = local_req_builder.build()?;
1290 log::debug!("request content: {:?}", local_req.body());
1291 let local_resp = local_client.execute(local_req).await?;
1292
1293 let local_status = local_resp.status();
1294 let local_content = local_resp.text().await?;
1295 log::debug!("response content: {}", local_content);
1296
1297 if !local_status.is_client_error() && !local_status.is_server_error() {
1298 match serde_json::from_str::<crate::datadogV2::model::DORAListResponse>(&local_content)
1299 {
1300 Ok(e) => {
1301 return Ok(datadog::ResponseContent {
1302 status: local_status,
1303 content: local_content,
1304 entity: Some(e),
1305 })
1306 }
1307 Err(e) => return Err(datadog::Error::Serde(e)),
1308 };
1309 } else {
1310 let local_entity: Option<ListDORAFailuresError> =
1311 serde_json::from_str(&local_content).ok();
1312 let local_error = datadog::ResponseContent {
1313 status: local_status,
1314 content: local_content,
1315 entity: local_entity,
1316 };
1317 Err(datadog::Error::ResponseError(local_error))
1318 }
1319 }
1320}