1use crate::datadog;
5use async_stream::try_stream;
6use flate2::{
7 write::{GzEncoder, ZlibEncoder},
8 Compression,
9};
10use futures_core::stream::Stream;
11use log::warn;
12use reqwest::header::{HeaderMap, HeaderValue};
13use serde::{Deserialize, Serialize};
14use std::io::Write;
15
16#[non_exhaustive]
18#[derive(Clone, Default, Debug)]
19pub struct GetIncidentOptionalParams {
20 pub include: Option<Vec<crate::datadogV2::model::IncidentRelatedObject>>,
22}
23
24impl GetIncidentOptionalParams {
25 pub fn include(mut self, value: Vec<crate::datadogV2::model::IncidentRelatedObject>) -> Self {
27 self.include = Some(value);
28 self
29 }
30}
31
32#[non_exhaustive]
34#[derive(Clone, Default, Debug)]
35pub struct ListIncidentAttachmentsOptionalParams {
36 pub include: Option<Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>>,
38 pub filter_attachment_type:
40 Option<Vec<crate::datadogV2::model::IncidentAttachmentAttachmentType>>,
41}
42
43impl ListIncidentAttachmentsOptionalParams {
44 pub fn include(
46 mut self,
47 value: Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>,
48 ) -> Self {
49 self.include = Some(value);
50 self
51 }
52 pub fn filter_attachment_type(
54 mut self,
55 value: Vec<crate::datadogV2::model::IncidentAttachmentAttachmentType>,
56 ) -> Self {
57 self.filter_attachment_type = Some(value);
58 self
59 }
60}
61
62#[non_exhaustive]
64#[derive(Clone, Default, Debug)]
65pub struct ListIncidentTypesOptionalParams {
66 pub include_deleted: Option<bool>,
68}
69
70impl ListIncidentTypesOptionalParams {
71 pub fn include_deleted(mut self, value: bool) -> Self {
73 self.include_deleted = Some(value);
74 self
75 }
76}
77
78#[non_exhaustive]
80#[derive(Clone, Default, Debug)]
81pub struct ListIncidentsOptionalParams {
82 pub include: Option<Vec<crate::datadogV2::model::IncidentRelatedObject>>,
84 pub page_size: Option<i64>,
86 pub page_offset: Option<i64>,
88}
89
90impl ListIncidentsOptionalParams {
91 pub fn include(mut self, value: Vec<crate::datadogV2::model::IncidentRelatedObject>) -> Self {
93 self.include = Some(value);
94 self
95 }
96 pub fn page_size(mut self, value: i64) -> Self {
98 self.page_size = Some(value);
99 self
100 }
101 pub fn page_offset(mut self, value: i64) -> Self {
103 self.page_offset = Some(value);
104 self
105 }
106}
107
108#[non_exhaustive]
110#[derive(Clone, Default, Debug)]
111pub struct SearchIncidentsOptionalParams {
112 pub include: Option<crate::datadogV2::model::IncidentRelatedObject>,
114 pub sort: Option<crate::datadogV2::model::IncidentSearchSortOrder>,
116 pub page_size: Option<i64>,
118 pub page_offset: Option<i64>,
120}
121
122impl SearchIncidentsOptionalParams {
123 pub fn include(mut self, value: crate::datadogV2::model::IncidentRelatedObject) -> Self {
125 self.include = Some(value);
126 self
127 }
128 pub fn sort(mut self, value: crate::datadogV2::model::IncidentSearchSortOrder) -> Self {
130 self.sort = Some(value);
131 self
132 }
133 pub fn page_size(mut self, value: i64) -> Self {
135 self.page_size = Some(value);
136 self
137 }
138 pub fn page_offset(mut self, value: i64) -> Self {
140 self.page_offset = Some(value);
141 self
142 }
143}
144
145#[non_exhaustive]
147#[derive(Clone, Default, Debug)]
148pub struct UpdateIncidentOptionalParams {
149 pub include: Option<Vec<crate::datadogV2::model::IncidentRelatedObject>>,
151}
152
153impl UpdateIncidentOptionalParams {
154 pub fn include(mut self, value: Vec<crate::datadogV2::model::IncidentRelatedObject>) -> Self {
156 self.include = Some(value);
157 self
158 }
159}
160
161#[non_exhaustive]
163#[derive(Clone, Default, Debug)]
164pub struct UpdateIncidentAttachmentsOptionalParams {
165 pub include: Option<Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>>,
167}
168
169impl UpdateIncidentAttachmentsOptionalParams {
170 pub fn include(
172 mut self,
173 value: Vec<crate::datadogV2::model::IncidentAttachmentRelatedObject>,
174 ) -> Self {
175 self.include = Some(value);
176 self
177 }
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum CreateIncidentError {
184 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
185 UnknownValue(serde_json::Value),
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190#[serde(untagged)]
191pub enum CreateIncidentIntegrationError {
192 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
193 UnknownValue(serde_json::Value),
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum CreateIncidentTodoError {
200 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
201 UnknownValue(serde_json::Value),
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize)]
206#[serde(untagged)]
207pub enum CreateIncidentTypeError {
208 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
209 UnknownValue(serde_json::Value),
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
214#[serde(untagged)]
215pub enum DeleteIncidentError {
216 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
217 UnknownValue(serde_json::Value),
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
222#[serde(untagged)]
223pub enum DeleteIncidentIntegrationError {
224 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
225 UnknownValue(serde_json::Value),
226}
227
228#[derive(Debug, Clone, Serialize, Deserialize)]
230#[serde(untagged)]
231pub enum DeleteIncidentTodoError {
232 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
233 UnknownValue(serde_json::Value),
234}
235
236#[derive(Debug, Clone, Serialize, Deserialize)]
238#[serde(untagged)]
239pub enum DeleteIncidentTypeError {
240 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
241 UnknownValue(serde_json::Value),
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize)]
246#[serde(untagged)]
247pub enum GetIncidentError {
248 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
249 UnknownValue(serde_json::Value),
250}
251
252#[derive(Debug, Clone, Serialize, Deserialize)]
254#[serde(untagged)]
255pub enum GetIncidentIntegrationError {
256 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
257 UnknownValue(serde_json::Value),
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize)]
262#[serde(untagged)]
263pub enum GetIncidentTodoError {
264 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
265 UnknownValue(serde_json::Value),
266}
267
268#[derive(Debug, Clone, Serialize, Deserialize)]
270#[serde(untagged)]
271pub enum GetIncidentTypeError {
272 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
273 UnknownValue(serde_json::Value),
274}
275
276#[derive(Debug, Clone, Serialize, Deserialize)]
278#[serde(untagged)]
279pub enum ListIncidentAttachmentsError {
280 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
281 UnknownValue(serde_json::Value),
282}
283
284#[derive(Debug, Clone, Serialize, Deserialize)]
286#[serde(untagged)]
287pub enum ListIncidentIntegrationsError {
288 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
289 UnknownValue(serde_json::Value),
290}
291
292#[derive(Debug, Clone, Serialize, Deserialize)]
294#[serde(untagged)]
295pub enum ListIncidentTodosError {
296 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
297 UnknownValue(serde_json::Value),
298}
299
300#[derive(Debug, Clone, Serialize, Deserialize)]
302#[serde(untagged)]
303pub enum ListIncidentTypesError {
304 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
305 UnknownValue(serde_json::Value),
306}
307
308#[derive(Debug, Clone, Serialize, Deserialize)]
310#[serde(untagged)]
311pub enum ListIncidentsError {
312 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
313 UnknownValue(serde_json::Value),
314}
315
316#[derive(Debug, Clone, Serialize, Deserialize)]
318#[serde(untagged)]
319pub enum SearchIncidentsError {
320 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
321 UnknownValue(serde_json::Value),
322}
323
324#[derive(Debug, Clone, Serialize, Deserialize)]
326#[serde(untagged)]
327pub enum UpdateIncidentError {
328 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
329 UnknownValue(serde_json::Value),
330}
331
332#[derive(Debug, Clone, Serialize, Deserialize)]
334#[serde(untagged)]
335pub enum UpdateIncidentAttachmentsError {
336 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
337 UnknownValue(serde_json::Value),
338}
339
340#[derive(Debug, Clone, Serialize, Deserialize)]
342#[serde(untagged)]
343pub enum UpdateIncidentIntegrationError {
344 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
345 UnknownValue(serde_json::Value),
346}
347
348#[derive(Debug, Clone, Serialize, Deserialize)]
350#[serde(untagged)]
351pub enum UpdateIncidentTodoError {
352 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
353 UnknownValue(serde_json::Value),
354}
355
356#[derive(Debug, Clone, Serialize, Deserialize)]
358#[serde(untagged)]
359pub enum UpdateIncidentTypeError {
360 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
361 UnknownValue(serde_json::Value),
362}
363
364#[derive(Debug, Clone)]
366pub struct IncidentsAPI {
367 config: datadog::Configuration,
368 client: reqwest_middleware::ClientWithMiddleware,
369}
370
371impl Default for IncidentsAPI {
372 fn default() -> Self {
373 Self::with_config(datadog::Configuration::default())
374 }
375}
376
377impl IncidentsAPI {
378 pub fn new() -> Self {
379 Self::default()
380 }
381 pub fn with_config(config: datadog::Configuration) -> Self {
382 let mut reqwest_client_builder = reqwest::Client::builder();
383
384 if let Some(proxy_url) = &config.proxy_url {
385 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
386 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
387 }
388
389 let mut middleware_client_builder =
390 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
391
392 if config.enable_retry {
393 struct RetryableStatus;
394 impl reqwest_retry::RetryableStrategy for RetryableStatus {
395 fn handle(
396 &self,
397 res: &Result<reqwest::Response, reqwest_middleware::Error>,
398 ) -> Option<reqwest_retry::Retryable> {
399 match res {
400 Ok(success) => reqwest_retry::default_on_request_success(success),
401 Err(_) => None,
402 }
403 }
404 }
405 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
406 .build_with_max_retries(config.max_retries);
407
408 let retry_middleware =
409 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
410 backoff_policy,
411 RetryableStatus,
412 );
413
414 middleware_client_builder = middleware_client_builder.with(retry_middleware);
415 }
416
417 let client = middleware_client_builder.build();
418
419 Self { config, client }
420 }
421
422 pub fn with_client_and_config(
423 config: datadog::Configuration,
424 client: reqwest_middleware::ClientWithMiddleware,
425 ) -> Self {
426 Self { config, client }
427 }
428
429 pub async fn create_incident(
431 &self,
432 body: crate::datadogV2::model::IncidentCreateRequest,
433 ) -> Result<crate::datadogV2::model::IncidentResponse, datadog::Error<CreateIncidentError>>
434 {
435 match self.create_incident_with_http_info(body).await {
436 Ok(response_content) => {
437 if let Some(e) = response_content.entity {
438 Ok(e)
439 } else {
440 Err(datadog::Error::Serde(serde::de::Error::custom(
441 "response content was None",
442 )))
443 }
444 }
445 Err(err) => Err(err),
446 }
447 }
448
449 pub async fn create_incident_with_http_info(
451 &self,
452 body: crate::datadogV2::model::IncidentCreateRequest,
453 ) -> Result<
454 datadog::ResponseContent<crate::datadogV2::model::IncidentResponse>,
455 datadog::Error<CreateIncidentError>,
456 > {
457 let local_configuration = &self.config;
458 let operation_id = "v2.create_incident";
459 if local_configuration.is_unstable_operation_enabled(operation_id) {
460 warn!("Using unstable operation {operation_id}");
461 } else {
462 let local_error = datadog::UnstableOperationDisabledError {
463 msg: "Operation 'v2.create_incident' is not enabled".to_string(),
464 };
465 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
466 }
467
468 let local_client = &self.client;
469
470 let local_uri_str = format!(
471 "{}/api/v2/incidents",
472 local_configuration.get_operation_host(operation_id)
473 );
474 let mut local_req_builder =
475 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
476
477 let mut headers = HeaderMap::new();
479 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
480 headers.insert("Accept", HeaderValue::from_static("application/json"));
481
482 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
484 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
485 Err(e) => {
486 log::warn!("Failed to parse user agent header: {e}, falling back to default");
487 headers.insert(
488 reqwest::header::USER_AGENT,
489 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
490 )
491 }
492 };
493
494 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
496 headers.insert(
497 "DD-API-KEY",
498 HeaderValue::from_str(local_key.key.as_str())
499 .expect("failed to parse DD-API-KEY header"),
500 );
501 };
502 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
503 headers.insert(
504 "DD-APPLICATION-KEY",
505 HeaderValue::from_str(local_key.key.as_str())
506 .expect("failed to parse DD-APPLICATION-KEY header"),
507 );
508 };
509
510 let output = Vec::new();
512 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
513 if body.serialize(&mut ser).is_ok() {
514 if let Some(content_encoding) = headers.get("Content-Encoding") {
515 match content_encoding.to_str().unwrap_or_default() {
516 "gzip" => {
517 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
518 let _ = enc.write_all(ser.into_inner().as_slice());
519 match enc.finish() {
520 Ok(buf) => {
521 local_req_builder = local_req_builder.body(buf);
522 }
523 Err(e) => return Err(datadog::Error::Io(e)),
524 }
525 }
526 "deflate" => {
527 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
528 let _ = enc.write_all(ser.into_inner().as_slice());
529 match enc.finish() {
530 Ok(buf) => {
531 local_req_builder = local_req_builder.body(buf);
532 }
533 Err(e) => return Err(datadog::Error::Io(e)),
534 }
535 }
536 "zstd1" => {
537 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
538 let _ = enc.write_all(ser.into_inner().as_slice());
539 match enc.finish() {
540 Ok(buf) => {
541 local_req_builder = local_req_builder.body(buf);
542 }
543 Err(e) => return Err(datadog::Error::Io(e)),
544 }
545 }
546 _ => {
547 local_req_builder = local_req_builder.body(ser.into_inner());
548 }
549 }
550 } else {
551 local_req_builder = local_req_builder.body(ser.into_inner());
552 }
553 }
554
555 local_req_builder = local_req_builder.headers(headers);
556 let local_req = local_req_builder.build()?;
557 log::debug!("request content: {:?}", local_req.body());
558 let local_resp = local_client.execute(local_req).await?;
559
560 let local_status = local_resp.status();
561 let local_content = local_resp.text().await?;
562 log::debug!("response content: {}", local_content);
563
564 if !local_status.is_client_error() && !local_status.is_server_error() {
565 match serde_json::from_str::<crate::datadogV2::model::IncidentResponse>(&local_content)
566 {
567 Ok(e) => {
568 return Ok(datadog::ResponseContent {
569 status: local_status,
570 content: local_content,
571 entity: Some(e),
572 })
573 }
574 Err(e) => return Err(datadog::Error::Serde(e)),
575 };
576 } else {
577 let local_entity: Option<CreateIncidentError> =
578 serde_json::from_str(&local_content).ok();
579 let local_error = datadog::ResponseContent {
580 status: local_status,
581 content: local_content,
582 entity: local_entity,
583 };
584 Err(datadog::Error::ResponseError(local_error))
585 }
586 }
587
588 pub async fn create_incident_integration(
590 &self,
591 incident_id: String,
592 body: crate::datadogV2::model::IncidentIntegrationMetadataCreateRequest,
593 ) -> Result<
594 crate::datadogV2::model::IncidentIntegrationMetadataResponse,
595 datadog::Error<CreateIncidentIntegrationError>,
596 > {
597 match self
598 .create_incident_integration_with_http_info(incident_id, body)
599 .await
600 {
601 Ok(response_content) => {
602 if let Some(e) = response_content.entity {
603 Ok(e)
604 } else {
605 Err(datadog::Error::Serde(serde::de::Error::custom(
606 "response content was None",
607 )))
608 }
609 }
610 Err(err) => Err(err),
611 }
612 }
613
614 pub async fn create_incident_integration_with_http_info(
616 &self,
617 incident_id: String,
618 body: crate::datadogV2::model::IncidentIntegrationMetadataCreateRequest,
619 ) -> Result<
620 datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataResponse>,
621 datadog::Error<CreateIncidentIntegrationError>,
622 > {
623 let local_configuration = &self.config;
624 let operation_id = "v2.create_incident_integration";
625 if local_configuration.is_unstable_operation_enabled(operation_id) {
626 warn!("Using unstable operation {operation_id}");
627 } else {
628 let local_error = datadog::UnstableOperationDisabledError {
629 msg: "Operation 'v2.create_incident_integration' is not enabled".to_string(),
630 };
631 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
632 }
633
634 let local_client = &self.client;
635
636 let local_uri_str = format!(
637 "{}/api/v2/incidents/{incident_id}/relationships/integrations",
638 local_configuration.get_operation_host(operation_id),
639 incident_id = datadog::urlencode(incident_id)
640 );
641 let mut local_req_builder =
642 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
643
644 let mut headers = HeaderMap::new();
646 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
647 headers.insert("Accept", HeaderValue::from_static("application/json"));
648
649 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
651 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
652 Err(e) => {
653 log::warn!("Failed to parse user agent header: {e}, falling back to default");
654 headers.insert(
655 reqwest::header::USER_AGENT,
656 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
657 )
658 }
659 };
660
661 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
663 headers.insert(
664 "DD-API-KEY",
665 HeaderValue::from_str(local_key.key.as_str())
666 .expect("failed to parse DD-API-KEY header"),
667 );
668 };
669 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
670 headers.insert(
671 "DD-APPLICATION-KEY",
672 HeaderValue::from_str(local_key.key.as_str())
673 .expect("failed to parse DD-APPLICATION-KEY header"),
674 );
675 };
676
677 let output = Vec::new();
679 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
680 if body.serialize(&mut ser).is_ok() {
681 if let Some(content_encoding) = headers.get("Content-Encoding") {
682 match content_encoding.to_str().unwrap_or_default() {
683 "gzip" => {
684 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
685 let _ = enc.write_all(ser.into_inner().as_slice());
686 match enc.finish() {
687 Ok(buf) => {
688 local_req_builder = local_req_builder.body(buf);
689 }
690 Err(e) => return Err(datadog::Error::Io(e)),
691 }
692 }
693 "deflate" => {
694 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
695 let _ = enc.write_all(ser.into_inner().as_slice());
696 match enc.finish() {
697 Ok(buf) => {
698 local_req_builder = local_req_builder.body(buf);
699 }
700 Err(e) => return Err(datadog::Error::Io(e)),
701 }
702 }
703 "zstd1" => {
704 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
705 let _ = enc.write_all(ser.into_inner().as_slice());
706 match enc.finish() {
707 Ok(buf) => {
708 local_req_builder = local_req_builder.body(buf);
709 }
710 Err(e) => return Err(datadog::Error::Io(e)),
711 }
712 }
713 _ => {
714 local_req_builder = local_req_builder.body(ser.into_inner());
715 }
716 }
717 } else {
718 local_req_builder = local_req_builder.body(ser.into_inner());
719 }
720 }
721
722 local_req_builder = local_req_builder.headers(headers);
723 let local_req = local_req_builder.build()?;
724 log::debug!("request content: {:?}", local_req.body());
725 let local_resp = local_client.execute(local_req).await?;
726
727 let local_status = local_resp.status();
728 let local_content = local_resp.text().await?;
729 log::debug!("response content: {}", local_content);
730
731 if !local_status.is_client_error() && !local_status.is_server_error() {
732 match serde_json::from_str::<crate::datadogV2::model::IncidentIntegrationMetadataResponse>(
733 &local_content,
734 ) {
735 Ok(e) => {
736 return Ok(datadog::ResponseContent {
737 status: local_status,
738 content: local_content,
739 entity: Some(e),
740 })
741 }
742 Err(e) => return Err(datadog::Error::Serde(e)),
743 };
744 } else {
745 let local_entity: Option<CreateIncidentIntegrationError> =
746 serde_json::from_str(&local_content).ok();
747 let local_error = datadog::ResponseContent {
748 status: local_status,
749 content: local_content,
750 entity: local_entity,
751 };
752 Err(datadog::Error::ResponseError(local_error))
753 }
754 }
755
756 pub async fn create_incident_todo(
758 &self,
759 incident_id: String,
760 body: crate::datadogV2::model::IncidentTodoCreateRequest,
761 ) -> Result<
762 crate::datadogV2::model::IncidentTodoResponse,
763 datadog::Error<CreateIncidentTodoError>,
764 > {
765 match self
766 .create_incident_todo_with_http_info(incident_id, body)
767 .await
768 {
769 Ok(response_content) => {
770 if let Some(e) = response_content.entity {
771 Ok(e)
772 } else {
773 Err(datadog::Error::Serde(serde::de::Error::custom(
774 "response content was None",
775 )))
776 }
777 }
778 Err(err) => Err(err),
779 }
780 }
781
782 pub async fn create_incident_todo_with_http_info(
784 &self,
785 incident_id: String,
786 body: crate::datadogV2::model::IncidentTodoCreateRequest,
787 ) -> Result<
788 datadog::ResponseContent<crate::datadogV2::model::IncidentTodoResponse>,
789 datadog::Error<CreateIncidentTodoError>,
790 > {
791 let local_configuration = &self.config;
792 let operation_id = "v2.create_incident_todo";
793 if local_configuration.is_unstable_operation_enabled(operation_id) {
794 warn!("Using unstable operation {operation_id}");
795 } else {
796 let local_error = datadog::UnstableOperationDisabledError {
797 msg: "Operation 'v2.create_incident_todo' is not enabled".to_string(),
798 };
799 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
800 }
801
802 let local_client = &self.client;
803
804 let local_uri_str = format!(
805 "{}/api/v2/incidents/{incident_id}/relationships/todos",
806 local_configuration.get_operation_host(operation_id),
807 incident_id = datadog::urlencode(incident_id)
808 );
809 let mut local_req_builder =
810 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
811
812 let mut headers = HeaderMap::new();
814 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
815 headers.insert("Accept", HeaderValue::from_static("application/json"));
816
817 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
819 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
820 Err(e) => {
821 log::warn!("Failed to parse user agent header: {e}, falling back to default");
822 headers.insert(
823 reqwest::header::USER_AGENT,
824 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
825 )
826 }
827 };
828
829 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
831 headers.insert(
832 "DD-API-KEY",
833 HeaderValue::from_str(local_key.key.as_str())
834 .expect("failed to parse DD-API-KEY header"),
835 );
836 };
837 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
838 headers.insert(
839 "DD-APPLICATION-KEY",
840 HeaderValue::from_str(local_key.key.as_str())
841 .expect("failed to parse DD-APPLICATION-KEY header"),
842 );
843 };
844
845 let output = Vec::new();
847 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
848 if body.serialize(&mut ser).is_ok() {
849 if let Some(content_encoding) = headers.get("Content-Encoding") {
850 match content_encoding.to_str().unwrap_or_default() {
851 "gzip" => {
852 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
853 let _ = enc.write_all(ser.into_inner().as_slice());
854 match enc.finish() {
855 Ok(buf) => {
856 local_req_builder = local_req_builder.body(buf);
857 }
858 Err(e) => return Err(datadog::Error::Io(e)),
859 }
860 }
861 "deflate" => {
862 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
863 let _ = enc.write_all(ser.into_inner().as_slice());
864 match enc.finish() {
865 Ok(buf) => {
866 local_req_builder = local_req_builder.body(buf);
867 }
868 Err(e) => return Err(datadog::Error::Io(e)),
869 }
870 }
871 "zstd1" => {
872 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
873 let _ = enc.write_all(ser.into_inner().as_slice());
874 match enc.finish() {
875 Ok(buf) => {
876 local_req_builder = local_req_builder.body(buf);
877 }
878 Err(e) => return Err(datadog::Error::Io(e)),
879 }
880 }
881 _ => {
882 local_req_builder = local_req_builder.body(ser.into_inner());
883 }
884 }
885 } else {
886 local_req_builder = local_req_builder.body(ser.into_inner());
887 }
888 }
889
890 local_req_builder = local_req_builder.headers(headers);
891 let local_req = local_req_builder.build()?;
892 log::debug!("request content: {:?}", local_req.body());
893 let local_resp = local_client.execute(local_req).await?;
894
895 let local_status = local_resp.status();
896 let local_content = local_resp.text().await?;
897 log::debug!("response content: {}", local_content);
898
899 if !local_status.is_client_error() && !local_status.is_server_error() {
900 match serde_json::from_str::<crate::datadogV2::model::IncidentTodoResponse>(
901 &local_content,
902 ) {
903 Ok(e) => {
904 return Ok(datadog::ResponseContent {
905 status: local_status,
906 content: local_content,
907 entity: Some(e),
908 })
909 }
910 Err(e) => return Err(datadog::Error::Serde(e)),
911 };
912 } else {
913 let local_entity: Option<CreateIncidentTodoError> =
914 serde_json::from_str(&local_content).ok();
915 let local_error = datadog::ResponseContent {
916 status: local_status,
917 content: local_content,
918 entity: local_entity,
919 };
920 Err(datadog::Error::ResponseError(local_error))
921 }
922 }
923
924 pub async fn create_incident_type(
926 &self,
927 body: crate::datadogV2::model::IncidentTypeCreateRequest,
928 ) -> Result<
929 crate::datadogV2::model::IncidentTypeResponse,
930 datadog::Error<CreateIncidentTypeError>,
931 > {
932 match self.create_incident_type_with_http_info(body).await {
933 Ok(response_content) => {
934 if let Some(e) = response_content.entity {
935 Ok(e)
936 } else {
937 Err(datadog::Error::Serde(serde::de::Error::custom(
938 "response content was None",
939 )))
940 }
941 }
942 Err(err) => Err(err),
943 }
944 }
945
946 pub async fn create_incident_type_with_http_info(
948 &self,
949 body: crate::datadogV2::model::IncidentTypeCreateRequest,
950 ) -> Result<
951 datadog::ResponseContent<crate::datadogV2::model::IncidentTypeResponse>,
952 datadog::Error<CreateIncidentTypeError>,
953 > {
954 let local_configuration = &self.config;
955 let operation_id = "v2.create_incident_type";
956 if local_configuration.is_unstable_operation_enabled(operation_id) {
957 warn!("Using unstable operation {operation_id}");
958 } else {
959 let local_error = datadog::UnstableOperationDisabledError {
960 msg: "Operation 'v2.create_incident_type' is not enabled".to_string(),
961 };
962 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
963 }
964
965 let local_client = &self.client;
966
967 let local_uri_str = format!(
968 "{}/api/v2/incidents/config/types",
969 local_configuration.get_operation_host(operation_id)
970 );
971 let mut local_req_builder =
972 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
973
974 let mut headers = HeaderMap::new();
976 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
977 headers.insert("Accept", HeaderValue::from_static("application/json"));
978
979 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
981 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
982 Err(e) => {
983 log::warn!("Failed to parse user agent header: {e}, falling back to default");
984 headers.insert(
985 reqwest::header::USER_AGENT,
986 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
987 )
988 }
989 };
990
991 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
993 headers.insert(
994 "DD-API-KEY",
995 HeaderValue::from_str(local_key.key.as_str())
996 .expect("failed to parse DD-API-KEY header"),
997 );
998 };
999 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1000 headers.insert(
1001 "DD-APPLICATION-KEY",
1002 HeaderValue::from_str(local_key.key.as_str())
1003 .expect("failed to parse DD-APPLICATION-KEY header"),
1004 );
1005 };
1006
1007 let output = Vec::new();
1009 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1010 if body.serialize(&mut ser).is_ok() {
1011 if let Some(content_encoding) = headers.get("Content-Encoding") {
1012 match content_encoding.to_str().unwrap_or_default() {
1013 "gzip" => {
1014 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1015 let _ = enc.write_all(ser.into_inner().as_slice());
1016 match enc.finish() {
1017 Ok(buf) => {
1018 local_req_builder = local_req_builder.body(buf);
1019 }
1020 Err(e) => return Err(datadog::Error::Io(e)),
1021 }
1022 }
1023 "deflate" => {
1024 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1025 let _ = enc.write_all(ser.into_inner().as_slice());
1026 match enc.finish() {
1027 Ok(buf) => {
1028 local_req_builder = local_req_builder.body(buf);
1029 }
1030 Err(e) => return Err(datadog::Error::Io(e)),
1031 }
1032 }
1033 "zstd1" => {
1034 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1035 let _ = enc.write_all(ser.into_inner().as_slice());
1036 match enc.finish() {
1037 Ok(buf) => {
1038 local_req_builder = local_req_builder.body(buf);
1039 }
1040 Err(e) => return Err(datadog::Error::Io(e)),
1041 }
1042 }
1043 _ => {
1044 local_req_builder = local_req_builder.body(ser.into_inner());
1045 }
1046 }
1047 } else {
1048 local_req_builder = local_req_builder.body(ser.into_inner());
1049 }
1050 }
1051
1052 local_req_builder = local_req_builder.headers(headers);
1053 let local_req = local_req_builder.build()?;
1054 log::debug!("request content: {:?}", local_req.body());
1055 let local_resp = local_client.execute(local_req).await?;
1056
1057 let local_status = local_resp.status();
1058 let local_content = local_resp.text().await?;
1059 log::debug!("response content: {}", local_content);
1060
1061 if !local_status.is_client_error() && !local_status.is_server_error() {
1062 match serde_json::from_str::<crate::datadogV2::model::IncidentTypeResponse>(
1063 &local_content,
1064 ) {
1065 Ok(e) => {
1066 return Ok(datadog::ResponseContent {
1067 status: local_status,
1068 content: local_content,
1069 entity: Some(e),
1070 })
1071 }
1072 Err(e) => return Err(datadog::Error::Serde(e)),
1073 };
1074 } else {
1075 let local_entity: Option<CreateIncidentTypeError> =
1076 serde_json::from_str(&local_content).ok();
1077 let local_error = datadog::ResponseContent {
1078 status: local_status,
1079 content: local_content,
1080 entity: local_entity,
1081 };
1082 Err(datadog::Error::ResponseError(local_error))
1083 }
1084 }
1085
1086 pub async fn delete_incident(
1088 &self,
1089 incident_id: String,
1090 ) -> Result<(), datadog::Error<DeleteIncidentError>> {
1091 match self.delete_incident_with_http_info(incident_id).await {
1092 Ok(_) => Ok(()),
1093 Err(err) => Err(err),
1094 }
1095 }
1096
1097 pub async fn delete_incident_with_http_info(
1099 &self,
1100 incident_id: String,
1101 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentError>> {
1102 let local_configuration = &self.config;
1103 let operation_id = "v2.delete_incident";
1104 if local_configuration.is_unstable_operation_enabled(operation_id) {
1105 warn!("Using unstable operation {operation_id}");
1106 } else {
1107 let local_error = datadog::UnstableOperationDisabledError {
1108 msg: "Operation 'v2.delete_incident' is not enabled".to_string(),
1109 };
1110 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1111 }
1112
1113 let local_client = &self.client;
1114
1115 let local_uri_str = format!(
1116 "{}/api/v2/incidents/{incident_id}",
1117 local_configuration.get_operation_host(operation_id),
1118 incident_id = datadog::urlencode(incident_id)
1119 );
1120 let mut local_req_builder =
1121 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1122
1123 let mut headers = HeaderMap::new();
1125 headers.insert("Accept", HeaderValue::from_static("*/*"));
1126
1127 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1129 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1130 Err(e) => {
1131 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1132 headers.insert(
1133 reqwest::header::USER_AGENT,
1134 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1135 )
1136 }
1137 };
1138
1139 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1141 headers.insert(
1142 "DD-API-KEY",
1143 HeaderValue::from_str(local_key.key.as_str())
1144 .expect("failed to parse DD-API-KEY header"),
1145 );
1146 };
1147 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1148 headers.insert(
1149 "DD-APPLICATION-KEY",
1150 HeaderValue::from_str(local_key.key.as_str())
1151 .expect("failed to parse DD-APPLICATION-KEY header"),
1152 );
1153 };
1154
1155 local_req_builder = local_req_builder.headers(headers);
1156 let local_req = local_req_builder.build()?;
1157 log::debug!("request content: {:?}", local_req.body());
1158 let local_resp = local_client.execute(local_req).await?;
1159
1160 let local_status = local_resp.status();
1161 let local_content = local_resp.text().await?;
1162 log::debug!("response content: {}", local_content);
1163
1164 if !local_status.is_client_error() && !local_status.is_server_error() {
1165 Ok(datadog::ResponseContent {
1166 status: local_status,
1167 content: local_content,
1168 entity: None,
1169 })
1170 } else {
1171 let local_entity: Option<DeleteIncidentError> =
1172 serde_json::from_str(&local_content).ok();
1173 let local_error = datadog::ResponseContent {
1174 status: local_status,
1175 content: local_content,
1176 entity: local_entity,
1177 };
1178 Err(datadog::Error::ResponseError(local_error))
1179 }
1180 }
1181
1182 pub async fn delete_incident_integration(
1184 &self,
1185 incident_id: String,
1186 integration_metadata_id: String,
1187 ) -> Result<(), datadog::Error<DeleteIncidentIntegrationError>> {
1188 match self
1189 .delete_incident_integration_with_http_info(incident_id, integration_metadata_id)
1190 .await
1191 {
1192 Ok(_) => Ok(()),
1193 Err(err) => Err(err),
1194 }
1195 }
1196
1197 pub async fn delete_incident_integration_with_http_info(
1199 &self,
1200 incident_id: String,
1201 integration_metadata_id: String,
1202 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentIntegrationError>> {
1203 let local_configuration = &self.config;
1204 let operation_id = "v2.delete_incident_integration";
1205 if local_configuration.is_unstable_operation_enabled(operation_id) {
1206 warn!("Using unstable operation {operation_id}");
1207 } else {
1208 let local_error = datadog::UnstableOperationDisabledError {
1209 msg: "Operation 'v2.delete_incident_integration' is not enabled".to_string(),
1210 };
1211 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1212 }
1213
1214 let local_client = &self.client;
1215
1216 let local_uri_str = format!(
1217 "{}/api/v2/incidents/{incident_id}/relationships/integrations/{integration_metadata_id}",
1218 local_configuration.get_operation_host(operation_id), incident_id=
1219 datadog::urlencode(incident_id)
1220 , integration_metadata_id=
1221 datadog::urlencode(integration_metadata_id)
1222 );
1223 let mut local_req_builder =
1224 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1225
1226 let mut headers = HeaderMap::new();
1228 headers.insert("Accept", HeaderValue::from_static("*/*"));
1229
1230 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1232 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1233 Err(e) => {
1234 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1235 headers.insert(
1236 reqwest::header::USER_AGENT,
1237 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1238 )
1239 }
1240 };
1241
1242 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1244 headers.insert(
1245 "DD-API-KEY",
1246 HeaderValue::from_str(local_key.key.as_str())
1247 .expect("failed to parse DD-API-KEY header"),
1248 );
1249 };
1250 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1251 headers.insert(
1252 "DD-APPLICATION-KEY",
1253 HeaderValue::from_str(local_key.key.as_str())
1254 .expect("failed to parse DD-APPLICATION-KEY header"),
1255 );
1256 };
1257
1258 local_req_builder = local_req_builder.headers(headers);
1259 let local_req = local_req_builder.build()?;
1260 log::debug!("request content: {:?}", local_req.body());
1261 let local_resp = local_client.execute(local_req).await?;
1262
1263 let local_status = local_resp.status();
1264 let local_content = local_resp.text().await?;
1265 log::debug!("response content: {}", local_content);
1266
1267 if !local_status.is_client_error() && !local_status.is_server_error() {
1268 Ok(datadog::ResponseContent {
1269 status: local_status,
1270 content: local_content,
1271 entity: None,
1272 })
1273 } else {
1274 let local_entity: Option<DeleteIncidentIntegrationError> =
1275 serde_json::from_str(&local_content).ok();
1276 let local_error = datadog::ResponseContent {
1277 status: local_status,
1278 content: local_content,
1279 entity: local_entity,
1280 };
1281 Err(datadog::Error::ResponseError(local_error))
1282 }
1283 }
1284
1285 pub async fn delete_incident_todo(
1287 &self,
1288 incident_id: String,
1289 todo_id: String,
1290 ) -> Result<(), datadog::Error<DeleteIncidentTodoError>> {
1291 match self
1292 .delete_incident_todo_with_http_info(incident_id, todo_id)
1293 .await
1294 {
1295 Ok(_) => Ok(()),
1296 Err(err) => Err(err),
1297 }
1298 }
1299
1300 pub async fn delete_incident_todo_with_http_info(
1302 &self,
1303 incident_id: String,
1304 todo_id: String,
1305 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentTodoError>> {
1306 let local_configuration = &self.config;
1307 let operation_id = "v2.delete_incident_todo";
1308 if local_configuration.is_unstable_operation_enabled(operation_id) {
1309 warn!("Using unstable operation {operation_id}");
1310 } else {
1311 let local_error = datadog::UnstableOperationDisabledError {
1312 msg: "Operation 'v2.delete_incident_todo' is not enabled".to_string(),
1313 };
1314 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1315 }
1316
1317 let local_client = &self.client;
1318
1319 let local_uri_str = format!(
1320 "{}/api/v2/incidents/{incident_id}/relationships/todos/{todo_id}",
1321 local_configuration.get_operation_host(operation_id),
1322 incident_id = datadog::urlencode(incident_id),
1323 todo_id = datadog::urlencode(todo_id)
1324 );
1325 let mut local_req_builder =
1326 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1327
1328 let mut headers = HeaderMap::new();
1330 headers.insert("Accept", HeaderValue::from_static("*/*"));
1331
1332 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1334 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1335 Err(e) => {
1336 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1337 headers.insert(
1338 reqwest::header::USER_AGENT,
1339 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1340 )
1341 }
1342 };
1343
1344 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1346 headers.insert(
1347 "DD-API-KEY",
1348 HeaderValue::from_str(local_key.key.as_str())
1349 .expect("failed to parse DD-API-KEY header"),
1350 );
1351 };
1352 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1353 headers.insert(
1354 "DD-APPLICATION-KEY",
1355 HeaderValue::from_str(local_key.key.as_str())
1356 .expect("failed to parse DD-APPLICATION-KEY header"),
1357 );
1358 };
1359
1360 local_req_builder = local_req_builder.headers(headers);
1361 let local_req = local_req_builder.build()?;
1362 log::debug!("request content: {:?}", local_req.body());
1363 let local_resp = local_client.execute(local_req).await?;
1364
1365 let local_status = local_resp.status();
1366 let local_content = local_resp.text().await?;
1367 log::debug!("response content: {}", local_content);
1368
1369 if !local_status.is_client_error() && !local_status.is_server_error() {
1370 Ok(datadog::ResponseContent {
1371 status: local_status,
1372 content: local_content,
1373 entity: None,
1374 })
1375 } else {
1376 let local_entity: Option<DeleteIncidentTodoError> =
1377 serde_json::from_str(&local_content).ok();
1378 let local_error = datadog::ResponseContent {
1379 status: local_status,
1380 content: local_content,
1381 entity: local_entity,
1382 };
1383 Err(datadog::Error::ResponseError(local_error))
1384 }
1385 }
1386
1387 pub async fn delete_incident_type(
1389 &self,
1390 incident_type_id: String,
1391 ) -> Result<(), datadog::Error<DeleteIncidentTypeError>> {
1392 match self
1393 .delete_incident_type_with_http_info(incident_type_id)
1394 .await
1395 {
1396 Ok(_) => Ok(()),
1397 Err(err) => Err(err),
1398 }
1399 }
1400
1401 pub async fn delete_incident_type_with_http_info(
1403 &self,
1404 incident_type_id: String,
1405 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteIncidentTypeError>> {
1406 let local_configuration = &self.config;
1407 let operation_id = "v2.delete_incident_type";
1408 if local_configuration.is_unstable_operation_enabled(operation_id) {
1409 warn!("Using unstable operation {operation_id}");
1410 } else {
1411 let local_error = datadog::UnstableOperationDisabledError {
1412 msg: "Operation 'v2.delete_incident_type' is not enabled".to_string(),
1413 };
1414 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1415 }
1416
1417 let local_client = &self.client;
1418
1419 let local_uri_str = format!(
1420 "{}/api/v2/incidents/config/types/{incident_type_id}",
1421 local_configuration.get_operation_host(operation_id),
1422 incident_type_id = datadog::urlencode(incident_type_id)
1423 );
1424 let mut local_req_builder =
1425 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1426
1427 let mut headers = HeaderMap::new();
1429 headers.insert("Accept", HeaderValue::from_static("*/*"));
1430
1431 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1433 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1434 Err(e) => {
1435 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1436 headers.insert(
1437 reqwest::header::USER_AGENT,
1438 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1439 )
1440 }
1441 };
1442
1443 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1445 headers.insert(
1446 "DD-API-KEY",
1447 HeaderValue::from_str(local_key.key.as_str())
1448 .expect("failed to parse DD-API-KEY header"),
1449 );
1450 };
1451 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1452 headers.insert(
1453 "DD-APPLICATION-KEY",
1454 HeaderValue::from_str(local_key.key.as_str())
1455 .expect("failed to parse DD-APPLICATION-KEY header"),
1456 );
1457 };
1458
1459 local_req_builder = local_req_builder.headers(headers);
1460 let local_req = local_req_builder.build()?;
1461 log::debug!("request content: {:?}", local_req.body());
1462 let local_resp = local_client.execute(local_req).await?;
1463
1464 let local_status = local_resp.status();
1465 let local_content = local_resp.text().await?;
1466 log::debug!("response content: {}", local_content);
1467
1468 if !local_status.is_client_error() && !local_status.is_server_error() {
1469 Ok(datadog::ResponseContent {
1470 status: local_status,
1471 content: local_content,
1472 entity: None,
1473 })
1474 } else {
1475 let local_entity: Option<DeleteIncidentTypeError> =
1476 serde_json::from_str(&local_content).ok();
1477 let local_error = datadog::ResponseContent {
1478 status: local_status,
1479 content: local_content,
1480 entity: local_entity,
1481 };
1482 Err(datadog::Error::ResponseError(local_error))
1483 }
1484 }
1485
1486 pub async fn get_incident(
1488 &self,
1489 incident_id: String,
1490 params: GetIncidentOptionalParams,
1491 ) -> Result<crate::datadogV2::model::IncidentResponse, datadog::Error<GetIncidentError>> {
1492 match self.get_incident_with_http_info(incident_id, params).await {
1493 Ok(response_content) => {
1494 if let Some(e) = response_content.entity {
1495 Ok(e)
1496 } else {
1497 Err(datadog::Error::Serde(serde::de::Error::custom(
1498 "response content was None",
1499 )))
1500 }
1501 }
1502 Err(err) => Err(err),
1503 }
1504 }
1505
1506 pub async fn get_incident_with_http_info(
1508 &self,
1509 incident_id: String,
1510 params: GetIncidentOptionalParams,
1511 ) -> Result<
1512 datadog::ResponseContent<crate::datadogV2::model::IncidentResponse>,
1513 datadog::Error<GetIncidentError>,
1514 > {
1515 let local_configuration = &self.config;
1516 let operation_id = "v2.get_incident";
1517 if local_configuration.is_unstable_operation_enabled(operation_id) {
1518 warn!("Using unstable operation {operation_id}");
1519 } else {
1520 let local_error = datadog::UnstableOperationDisabledError {
1521 msg: "Operation 'v2.get_incident' is not enabled".to_string(),
1522 };
1523 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1524 }
1525
1526 let include = params.include;
1528
1529 let local_client = &self.client;
1530
1531 let local_uri_str = format!(
1532 "{}/api/v2/incidents/{incident_id}",
1533 local_configuration.get_operation_host(operation_id),
1534 incident_id = datadog::urlencode(incident_id)
1535 );
1536 let mut local_req_builder =
1537 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1538
1539 if let Some(ref local) = include {
1540 local_req_builder = local_req_builder.query(&[(
1541 "include",
1542 &local
1543 .iter()
1544 .map(|p| p.to_string())
1545 .collect::<Vec<String>>()
1546 .join(",")
1547 .to_string(),
1548 )]);
1549 };
1550
1551 let mut headers = HeaderMap::new();
1553 headers.insert("Accept", HeaderValue::from_static("application/json"));
1554
1555 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1557 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1558 Err(e) => {
1559 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1560 headers.insert(
1561 reqwest::header::USER_AGENT,
1562 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1563 )
1564 }
1565 };
1566
1567 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1569 headers.insert(
1570 "DD-API-KEY",
1571 HeaderValue::from_str(local_key.key.as_str())
1572 .expect("failed to parse DD-API-KEY header"),
1573 );
1574 };
1575 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1576 headers.insert(
1577 "DD-APPLICATION-KEY",
1578 HeaderValue::from_str(local_key.key.as_str())
1579 .expect("failed to parse DD-APPLICATION-KEY header"),
1580 );
1581 };
1582
1583 local_req_builder = local_req_builder.headers(headers);
1584 let local_req = local_req_builder.build()?;
1585 log::debug!("request content: {:?}", local_req.body());
1586 let local_resp = local_client.execute(local_req).await?;
1587
1588 let local_status = local_resp.status();
1589 let local_content = local_resp.text().await?;
1590 log::debug!("response content: {}", local_content);
1591
1592 if !local_status.is_client_error() && !local_status.is_server_error() {
1593 match serde_json::from_str::<crate::datadogV2::model::IncidentResponse>(&local_content)
1594 {
1595 Ok(e) => {
1596 return Ok(datadog::ResponseContent {
1597 status: local_status,
1598 content: local_content,
1599 entity: Some(e),
1600 })
1601 }
1602 Err(e) => return Err(datadog::Error::Serde(e)),
1603 };
1604 } else {
1605 let local_entity: Option<GetIncidentError> = serde_json::from_str(&local_content).ok();
1606 let local_error = datadog::ResponseContent {
1607 status: local_status,
1608 content: local_content,
1609 entity: local_entity,
1610 };
1611 Err(datadog::Error::ResponseError(local_error))
1612 }
1613 }
1614
1615 pub async fn get_incident_integration(
1617 &self,
1618 incident_id: String,
1619 integration_metadata_id: String,
1620 ) -> Result<
1621 crate::datadogV2::model::IncidentIntegrationMetadataResponse,
1622 datadog::Error<GetIncidentIntegrationError>,
1623 > {
1624 match self
1625 .get_incident_integration_with_http_info(incident_id, integration_metadata_id)
1626 .await
1627 {
1628 Ok(response_content) => {
1629 if let Some(e) = response_content.entity {
1630 Ok(e)
1631 } else {
1632 Err(datadog::Error::Serde(serde::de::Error::custom(
1633 "response content was None",
1634 )))
1635 }
1636 }
1637 Err(err) => Err(err),
1638 }
1639 }
1640
1641 pub async fn get_incident_integration_with_http_info(
1643 &self,
1644 incident_id: String,
1645 integration_metadata_id: String,
1646 ) -> Result<
1647 datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataResponse>,
1648 datadog::Error<GetIncidentIntegrationError>,
1649 > {
1650 let local_configuration = &self.config;
1651 let operation_id = "v2.get_incident_integration";
1652 if local_configuration.is_unstable_operation_enabled(operation_id) {
1653 warn!("Using unstable operation {operation_id}");
1654 } else {
1655 let local_error = datadog::UnstableOperationDisabledError {
1656 msg: "Operation 'v2.get_incident_integration' is not enabled".to_string(),
1657 };
1658 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1659 }
1660
1661 let local_client = &self.client;
1662
1663 let local_uri_str = format!(
1664 "{}/api/v2/incidents/{incident_id}/relationships/integrations/{integration_metadata_id}",
1665 local_configuration.get_operation_host(operation_id), incident_id=
1666 datadog::urlencode(incident_id)
1667 , integration_metadata_id=
1668 datadog::urlencode(integration_metadata_id)
1669 );
1670 let mut local_req_builder =
1671 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1672
1673 let mut headers = HeaderMap::new();
1675 headers.insert("Accept", HeaderValue::from_static("application/json"));
1676
1677 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1679 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1680 Err(e) => {
1681 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1682 headers.insert(
1683 reqwest::header::USER_AGENT,
1684 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1685 )
1686 }
1687 };
1688
1689 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1691 headers.insert(
1692 "DD-API-KEY",
1693 HeaderValue::from_str(local_key.key.as_str())
1694 .expect("failed to parse DD-API-KEY header"),
1695 );
1696 };
1697 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1698 headers.insert(
1699 "DD-APPLICATION-KEY",
1700 HeaderValue::from_str(local_key.key.as_str())
1701 .expect("failed to parse DD-APPLICATION-KEY header"),
1702 );
1703 };
1704
1705 local_req_builder = local_req_builder.headers(headers);
1706 let local_req = local_req_builder.build()?;
1707 log::debug!("request content: {:?}", local_req.body());
1708 let local_resp = local_client.execute(local_req).await?;
1709
1710 let local_status = local_resp.status();
1711 let local_content = local_resp.text().await?;
1712 log::debug!("response content: {}", local_content);
1713
1714 if !local_status.is_client_error() && !local_status.is_server_error() {
1715 match serde_json::from_str::<crate::datadogV2::model::IncidentIntegrationMetadataResponse>(
1716 &local_content,
1717 ) {
1718 Ok(e) => {
1719 return Ok(datadog::ResponseContent {
1720 status: local_status,
1721 content: local_content,
1722 entity: Some(e),
1723 })
1724 }
1725 Err(e) => return Err(datadog::Error::Serde(e)),
1726 };
1727 } else {
1728 let local_entity: Option<GetIncidentIntegrationError> =
1729 serde_json::from_str(&local_content).ok();
1730 let local_error = datadog::ResponseContent {
1731 status: local_status,
1732 content: local_content,
1733 entity: local_entity,
1734 };
1735 Err(datadog::Error::ResponseError(local_error))
1736 }
1737 }
1738
1739 pub async fn get_incident_todo(
1741 &self,
1742 incident_id: String,
1743 todo_id: String,
1744 ) -> Result<crate::datadogV2::model::IncidentTodoResponse, datadog::Error<GetIncidentTodoError>>
1745 {
1746 match self
1747 .get_incident_todo_with_http_info(incident_id, todo_id)
1748 .await
1749 {
1750 Ok(response_content) => {
1751 if let Some(e) = response_content.entity {
1752 Ok(e)
1753 } else {
1754 Err(datadog::Error::Serde(serde::de::Error::custom(
1755 "response content was None",
1756 )))
1757 }
1758 }
1759 Err(err) => Err(err),
1760 }
1761 }
1762
1763 pub async fn get_incident_todo_with_http_info(
1765 &self,
1766 incident_id: String,
1767 todo_id: String,
1768 ) -> Result<
1769 datadog::ResponseContent<crate::datadogV2::model::IncidentTodoResponse>,
1770 datadog::Error<GetIncidentTodoError>,
1771 > {
1772 let local_configuration = &self.config;
1773 let operation_id = "v2.get_incident_todo";
1774 if local_configuration.is_unstable_operation_enabled(operation_id) {
1775 warn!("Using unstable operation {operation_id}");
1776 } else {
1777 let local_error = datadog::UnstableOperationDisabledError {
1778 msg: "Operation 'v2.get_incident_todo' is not enabled".to_string(),
1779 };
1780 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1781 }
1782
1783 let local_client = &self.client;
1784
1785 let local_uri_str = format!(
1786 "{}/api/v2/incidents/{incident_id}/relationships/todos/{todo_id}",
1787 local_configuration.get_operation_host(operation_id),
1788 incident_id = datadog::urlencode(incident_id),
1789 todo_id = datadog::urlencode(todo_id)
1790 );
1791 let mut local_req_builder =
1792 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1793
1794 let mut headers = HeaderMap::new();
1796 headers.insert("Accept", HeaderValue::from_static("application/json"));
1797
1798 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1800 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1801 Err(e) => {
1802 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1803 headers.insert(
1804 reqwest::header::USER_AGENT,
1805 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1806 )
1807 }
1808 };
1809
1810 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1812 headers.insert(
1813 "DD-API-KEY",
1814 HeaderValue::from_str(local_key.key.as_str())
1815 .expect("failed to parse DD-API-KEY header"),
1816 );
1817 };
1818 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1819 headers.insert(
1820 "DD-APPLICATION-KEY",
1821 HeaderValue::from_str(local_key.key.as_str())
1822 .expect("failed to parse DD-APPLICATION-KEY header"),
1823 );
1824 };
1825
1826 local_req_builder = local_req_builder.headers(headers);
1827 let local_req = local_req_builder.build()?;
1828 log::debug!("request content: {:?}", local_req.body());
1829 let local_resp = local_client.execute(local_req).await?;
1830
1831 let local_status = local_resp.status();
1832 let local_content = local_resp.text().await?;
1833 log::debug!("response content: {}", local_content);
1834
1835 if !local_status.is_client_error() && !local_status.is_server_error() {
1836 match serde_json::from_str::<crate::datadogV2::model::IncidentTodoResponse>(
1837 &local_content,
1838 ) {
1839 Ok(e) => {
1840 return Ok(datadog::ResponseContent {
1841 status: local_status,
1842 content: local_content,
1843 entity: Some(e),
1844 })
1845 }
1846 Err(e) => return Err(datadog::Error::Serde(e)),
1847 };
1848 } else {
1849 let local_entity: Option<GetIncidentTodoError> =
1850 serde_json::from_str(&local_content).ok();
1851 let local_error = datadog::ResponseContent {
1852 status: local_status,
1853 content: local_content,
1854 entity: local_entity,
1855 };
1856 Err(datadog::Error::ResponseError(local_error))
1857 }
1858 }
1859
1860 pub async fn get_incident_type(
1862 &self,
1863 incident_type_id: String,
1864 ) -> Result<crate::datadogV2::model::IncidentTypeResponse, datadog::Error<GetIncidentTypeError>>
1865 {
1866 match self
1867 .get_incident_type_with_http_info(incident_type_id)
1868 .await
1869 {
1870 Ok(response_content) => {
1871 if let Some(e) = response_content.entity {
1872 Ok(e)
1873 } else {
1874 Err(datadog::Error::Serde(serde::de::Error::custom(
1875 "response content was None",
1876 )))
1877 }
1878 }
1879 Err(err) => Err(err),
1880 }
1881 }
1882
1883 pub async fn get_incident_type_with_http_info(
1885 &self,
1886 incident_type_id: String,
1887 ) -> Result<
1888 datadog::ResponseContent<crate::datadogV2::model::IncidentTypeResponse>,
1889 datadog::Error<GetIncidentTypeError>,
1890 > {
1891 let local_configuration = &self.config;
1892 let operation_id = "v2.get_incident_type";
1893 if local_configuration.is_unstable_operation_enabled(operation_id) {
1894 warn!("Using unstable operation {operation_id}");
1895 } else {
1896 let local_error = datadog::UnstableOperationDisabledError {
1897 msg: "Operation 'v2.get_incident_type' is not enabled".to_string(),
1898 };
1899 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1900 }
1901
1902 let local_client = &self.client;
1903
1904 let local_uri_str = format!(
1905 "{}/api/v2/incidents/config/types/{incident_type_id}",
1906 local_configuration.get_operation_host(operation_id),
1907 incident_type_id = datadog::urlencode(incident_type_id)
1908 );
1909 let mut local_req_builder =
1910 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1911
1912 let mut headers = HeaderMap::new();
1914 headers.insert("Accept", HeaderValue::from_static("application/json"));
1915
1916 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1918 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1919 Err(e) => {
1920 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1921 headers.insert(
1922 reqwest::header::USER_AGENT,
1923 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1924 )
1925 }
1926 };
1927
1928 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1930 headers.insert(
1931 "DD-API-KEY",
1932 HeaderValue::from_str(local_key.key.as_str())
1933 .expect("failed to parse DD-API-KEY header"),
1934 );
1935 };
1936 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1937 headers.insert(
1938 "DD-APPLICATION-KEY",
1939 HeaderValue::from_str(local_key.key.as_str())
1940 .expect("failed to parse DD-APPLICATION-KEY header"),
1941 );
1942 };
1943
1944 local_req_builder = local_req_builder.headers(headers);
1945 let local_req = local_req_builder.build()?;
1946 log::debug!("request content: {:?}", local_req.body());
1947 let local_resp = local_client.execute(local_req).await?;
1948
1949 let local_status = local_resp.status();
1950 let local_content = local_resp.text().await?;
1951 log::debug!("response content: {}", local_content);
1952
1953 if !local_status.is_client_error() && !local_status.is_server_error() {
1954 match serde_json::from_str::<crate::datadogV2::model::IncidentTypeResponse>(
1955 &local_content,
1956 ) {
1957 Ok(e) => {
1958 return Ok(datadog::ResponseContent {
1959 status: local_status,
1960 content: local_content,
1961 entity: Some(e),
1962 })
1963 }
1964 Err(e) => return Err(datadog::Error::Serde(e)),
1965 };
1966 } else {
1967 let local_entity: Option<GetIncidentTypeError> =
1968 serde_json::from_str(&local_content).ok();
1969 let local_error = datadog::ResponseContent {
1970 status: local_status,
1971 content: local_content,
1972 entity: local_entity,
1973 };
1974 Err(datadog::Error::ResponseError(local_error))
1975 }
1976 }
1977
1978 pub async fn list_incident_attachments(
1980 &self,
1981 incident_id: String,
1982 params: ListIncidentAttachmentsOptionalParams,
1983 ) -> Result<
1984 crate::datadogV2::model::IncidentAttachmentsResponse,
1985 datadog::Error<ListIncidentAttachmentsError>,
1986 > {
1987 match self
1988 .list_incident_attachments_with_http_info(incident_id, params)
1989 .await
1990 {
1991 Ok(response_content) => {
1992 if let Some(e) = response_content.entity {
1993 Ok(e)
1994 } else {
1995 Err(datadog::Error::Serde(serde::de::Error::custom(
1996 "response content was None",
1997 )))
1998 }
1999 }
2000 Err(err) => Err(err),
2001 }
2002 }
2003
2004 pub async fn list_incident_attachments_with_http_info(
2006 &self,
2007 incident_id: String,
2008 params: ListIncidentAttachmentsOptionalParams,
2009 ) -> Result<
2010 datadog::ResponseContent<crate::datadogV2::model::IncidentAttachmentsResponse>,
2011 datadog::Error<ListIncidentAttachmentsError>,
2012 > {
2013 let local_configuration = &self.config;
2014 let operation_id = "v2.list_incident_attachments";
2015 if local_configuration.is_unstable_operation_enabled(operation_id) {
2016 warn!("Using unstable operation {operation_id}");
2017 } else {
2018 let local_error = datadog::UnstableOperationDisabledError {
2019 msg: "Operation 'v2.list_incident_attachments' is not enabled".to_string(),
2020 };
2021 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2022 }
2023
2024 let include = params.include;
2026 let filter_attachment_type = params.filter_attachment_type;
2027
2028 let local_client = &self.client;
2029
2030 let local_uri_str = format!(
2031 "{}/api/v2/incidents/{incident_id}/attachments",
2032 local_configuration.get_operation_host(operation_id),
2033 incident_id = datadog::urlencode(incident_id)
2034 );
2035 let mut local_req_builder =
2036 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2037
2038 if let Some(ref local) = include {
2039 local_req_builder = local_req_builder.query(&[(
2040 "include",
2041 &local
2042 .iter()
2043 .map(|p| p.to_string())
2044 .collect::<Vec<String>>()
2045 .join(",")
2046 .to_string(),
2047 )]);
2048 };
2049 if let Some(ref local) = filter_attachment_type {
2050 local_req_builder = local_req_builder.query(&[(
2051 "filter[attachment_type]",
2052 &local
2053 .iter()
2054 .map(|p| p.to_string())
2055 .collect::<Vec<String>>()
2056 .join(",")
2057 .to_string(),
2058 )]);
2059 };
2060
2061 let mut headers = HeaderMap::new();
2063 headers.insert("Accept", HeaderValue::from_static("application/json"));
2064
2065 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2067 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2068 Err(e) => {
2069 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2070 headers.insert(
2071 reqwest::header::USER_AGENT,
2072 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2073 )
2074 }
2075 };
2076
2077 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2079 headers.insert(
2080 "DD-API-KEY",
2081 HeaderValue::from_str(local_key.key.as_str())
2082 .expect("failed to parse DD-API-KEY header"),
2083 );
2084 };
2085 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2086 headers.insert(
2087 "DD-APPLICATION-KEY",
2088 HeaderValue::from_str(local_key.key.as_str())
2089 .expect("failed to parse DD-APPLICATION-KEY header"),
2090 );
2091 };
2092
2093 local_req_builder = local_req_builder.headers(headers);
2094 let local_req = local_req_builder.build()?;
2095 log::debug!("request content: {:?}", local_req.body());
2096 let local_resp = local_client.execute(local_req).await?;
2097
2098 let local_status = local_resp.status();
2099 let local_content = local_resp.text().await?;
2100 log::debug!("response content: {}", local_content);
2101
2102 if !local_status.is_client_error() && !local_status.is_server_error() {
2103 match serde_json::from_str::<crate::datadogV2::model::IncidentAttachmentsResponse>(
2104 &local_content,
2105 ) {
2106 Ok(e) => {
2107 return Ok(datadog::ResponseContent {
2108 status: local_status,
2109 content: local_content,
2110 entity: Some(e),
2111 })
2112 }
2113 Err(e) => return Err(datadog::Error::Serde(e)),
2114 };
2115 } else {
2116 let local_entity: Option<ListIncidentAttachmentsError> =
2117 serde_json::from_str(&local_content).ok();
2118 let local_error = datadog::ResponseContent {
2119 status: local_status,
2120 content: local_content,
2121 entity: local_entity,
2122 };
2123 Err(datadog::Error::ResponseError(local_error))
2124 }
2125 }
2126
2127 pub async fn list_incident_integrations(
2129 &self,
2130 incident_id: String,
2131 ) -> Result<
2132 crate::datadogV2::model::IncidentIntegrationMetadataListResponse,
2133 datadog::Error<ListIncidentIntegrationsError>,
2134 > {
2135 match self
2136 .list_incident_integrations_with_http_info(incident_id)
2137 .await
2138 {
2139 Ok(response_content) => {
2140 if let Some(e) = response_content.entity {
2141 Ok(e)
2142 } else {
2143 Err(datadog::Error::Serde(serde::de::Error::custom(
2144 "response content was None",
2145 )))
2146 }
2147 }
2148 Err(err) => Err(err),
2149 }
2150 }
2151
2152 pub async fn list_incident_integrations_with_http_info(
2154 &self,
2155 incident_id: String,
2156 ) -> Result<
2157 datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataListResponse>,
2158 datadog::Error<ListIncidentIntegrationsError>,
2159 > {
2160 let local_configuration = &self.config;
2161 let operation_id = "v2.list_incident_integrations";
2162 if local_configuration.is_unstable_operation_enabled(operation_id) {
2163 warn!("Using unstable operation {operation_id}");
2164 } else {
2165 let local_error = datadog::UnstableOperationDisabledError {
2166 msg: "Operation 'v2.list_incident_integrations' is not enabled".to_string(),
2167 };
2168 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2169 }
2170
2171 let local_client = &self.client;
2172
2173 let local_uri_str = format!(
2174 "{}/api/v2/incidents/{incident_id}/relationships/integrations",
2175 local_configuration.get_operation_host(operation_id),
2176 incident_id = datadog::urlencode(incident_id)
2177 );
2178 let mut local_req_builder =
2179 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2180
2181 let mut headers = HeaderMap::new();
2183 headers.insert("Accept", HeaderValue::from_static("application/json"));
2184
2185 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2187 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2188 Err(e) => {
2189 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2190 headers.insert(
2191 reqwest::header::USER_AGENT,
2192 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2193 )
2194 }
2195 };
2196
2197 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2199 headers.insert(
2200 "DD-API-KEY",
2201 HeaderValue::from_str(local_key.key.as_str())
2202 .expect("failed to parse DD-API-KEY header"),
2203 );
2204 };
2205 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2206 headers.insert(
2207 "DD-APPLICATION-KEY",
2208 HeaderValue::from_str(local_key.key.as_str())
2209 .expect("failed to parse DD-APPLICATION-KEY header"),
2210 );
2211 };
2212
2213 local_req_builder = local_req_builder.headers(headers);
2214 let local_req = local_req_builder.build()?;
2215 log::debug!("request content: {:?}", local_req.body());
2216 let local_resp = local_client.execute(local_req).await?;
2217
2218 let local_status = local_resp.status();
2219 let local_content = local_resp.text().await?;
2220 log::debug!("response content: {}", local_content);
2221
2222 if !local_status.is_client_error() && !local_status.is_server_error() {
2223 match serde_json::from_str::<
2224 crate::datadogV2::model::IncidentIntegrationMetadataListResponse,
2225 >(&local_content)
2226 {
2227 Ok(e) => {
2228 return Ok(datadog::ResponseContent {
2229 status: local_status,
2230 content: local_content,
2231 entity: Some(e),
2232 })
2233 }
2234 Err(e) => return Err(datadog::Error::Serde(e)),
2235 };
2236 } else {
2237 let local_entity: Option<ListIncidentIntegrationsError> =
2238 serde_json::from_str(&local_content).ok();
2239 let local_error = datadog::ResponseContent {
2240 status: local_status,
2241 content: local_content,
2242 entity: local_entity,
2243 };
2244 Err(datadog::Error::ResponseError(local_error))
2245 }
2246 }
2247
2248 pub async fn list_incident_todos(
2250 &self,
2251 incident_id: String,
2252 ) -> Result<
2253 crate::datadogV2::model::IncidentTodoListResponse,
2254 datadog::Error<ListIncidentTodosError>,
2255 > {
2256 match self.list_incident_todos_with_http_info(incident_id).await {
2257 Ok(response_content) => {
2258 if let Some(e) = response_content.entity {
2259 Ok(e)
2260 } else {
2261 Err(datadog::Error::Serde(serde::de::Error::custom(
2262 "response content was None",
2263 )))
2264 }
2265 }
2266 Err(err) => Err(err),
2267 }
2268 }
2269
2270 pub async fn list_incident_todos_with_http_info(
2272 &self,
2273 incident_id: String,
2274 ) -> Result<
2275 datadog::ResponseContent<crate::datadogV2::model::IncidentTodoListResponse>,
2276 datadog::Error<ListIncidentTodosError>,
2277 > {
2278 let local_configuration = &self.config;
2279 let operation_id = "v2.list_incident_todos";
2280 if local_configuration.is_unstable_operation_enabled(operation_id) {
2281 warn!("Using unstable operation {operation_id}");
2282 } else {
2283 let local_error = datadog::UnstableOperationDisabledError {
2284 msg: "Operation 'v2.list_incident_todos' is not enabled".to_string(),
2285 };
2286 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2287 }
2288
2289 let local_client = &self.client;
2290
2291 let local_uri_str = format!(
2292 "{}/api/v2/incidents/{incident_id}/relationships/todos",
2293 local_configuration.get_operation_host(operation_id),
2294 incident_id = datadog::urlencode(incident_id)
2295 );
2296 let mut local_req_builder =
2297 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2298
2299 let mut headers = HeaderMap::new();
2301 headers.insert("Accept", HeaderValue::from_static("application/json"));
2302
2303 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2305 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2306 Err(e) => {
2307 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2308 headers.insert(
2309 reqwest::header::USER_AGENT,
2310 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2311 )
2312 }
2313 };
2314
2315 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2317 headers.insert(
2318 "DD-API-KEY",
2319 HeaderValue::from_str(local_key.key.as_str())
2320 .expect("failed to parse DD-API-KEY header"),
2321 );
2322 };
2323 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2324 headers.insert(
2325 "DD-APPLICATION-KEY",
2326 HeaderValue::from_str(local_key.key.as_str())
2327 .expect("failed to parse DD-APPLICATION-KEY header"),
2328 );
2329 };
2330
2331 local_req_builder = local_req_builder.headers(headers);
2332 let local_req = local_req_builder.build()?;
2333 log::debug!("request content: {:?}", local_req.body());
2334 let local_resp = local_client.execute(local_req).await?;
2335
2336 let local_status = local_resp.status();
2337 let local_content = local_resp.text().await?;
2338 log::debug!("response content: {}", local_content);
2339
2340 if !local_status.is_client_error() && !local_status.is_server_error() {
2341 match serde_json::from_str::<crate::datadogV2::model::IncidentTodoListResponse>(
2342 &local_content,
2343 ) {
2344 Ok(e) => {
2345 return Ok(datadog::ResponseContent {
2346 status: local_status,
2347 content: local_content,
2348 entity: Some(e),
2349 })
2350 }
2351 Err(e) => return Err(datadog::Error::Serde(e)),
2352 };
2353 } else {
2354 let local_entity: Option<ListIncidentTodosError> =
2355 serde_json::from_str(&local_content).ok();
2356 let local_error = datadog::ResponseContent {
2357 status: local_status,
2358 content: local_content,
2359 entity: local_entity,
2360 };
2361 Err(datadog::Error::ResponseError(local_error))
2362 }
2363 }
2364
2365 pub async fn list_incident_types(
2367 &self,
2368 params: ListIncidentTypesOptionalParams,
2369 ) -> Result<
2370 crate::datadogV2::model::IncidentTypeListResponse,
2371 datadog::Error<ListIncidentTypesError>,
2372 > {
2373 match self.list_incident_types_with_http_info(params).await {
2374 Ok(response_content) => {
2375 if let Some(e) = response_content.entity {
2376 Ok(e)
2377 } else {
2378 Err(datadog::Error::Serde(serde::de::Error::custom(
2379 "response content was None",
2380 )))
2381 }
2382 }
2383 Err(err) => Err(err),
2384 }
2385 }
2386
2387 pub async fn list_incident_types_with_http_info(
2389 &self,
2390 params: ListIncidentTypesOptionalParams,
2391 ) -> Result<
2392 datadog::ResponseContent<crate::datadogV2::model::IncidentTypeListResponse>,
2393 datadog::Error<ListIncidentTypesError>,
2394 > {
2395 let local_configuration = &self.config;
2396 let operation_id = "v2.list_incident_types";
2397 if local_configuration.is_unstable_operation_enabled(operation_id) {
2398 warn!("Using unstable operation {operation_id}");
2399 } else {
2400 let local_error = datadog::UnstableOperationDisabledError {
2401 msg: "Operation 'v2.list_incident_types' is not enabled".to_string(),
2402 };
2403 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2404 }
2405
2406 let include_deleted = params.include_deleted;
2408
2409 let local_client = &self.client;
2410
2411 let local_uri_str = format!(
2412 "{}/api/v2/incidents/config/types",
2413 local_configuration.get_operation_host(operation_id)
2414 );
2415 let mut local_req_builder =
2416 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2417
2418 if let Some(ref local_query_param) = include_deleted {
2419 local_req_builder =
2420 local_req_builder.query(&[("include_deleted", &local_query_param.to_string())]);
2421 };
2422
2423 let mut headers = HeaderMap::new();
2425 headers.insert("Accept", HeaderValue::from_static("application/json"));
2426
2427 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2429 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2430 Err(e) => {
2431 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2432 headers.insert(
2433 reqwest::header::USER_AGENT,
2434 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2435 )
2436 }
2437 };
2438
2439 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2441 headers.insert(
2442 "DD-API-KEY",
2443 HeaderValue::from_str(local_key.key.as_str())
2444 .expect("failed to parse DD-API-KEY header"),
2445 );
2446 };
2447 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2448 headers.insert(
2449 "DD-APPLICATION-KEY",
2450 HeaderValue::from_str(local_key.key.as_str())
2451 .expect("failed to parse DD-APPLICATION-KEY header"),
2452 );
2453 };
2454
2455 local_req_builder = local_req_builder.headers(headers);
2456 let local_req = local_req_builder.build()?;
2457 log::debug!("request content: {:?}", local_req.body());
2458 let local_resp = local_client.execute(local_req).await?;
2459
2460 let local_status = local_resp.status();
2461 let local_content = local_resp.text().await?;
2462 log::debug!("response content: {}", local_content);
2463
2464 if !local_status.is_client_error() && !local_status.is_server_error() {
2465 match serde_json::from_str::<crate::datadogV2::model::IncidentTypeListResponse>(
2466 &local_content,
2467 ) {
2468 Ok(e) => {
2469 return Ok(datadog::ResponseContent {
2470 status: local_status,
2471 content: local_content,
2472 entity: Some(e),
2473 })
2474 }
2475 Err(e) => return Err(datadog::Error::Serde(e)),
2476 };
2477 } else {
2478 let local_entity: Option<ListIncidentTypesError> =
2479 serde_json::from_str(&local_content).ok();
2480 let local_error = datadog::ResponseContent {
2481 status: local_status,
2482 content: local_content,
2483 entity: local_entity,
2484 };
2485 Err(datadog::Error::ResponseError(local_error))
2486 }
2487 }
2488
2489 pub async fn list_incidents(
2491 &self,
2492 params: ListIncidentsOptionalParams,
2493 ) -> Result<crate::datadogV2::model::IncidentsResponse, datadog::Error<ListIncidentsError>>
2494 {
2495 match self.list_incidents_with_http_info(params).await {
2496 Ok(response_content) => {
2497 if let Some(e) = response_content.entity {
2498 Ok(e)
2499 } else {
2500 Err(datadog::Error::Serde(serde::de::Error::custom(
2501 "response content was None",
2502 )))
2503 }
2504 }
2505 Err(err) => Err(err),
2506 }
2507 }
2508
2509 pub fn list_incidents_with_pagination(
2510 &self,
2511 mut params: ListIncidentsOptionalParams,
2512 ) -> impl Stream<
2513 Item = Result<
2514 crate::datadogV2::model::IncidentResponseData,
2515 datadog::Error<ListIncidentsError>,
2516 >,
2517 > + '_ {
2518 try_stream! {
2519 let mut page_size: i64 = 10;
2520 if params.page_size.is_none() {
2521 params.page_size = Some(page_size);
2522 } else {
2523 page_size = params.page_size.unwrap().clone();
2524 }
2525 loop {
2526 let resp = self.list_incidents(params.clone()).await?;
2527
2528 let r = resp.data;
2529 let count = r.len();
2530 for team in r {
2531 yield team;
2532 }
2533
2534 if count < page_size as usize {
2535 break;
2536 }
2537 if params.page_offset.is_none() {
2538 params.page_offset = Some(page_size.clone());
2539 } else {
2540 params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
2541 }
2542 }
2543 }
2544 }
2545
2546 pub async fn list_incidents_with_http_info(
2548 &self,
2549 params: ListIncidentsOptionalParams,
2550 ) -> Result<
2551 datadog::ResponseContent<crate::datadogV2::model::IncidentsResponse>,
2552 datadog::Error<ListIncidentsError>,
2553 > {
2554 let local_configuration = &self.config;
2555 let operation_id = "v2.list_incidents";
2556 if local_configuration.is_unstable_operation_enabled(operation_id) {
2557 warn!("Using unstable operation {operation_id}");
2558 } else {
2559 let local_error = datadog::UnstableOperationDisabledError {
2560 msg: "Operation 'v2.list_incidents' is not enabled".to_string(),
2561 };
2562 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2563 }
2564
2565 let include = params.include;
2567 let page_size = params.page_size;
2568 let page_offset = params.page_offset;
2569
2570 let local_client = &self.client;
2571
2572 let local_uri_str = format!(
2573 "{}/api/v2/incidents",
2574 local_configuration.get_operation_host(operation_id)
2575 );
2576 let mut local_req_builder =
2577 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2578
2579 if let Some(ref local) = include {
2580 local_req_builder = local_req_builder.query(&[(
2581 "include",
2582 &local
2583 .iter()
2584 .map(|p| p.to_string())
2585 .collect::<Vec<String>>()
2586 .join(",")
2587 .to_string(),
2588 )]);
2589 };
2590 if let Some(ref local_query_param) = page_size {
2591 local_req_builder =
2592 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
2593 };
2594 if let Some(ref local_query_param) = page_offset {
2595 local_req_builder =
2596 local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
2597 };
2598
2599 let mut headers = HeaderMap::new();
2601 headers.insert("Accept", HeaderValue::from_static("application/json"));
2602
2603 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2605 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2606 Err(e) => {
2607 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2608 headers.insert(
2609 reqwest::header::USER_AGENT,
2610 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2611 )
2612 }
2613 };
2614
2615 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2617 headers.insert(
2618 "DD-API-KEY",
2619 HeaderValue::from_str(local_key.key.as_str())
2620 .expect("failed to parse DD-API-KEY header"),
2621 );
2622 };
2623 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2624 headers.insert(
2625 "DD-APPLICATION-KEY",
2626 HeaderValue::from_str(local_key.key.as_str())
2627 .expect("failed to parse DD-APPLICATION-KEY header"),
2628 );
2629 };
2630
2631 local_req_builder = local_req_builder.headers(headers);
2632 let local_req = local_req_builder.build()?;
2633 log::debug!("request content: {:?}", local_req.body());
2634 let local_resp = local_client.execute(local_req).await?;
2635
2636 let local_status = local_resp.status();
2637 let local_content = local_resp.text().await?;
2638 log::debug!("response content: {}", local_content);
2639
2640 if !local_status.is_client_error() && !local_status.is_server_error() {
2641 match serde_json::from_str::<crate::datadogV2::model::IncidentsResponse>(&local_content)
2642 {
2643 Ok(e) => {
2644 return Ok(datadog::ResponseContent {
2645 status: local_status,
2646 content: local_content,
2647 entity: Some(e),
2648 })
2649 }
2650 Err(e) => return Err(datadog::Error::Serde(e)),
2651 };
2652 } else {
2653 let local_entity: Option<ListIncidentsError> =
2654 serde_json::from_str(&local_content).ok();
2655 let local_error = datadog::ResponseContent {
2656 status: local_status,
2657 content: local_content,
2658 entity: local_entity,
2659 };
2660 Err(datadog::Error::ResponseError(local_error))
2661 }
2662 }
2663
2664 pub async fn search_incidents(
2666 &self,
2667 query: String,
2668 params: SearchIncidentsOptionalParams,
2669 ) -> Result<crate::datadogV2::model::IncidentSearchResponse, datadog::Error<SearchIncidentsError>>
2670 {
2671 match self.search_incidents_with_http_info(query, params).await {
2672 Ok(response_content) => {
2673 if let Some(e) = response_content.entity {
2674 Ok(e)
2675 } else {
2676 Err(datadog::Error::Serde(serde::de::Error::custom(
2677 "response content was None",
2678 )))
2679 }
2680 }
2681 Err(err) => Err(err),
2682 }
2683 }
2684
2685 pub fn search_incidents_with_pagination(
2686 &self,
2687 query: String,
2688 mut params: SearchIncidentsOptionalParams,
2689 ) -> impl Stream<
2690 Item = Result<
2691 crate::datadogV2::model::IncidentSearchResponseIncidentsData,
2692 datadog::Error<SearchIncidentsError>,
2693 >,
2694 > + '_ {
2695 try_stream! {
2696 let mut page_size: i64 = 10;
2697 if params.page_size.is_none() {
2698 params.page_size = Some(page_size);
2699 } else {
2700 page_size = params.page_size.unwrap().clone();
2701 }
2702 loop {
2703 let resp = self.search_incidents( query.clone(),params.clone()).await?;
2704 let Some(attributes) = resp.data.attributes else { break };
2705
2706 let r = attributes.incidents;
2707 let count = r.len();
2708 for team in r {
2709 yield team;
2710 }
2711
2712 if count < page_size as usize {
2713 break;
2714 }
2715 if params.page_offset.is_none() {
2716 params.page_offset = Some(page_size.clone());
2717 } else {
2718 params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
2719 }
2720 }
2721 }
2722 }
2723
2724 pub async fn search_incidents_with_http_info(
2726 &self,
2727 query: String,
2728 params: SearchIncidentsOptionalParams,
2729 ) -> Result<
2730 datadog::ResponseContent<crate::datadogV2::model::IncidentSearchResponse>,
2731 datadog::Error<SearchIncidentsError>,
2732 > {
2733 let local_configuration = &self.config;
2734 let operation_id = "v2.search_incidents";
2735 if local_configuration.is_unstable_operation_enabled(operation_id) {
2736 warn!("Using unstable operation {operation_id}");
2737 } else {
2738 let local_error = datadog::UnstableOperationDisabledError {
2739 msg: "Operation 'v2.search_incidents' is not enabled".to_string(),
2740 };
2741 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2742 }
2743
2744 let include = params.include;
2746 let sort = params.sort;
2747 let page_size = params.page_size;
2748 let page_offset = params.page_offset;
2749
2750 let local_client = &self.client;
2751
2752 let local_uri_str = format!(
2753 "{}/api/v2/incidents/search",
2754 local_configuration.get_operation_host(operation_id)
2755 );
2756 let mut local_req_builder =
2757 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
2758
2759 local_req_builder = local_req_builder.query(&[("query", &query.to_string())]);
2760 if let Some(ref local_query_param) = include {
2761 local_req_builder =
2762 local_req_builder.query(&[("include", &local_query_param.to_string())]);
2763 };
2764 if let Some(ref local_query_param) = sort {
2765 local_req_builder =
2766 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
2767 };
2768 if let Some(ref local_query_param) = page_size {
2769 local_req_builder =
2770 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
2771 };
2772 if let Some(ref local_query_param) = page_offset {
2773 local_req_builder =
2774 local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
2775 };
2776
2777 let mut headers = HeaderMap::new();
2779 headers.insert("Accept", HeaderValue::from_static("application/json"));
2780
2781 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2783 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2784 Err(e) => {
2785 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2786 headers.insert(
2787 reqwest::header::USER_AGENT,
2788 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2789 )
2790 }
2791 };
2792
2793 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2795 headers.insert(
2796 "DD-API-KEY",
2797 HeaderValue::from_str(local_key.key.as_str())
2798 .expect("failed to parse DD-API-KEY header"),
2799 );
2800 };
2801 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2802 headers.insert(
2803 "DD-APPLICATION-KEY",
2804 HeaderValue::from_str(local_key.key.as_str())
2805 .expect("failed to parse DD-APPLICATION-KEY header"),
2806 );
2807 };
2808
2809 local_req_builder = local_req_builder.headers(headers);
2810 let local_req = local_req_builder.build()?;
2811 log::debug!("request content: {:?}", local_req.body());
2812 let local_resp = local_client.execute(local_req).await?;
2813
2814 let local_status = local_resp.status();
2815 let local_content = local_resp.text().await?;
2816 log::debug!("response content: {}", local_content);
2817
2818 if !local_status.is_client_error() && !local_status.is_server_error() {
2819 match serde_json::from_str::<crate::datadogV2::model::IncidentSearchResponse>(
2820 &local_content,
2821 ) {
2822 Ok(e) => {
2823 return Ok(datadog::ResponseContent {
2824 status: local_status,
2825 content: local_content,
2826 entity: Some(e),
2827 })
2828 }
2829 Err(e) => return Err(datadog::Error::Serde(e)),
2830 };
2831 } else {
2832 let local_entity: Option<SearchIncidentsError> =
2833 serde_json::from_str(&local_content).ok();
2834 let local_error = datadog::ResponseContent {
2835 status: local_status,
2836 content: local_content,
2837 entity: local_entity,
2838 };
2839 Err(datadog::Error::ResponseError(local_error))
2840 }
2841 }
2842
2843 pub async fn update_incident(
2845 &self,
2846 incident_id: String,
2847 body: crate::datadogV2::model::IncidentUpdateRequest,
2848 params: UpdateIncidentOptionalParams,
2849 ) -> Result<crate::datadogV2::model::IncidentResponse, datadog::Error<UpdateIncidentError>>
2850 {
2851 match self
2852 .update_incident_with_http_info(incident_id, body, params)
2853 .await
2854 {
2855 Ok(response_content) => {
2856 if let Some(e) = response_content.entity {
2857 Ok(e)
2858 } else {
2859 Err(datadog::Error::Serde(serde::de::Error::custom(
2860 "response content was None",
2861 )))
2862 }
2863 }
2864 Err(err) => Err(err),
2865 }
2866 }
2867
2868 pub async fn update_incident_with_http_info(
2870 &self,
2871 incident_id: String,
2872 body: crate::datadogV2::model::IncidentUpdateRequest,
2873 params: UpdateIncidentOptionalParams,
2874 ) -> Result<
2875 datadog::ResponseContent<crate::datadogV2::model::IncidentResponse>,
2876 datadog::Error<UpdateIncidentError>,
2877 > {
2878 let local_configuration = &self.config;
2879 let operation_id = "v2.update_incident";
2880 if local_configuration.is_unstable_operation_enabled(operation_id) {
2881 warn!("Using unstable operation {operation_id}");
2882 } else {
2883 let local_error = datadog::UnstableOperationDisabledError {
2884 msg: "Operation 'v2.update_incident' is not enabled".to_string(),
2885 };
2886 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2887 }
2888
2889 let include = params.include;
2891
2892 let local_client = &self.client;
2893
2894 let local_uri_str = format!(
2895 "{}/api/v2/incidents/{incident_id}",
2896 local_configuration.get_operation_host(operation_id),
2897 incident_id = datadog::urlencode(incident_id)
2898 );
2899 let mut local_req_builder =
2900 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2901
2902 if let Some(ref local) = include {
2903 local_req_builder = local_req_builder.query(&[(
2904 "include",
2905 &local
2906 .iter()
2907 .map(|p| p.to_string())
2908 .collect::<Vec<String>>()
2909 .join(",")
2910 .to_string(),
2911 )]);
2912 };
2913
2914 let mut headers = HeaderMap::new();
2916 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2917 headers.insert("Accept", HeaderValue::from_static("application/json"));
2918
2919 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2921 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2922 Err(e) => {
2923 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2924 headers.insert(
2925 reqwest::header::USER_AGENT,
2926 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2927 )
2928 }
2929 };
2930
2931 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2933 headers.insert(
2934 "DD-API-KEY",
2935 HeaderValue::from_str(local_key.key.as_str())
2936 .expect("failed to parse DD-API-KEY header"),
2937 );
2938 };
2939 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2940 headers.insert(
2941 "DD-APPLICATION-KEY",
2942 HeaderValue::from_str(local_key.key.as_str())
2943 .expect("failed to parse DD-APPLICATION-KEY header"),
2944 );
2945 };
2946
2947 let output = Vec::new();
2949 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2950 if body.serialize(&mut ser).is_ok() {
2951 if let Some(content_encoding) = headers.get("Content-Encoding") {
2952 match content_encoding.to_str().unwrap_or_default() {
2953 "gzip" => {
2954 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2955 let _ = enc.write_all(ser.into_inner().as_slice());
2956 match enc.finish() {
2957 Ok(buf) => {
2958 local_req_builder = local_req_builder.body(buf);
2959 }
2960 Err(e) => return Err(datadog::Error::Io(e)),
2961 }
2962 }
2963 "deflate" => {
2964 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2965 let _ = enc.write_all(ser.into_inner().as_slice());
2966 match enc.finish() {
2967 Ok(buf) => {
2968 local_req_builder = local_req_builder.body(buf);
2969 }
2970 Err(e) => return Err(datadog::Error::Io(e)),
2971 }
2972 }
2973 "zstd1" => {
2974 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2975 let _ = enc.write_all(ser.into_inner().as_slice());
2976 match enc.finish() {
2977 Ok(buf) => {
2978 local_req_builder = local_req_builder.body(buf);
2979 }
2980 Err(e) => return Err(datadog::Error::Io(e)),
2981 }
2982 }
2983 _ => {
2984 local_req_builder = local_req_builder.body(ser.into_inner());
2985 }
2986 }
2987 } else {
2988 local_req_builder = local_req_builder.body(ser.into_inner());
2989 }
2990 }
2991
2992 local_req_builder = local_req_builder.headers(headers);
2993 let local_req = local_req_builder.build()?;
2994 log::debug!("request content: {:?}", local_req.body());
2995 let local_resp = local_client.execute(local_req).await?;
2996
2997 let local_status = local_resp.status();
2998 let local_content = local_resp.text().await?;
2999 log::debug!("response content: {}", local_content);
3000
3001 if !local_status.is_client_error() && !local_status.is_server_error() {
3002 match serde_json::from_str::<crate::datadogV2::model::IncidentResponse>(&local_content)
3003 {
3004 Ok(e) => {
3005 return Ok(datadog::ResponseContent {
3006 status: local_status,
3007 content: local_content,
3008 entity: Some(e),
3009 })
3010 }
3011 Err(e) => return Err(datadog::Error::Serde(e)),
3012 };
3013 } else {
3014 let local_entity: Option<UpdateIncidentError> =
3015 serde_json::from_str(&local_content).ok();
3016 let local_error = datadog::ResponseContent {
3017 status: local_status,
3018 content: local_content,
3019 entity: local_entity,
3020 };
3021 Err(datadog::Error::ResponseError(local_error))
3022 }
3023 }
3024
3025 pub async fn update_incident_attachments(
3027 &self,
3028 incident_id: String,
3029 body: crate::datadogV2::model::IncidentAttachmentUpdateRequest,
3030 params: UpdateIncidentAttachmentsOptionalParams,
3031 ) -> Result<
3032 crate::datadogV2::model::IncidentAttachmentUpdateResponse,
3033 datadog::Error<UpdateIncidentAttachmentsError>,
3034 > {
3035 match self
3036 .update_incident_attachments_with_http_info(incident_id, body, params)
3037 .await
3038 {
3039 Ok(response_content) => {
3040 if let Some(e) = response_content.entity {
3041 Ok(e)
3042 } else {
3043 Err(datadog::Error::Serde(serde::de::Error::custom(
3044 "response content was None",
3045 )))
3046 }
3047 }
3048 Err(err) => Err(err),
3049 }
3050 }
3051
3052 pub async fn update_incident_attachments_with_http_info(
3054 &self,
3055 incident_id: String,
3056 body: crate::datadogV2::model::IncidentAttachmentUpdateRequest,
3057 params: UpdateIncidentAttachmentsOptionalParams,
3058 ) -> Result<
3059 datadog::ResponseContent<crate::datadogV2::model::IncidentAttachmentUpdateResponse>,
3060 datadog::Error<UpdateIncidentAttachmentsError>,
3061 > {
3062 let local_configuration = &self.config;
3063 let operation_id = "v2.update_incident_attachments";
3064 if local_configuration.is_unstable_operation_enabled(operation_id) {
3065 warn!("Using unstable operation {operation_id}");
3066 } else {
3067 let local_error = datadog::UnstableOperationDisabledError {
3068 msg: "Operation 'v2.update_incident_attachments' is not enabled".to_string(),
3069 };
3070 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3071 }
3072
3073 let include = params.include;
3075
3076 let local_client = &self.client;
3077
3078 let local_uri_str = format!(
3079 "{}/api/v2/incidents/{incident_id}/attachments",
3080 local_configuration.get_operation_host(operation_id),
3081 incident_id = datadog::urlencode(incident_id)
3082 );
3083 let mut local_req_builder =
3084 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
3085
3086 if let Some(ref local) = include {
3087 local_req_builder = local_req_builder.query(&[(
3088 "include",
3089 &local
3090 .iter()
3091 .map(|p| p.to_string())
3092 .collect::<Vec<String>>()
3093 .join(",")
3094 .to_string(),
3095 )]);
3096 };
3097
3098 let mut headers = HeaderMap::new();
3100 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
3101 headers.insert("Accept", HeaderValue::from_static("application/json"));
3102
3103 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3105 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3106 Err(e) => {
3107 log::warn!("Failed to parse user agent header: {e}, falling back to default");
3108 headers.insert(
3109 reqwest::header::USER_AGENT,
3110 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3111 )
3112 }
3113 };
3114
3115 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3117 headers.insert(
3118 "DD-API-KEY",
3119 HeaderValue::from_str(local_key.key.as_str())
3120 .expect("failed to parse DD-API-KEY header"),
3121 );
3122 };
3123 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3124 headers.insert(
3125 "DD-APPLICATION-KEY",
3126 HeaderValue::from_str(local_key.key.as_str())
3127 .expect("failed to parse DD-APPLICATION-KEY header"),
3128 );
3129 };
3130
3131 let output = Vec::new();
3133 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
3134 if body.serialize(&mut ser).is_ok() {
3135 if let Some(content_encoding) = headers.get("Content-Encoding") {
3136 match content_encoding.to_str().unwrap_or_default() {
3137 "gzip" => {
3138 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
3139 let _ = enc.write_all(ser.into_inner().as_slice());
3140 match enc.finish() {
3141 Ok(buf) => {
3142 local_req_builder = local_req_builder.body(buf);
3143 }
3144 Err(e) => return Err(datadog::Error::Io(e)),
3145 }
3146 }
3147 "deflate" => {
3148 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
3149 let _ = enc.write_all(ser.into_inner().as_slice());
3150 match enc.finish() {
3151 Ok(buf) => {
3152 local_req_builder = local_req_builder.body(buf);
3153 }
3154 Err(e) => return Err(datadog::Error::Io(e)),
3155 }
3156 }
3157 "zstd1" => {
3158 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
3159 let _ = enc.write_all(ser.into_inner().as_slice());
3160 match enc.finish() {
3161 Ok(buf) => {
3162 local_req_builder = local_req_builder.body(buf);
3163 }
3164 Err(e) => return Err(datadog::Error::Io(e)),
3165 }
3166 }
3167 _ => {
3168 local_req_builder = local_req_builder.body(ser.into_inner());
3169 }
3170 }
3171 } else {
3172 local_req_builder = local_req_builder.body(ser.into_inner());
3173 }
3174 }
3175
3176 local_req_builder = local_req_builder.headers(headers);
3177 let local_req = local_req_builder.build()?;
3178 log::debug!("request content: {:?}", local_req.body());
3179 let local_resp = local_client.execute(local_req).await?;
3180
3181 let local_status = local_resp.status();
3182 let local_content = local_resp.text().await?;
3183 log::debug!("response content: {}", local_content);
3184
3185 if !local_status.is_client_error() && !local_status.is_server_error() {
3186 match serde_json::from_str::<crate::datadogV2::model::IncidentAttachmentUpdateResponse>(
3187 &local_content,
3188 ) {
3189 Ok(e) => {
3190 return Ok(datadog::ResponseContent {
3191 status: local_status,
3192 content: local_content,
3193 entity: Some(e),
3194 })
3195 }
3196 Err(e) => return Err(datadog::Error::Serde(e)),
3197 };
3198 } else {
3199 let local_entity: Option<UpdateIncidentAttachmentsError> =
3200 serde_json::from_str(&local_content).ok();
3201 let local_error = datadog::ResponseContent {
3202 status: local_status,
3203 content: local_content,
3204 entity: local_entity,
3205 };
3206 Err(datadog::Error::ResponseError(local_error))
3207 }
3208 }
3209
3210 pub async fn update_incident_integration(
3212 &self,
3213 incident_id: String,
3214 integration_metadata_id: String,
3215 body: crate::datadogV2::model::IncidentIntegrationMetadataPatchRequest,
3216 ) -> Result<
3217 crate::datadogV2::model::IncidentIntegrationMetadataResponse,
3218 datadog::Error<UpdateIncidentIntegrationError>,
3219 > {
3220 match self
3221 .update_incident_integration_with_http_info(incident_id, integration_metadata_id, body)
3222 .await
3223 {
3224 Ok(response_content) => {
3225 if let Some(e) = response_content.entity {
3226 Ok(e)
3227 } else {
3228 Err(datadog::Error::Serde(serde::de::Error::custom(
3229 "response content was None",
3230 )))
3231 }
3232 }
3233 Err(err) => Err(err),
3234 }
3235 }
3236
3237 pub async fn update_incident_integration_with_http_info(
3239 &self,
3240 incident_id: String,
3241 integration_metadata_id: String,
3242 body: crate::datadogV2::model::IncidentIntegrationMetadataPatchRequest,
3243 ) -> Result<
3244 datadog::ResponseContent<crate::datadogV2::model::IncidentIntegrationMetadataResponse>,
3245 datadog::Error<UpdateIncidentIntegrationError>,
3246 > {
3247 let local_configuration = &self.config;
3248 let operation_id = "v2.update_incident_integration";
3249 if local_configuration.is_unstable_operation_enabled(operation_id) {
3250 warn!("Using unstable operation {operation_id}");
3251 } else {
3252 let local_error = datadog::UnstableOperationDisabledError {
3253 msg: "Operation 'v2.update_incident_integration' is not enabled".to_string(),
3254 };
3255 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3256 }
3257
3258 let local_client = &self.client;
3259
3260 let local_uri_str = format!(
3261 "{}/api/v2/incidents/{incident_id}/relationships/integrations/{integration_metadata_id}",
3262 local_configuration.get_operation_host(operation_id), incident_id=
3263 datadog::urlencode(incident_id)
3264 , integration_metadata_id=
3265 datadog::urlencode(integration_metadata_id)
3266 );
3267 let mut local_req_builder =
3268 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
3269
3270 let mut headers = HeaderMap::new();
3272 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
3273 headers.insert("Accept", HeaderValue::from_static("application/json"));
3274
3275 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3277 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3278 Err(e) => {
3279 log::warn!("Failed to parse user agent header: {e}, falling back to default");
3280 headers.insert(
3281 reqwest::header::USER_AGENT,
3282 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3283 )
3284 }
3285 };
3286
3287 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3289 headers.insert(
3290 "DD-API-KEY",
3291 HeaderValue::from_str(local_key.key.as_str())
3292 .expect("failed to parse DD-API-KEY header"),
3293 );
3294 };
3295 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3296 headers.insert(
3297 "DD-APPLICATION-KEY",
3298 HeaderValue::from_str(local_key.key.as_str())
3299 .expect("failed to parse DD-APPLICATION-KEY header"),
3300 );
3301 };
3302
3303 let output = Vec::new();
3305 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
3306 if body.serialize(&mut ser).is_ok() {
3307 if let Some(content_encoding) = headers.get("Content-Encoding") {
3308 match content_encoding.to_str().unwrap_or_default() {
3309 "gzip" => {
3310 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
3311 let _ = enc.write_all(ser.into_inner().as_slice());
3312 match enc.finish() {
3313 Ok(buf) => {
3314 local_req_builder = local_req_builder.body(buf);
3315 }
3316 Err(e) => return Err(datadog::Error::Io(e)),
3317 }
3318 }
3319 "deflate" => {
3320 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
3321 let _ = enc.write_all(ser.into_inner().as_slice());
3322 match enc.finish() {
3323 Ok(buf) => {
3324 local_req_builder = local_req_builder.body(buf);
3325 }
3326 Err(e) => return Err(datadog::Error::Io(e)),
3327 }
3328 }
3329 "zstd1" => {
3330 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
3331 let _ = enc.write_all(ser.into_inner().as_slice());
3332 match enc.finish() {
3333 Ok(buf) => {
3334 local_req_builder = local_req_builder.body(buf);
3335 }
3336 Err(e) => return Err(datadog::Error::Io(e)),
3337 }
3338 }
3339 _ => {
3340 local_req_builder = local_req_builder.body(ser.into_inner());
3341 }
3342 }
3343 } else {
3344 local_req_builder = local_req_builder.body(ser.into_inner());
3345 }
3346 }
3347
3348 local_req_builder = local_req_builder.headers(headers);
3349 let local_req = local_req_builder.build()?;
3350 log::debug!("request content: {:?}", local_req.body());
3351 let local_resp = local_client.execute(local_req).await?;
3352
3353 let local_status = local_resp.status();
3354 let local_content = local_resp.text().await?;
3355 log::debug!("response content: {}", local_content);
3356
3357 if !local_status.is_client_error() && !local_status.is_server_error() {
3358 match serde_json::from_str::<crate::datadogV2::model::IncidentIntegrationMetadataResponse>(
3359 &local_content,
3360 ) {
3361 Ok(e) => {
3362 return Ok(datadog::ResponseContent {
3363 status: local_status,
3364 content: local_content,
3365 entity: Some(e),
3366 })
3367 }
3368 Err(e) => return Err(datadog::Error::Serde(e)),
3369 };
3370 } else {
3371 let local_entity: Option<UpdateIncidentIntegrationError> =
3372 serde_json::from_str(&local_content).ok();
3373 let local_error = datadog::ResponseContent {
3374 status: local_status,
3375 content: local_content,
3376 entity: local_entity,
3377 };
3378 Err(datadog::Error::ResponseError(local_error))
3379 }
3380 }
3381
3382 pub async fn update_incident_todo(
3384 &self,
3385 incident_id: String,
3386 todo_id: String,
3387 body: crate::datadogV2::model::IncidentTodoPatchRequest,
3388 ) -> Result<
3389 crate::datadogV2::model::IncidentTodoResponse,
3390 datadog::Error<UpdateIncidentTodoError>,
3391 > {
3392 match self
3393 .update_incident_todo_with_http_info(incident_id, todo_id, body)
3394 .await
3395 {
3396 Ok(response_content) => {
3397 if let Some(e) = response_content.entity {
3398 Ok(e)
3399 } else {
3400 Err(datadog::Error::Serde(serde::de::Error::custom(
3401 "response content was None",
3402 )))
3403 }
3404 }
3405 Err(err) => Err(err),
3406 }
3407 }
3408
3409 pub async fn update_incident_todo_with_http_info(
3411 &self,
3412 incident_id: String,
3413 todo_id: String,
3414 body: crate::datadogV2::model::IncidentTodoPatchRequest,
3415 ) -> Result<
3416 datadog::ResponseContent<crate::datadogV2::model::IncidentTodoResponse>,
3417 datadog::Error<UpdateIncidentTodoError>,
3418 > {
3419 let local_configuration = &self.config;
3420 let operation_id = "v2.update_incident_todo";
3421 if local_configuration.is_unstable_operation_enabled(operation_id) {
3422 warn!("Using unstable operation {operation_id}");
3423 } else {
3424 let local_error = datadog::UnstableOperationDisabledError {
3425 msg: "Operation 'v2.update_incident_todo' is not enabled".to_string(),
3426 };
3427 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3428 }
3429
3430 let local_client = &self.client;
3431
3432 let local_uri_str = format!(
3433 "{}/api/v2/incidents/{incident_id}/relationships/todos/{todo_id}",
3434 local_configuration.get_operation_host(operation_id),
3435 incident_id = datadog::urlencode(incident_id),
3436 todo_id = datadog::urlencode(todo_id)
3437 );
3438 let mut local_req_builder =
3439 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
3440
3441 let mut headers = HeaderMap::new();
3443 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
3444 headers.insert("Accept", HeaderValue::from_static("application/json"));
3445
3446 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3448 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3449 Err(e) => {
3450 log::warn!("Failed to parse user agent header: {e}, falling back to default");
3451 headers.insert(
3452 reqwest::header::USER_AGENT,
3453 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3454 )
3455 }
3456 };
3457
3458 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3460 headers.insert(
3461 "DD-API-KEY",
3462 HeaderValue::from_str(local_key.key.as_str())
3463 .expect("failed to parse DD-API-KEY header"),
3464 );
3465 };
3466 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3467 headers.insert(
3468 "DD-APPLICATION-KEY",
3469 HeaderValue::from_str(local_key.key.as_str())
3470 .expect("failed to parse DD-APPLICATION-KEY header"),
3471 );
3472 };
3473
3474 let output = Vec::new();
3476 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
3477 if body.serialize(&mut ser).is_ok() {
3478 if let Some(content_encoding) = headers.get("Content-Encoding") {
3479 match content_encoding.to_str().unwrap_or_default() {
3480 "gzip" => {
3481 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
3482 let _ = enc.write_all(ser.into_inner().as_slice());
3483 match enc.finish() {
3484 Ok(buf) => {
3485 local_req_builder = local_req_builder.body(buf);
3486 }
3487 Err(e) => return Err(datadog::Error::Io(e)),
3488 }
3489 }
3490 "deflate" => {
3491 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
3492 let _ = enc.write_all(ser.into_inner().as_slice());
3493 match enc.finish() {
3494 Ok(buf) => {
3495 local_req_builder = local_req_builder.body(buf);
3496 }
3497 Err(e) => return Err(datadog::Error::Io(e)),
3498 }
3499 }
3500 "zstd1" => {
3501 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
3502 let _ = enc.write_all(ser.into_inner().as_slice());
3503 match enc.finish() {
3504 Ok(buf) => {
3505 local_req_builder = local_req_builder.body(buf);
3506 }
3507 Err(e) => return Err(datadog::Error::Io(e)),
3508 }
3509 }
3510 _ => {
3511 local_req_builder = local_req_builder.body(ser.into_inner());
3512 }
3513 }
3514 } else {
3515 local_req_builder = local_req_builder.body(ser.into_inner());
3516 }
3517 }
3518
3519 local_req_builder = local_req_builder.headers(headers);
3520 let local_req = local_req_builder.build()?;
3521 log::debug!("request content: {:?}", local_req.body());
3522 let local_resp = local_client.execute(local_req).await?;
3523
3524 let local_status = local_resp.status();
3525 let local_content = local_resp.text().await?;
3526 log::debug!("response content: {}", local_content);
3527
3528 if !local_status.is_client_error() && !local_status.is_server_error() {
3529 match serde_json::from_str::<crate::datadogV2::model::IncidentTodoResponse>(
3530 &local_content,
3531 ) {
3532 Ok(e) => {
3533 return Ok(datadog::ResponseContent {
3534 status: local_status,
3535 content: local_content,
3536 entity: Some(e),
3537 })
3538 }
3539 Err(e) => return Err(datadog::Error::Serde(e)),
3540 };
3541 } else {
3542 let local_entity: Option<UpdateIncidentTodoError> =
3543 serde_json::from_str(&local_content).ok();
3544 let local_error = datadog::ResponseContent {
3545 status: local_status,
3546 content: local_content,
3547 entity: local_entity,
3548 };
3549 Err(datadog::Error::ResponseError(local_error))
3550 }
3551 }
3552
3553 pub async fn update_incident_type(
3555 &self,
3556 incident_type_id: String,
3557 body: crate::datadogV2::model::IncidentTypePatchRequest,
3558 ) -> Result<
3559 crate::datadogV2::model::IncidentTypeResponse,
3560 datadog::Error<UpdateIncidentTypeError>,
3561 > {
3562 match self
3563 .update_incident_type_with_http_info(incident_type_id, body)
3564 .await
3565 {
3566 Ok(response_content) => {
3567 if let Some(e) = response_content.entity {
3568 Ok(e)
3569 } else {
3570 Err(datadog::Error::Serde(serde::de::Error::custom(
3571 "response content was None",
3572 )))
3573 }
3574 }
3575 Err(err) => Err(err),
3576 }
3577 }
3578
3579 pub async fn update_incident_type_with_http_info(
3581 &self,
3582 incident_type_id: String,
3583 body: crate::datadogV2::model::IncidentTypePatchRequest,
3584 ) -> Result<
3585 datadog::ResponseContent<crate::datadogV2::model::IncidentTypeResponse>,
3586 datadog::Error<UpdateIncidentTypeError>,
3587 > {
3588 let local_configuration = &self.config;
3589 let operation_id = "v2.update_incident_type";
3590 if local_configuration.is_unstable_operation_enabled(operation_id) {
3591 warn!("Using unstable operation {operation_id}");
3592 } else {
3593 let local_error = datadog::UnstableOperationDisabledError {
3594 msg: "Operation 'v2.update_incident_type' is not enabled".to_string(),
3595 };
3596 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
3597 }
3598
3599 let local_client = &self.client;
3600
3601 let local_uri_str = format!(
3602 "{}/api/v2/incidents/config/types/{incident_type_id}",
3603 local_configuration.get_operation_host(operation_id),
3604 incident_type_id = datadog::urlencode(incident_type_id)
3605 );
3606 let mut local_req_builder =
3607 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
3608
3609 let mut headers = HeaderMap::new();
3611 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
3612 headers.insert("Accept", HeaderValue::from_static("application/json"));
3613
3614 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
3616 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
3617 Err(e) => {
3618 log::warn!("Failed to parse user agent header: {e}, falling back to default");
3619 headers.insert(
3620 reqwest::header::USER_AGENT,
3621 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
3622 )
3623 }
3624 };
3625
3626 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
3628 headers.insert(
3629 "DD-API-KEY",
3630 HeaderValue::from_str(local_key.key.as_str())
3631 .expect("failed to parse DD-API-KEY header"),
3632 );
3633 };
3634 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
3635 headers.insert(
3636 "DD-APPLICATION-KEY",
3637 HeaderValue::from_str(local_key.key.as_str())
3638 .expect("failed to parse DD-APPLICATION-KEY header"),
3639 );
3640 };
3641
3642 let output = Vec::new();
3644 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
3645 if body.serialize(&mut ser).is_ok() {
3646 if let Some(content_encoding) = headers.get("Content-Encoding") {
3647 match content_encoding.to_str().unwrap_or_default() {
3648 "gzip" => {
3649 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
3650 let _ = enc.write_all(ser.into_inner().as_slice());
3651 match enc.finish() {
3652 Ok(buf) => {
3653 local_req_builder = local_req_builder.body(buf);
3654 }
3655 Err(e) => return Err(datadog::Error::Io(e)),
3656 }
3657 }
3658 "deflate" => {
3659 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
3660 let _ = enc.write_all(ser.into_inner().as_slice());
3661 match enc.finish() {
3662 Ok(buf) => {
3663 local_req_builder = local_req_builder.body(buf);
3664 }
3665 Err(e) => return Err(datadog::Error::Io(e)),
3666 }
3667 }
3668 "zstd1" => {
3669 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
3670 let _ = enc.write_all(ser.into_inner().as_slice());
3671 match enc.finish() {
3672 Ok(buf) => {
3673 local_req_builder = local_req_builder.body(buf);
3674 }
3675 Err(e) => return Err(datadog::Error::Io(e)),
3676 }
3677 }
3678 _ => {
3679 local_req_builder = local_req_builder.body(ser.into_inner());
3680 }
3681 }
3682 } else {
3683 local_req_builder = local_req_builder.body(ser.into_inner());
3684 }
3685 }
3686
3687 local_req_builder = local_req_builder.headers(headers);
3688 let local_req = local_req_builder.build()?;
3689 log::debug!("request content: {:?}", local_req.body());
3690 let local_resp = local_client.execute(local_req).await?;
3691
3692 let local_status = local_resp.status();
3693 let local_content = local_resp.text().await?;
3694 log::debug!("response content: {}", local_content);
3695
3696 if !local_status.is_client_error() && !local_status.is_server_error() {
3697 match serde_json::from_str::<crate::datadogV2::model::IncidentTypeResponse>(
3698 &local_content,
3699 ) {
3700 Ok(e) => {
3701 return Ok(datadog::ResponseContent {
3702 status: local_status,
3703 content: local_content,
3704 entity: Some(e),
3705 })
3706 }
3707 Err(e) => return Err(datadog::Error::Serde(e)),
3708 };
3709 } else {
3710 let local_entity: Option<UpdateIncidentTypeError> =
3711 serde_json::from_str(&local_content).ok();
3712 let local_error = datadog::ResponseContent {
3713 status: local_status,
3714 content: local_content,
3715 entity: local_entity,
3716 };
3717 Err(datadog::Error::ResponseError(local_error))
3718 }
3719 }
3720}