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