1use crate::datadog;
5use async_stream::try_stream;
6use flate2::{
7 write::{GzEncoder, ZlibEncoder},
8 Compression,
9};
10use futures_core::stream::Stream;
11use reqwest::header::{HeaderMap, HeaderValue};
12use serde::{Deserialize, Serialize};
13use std::io::Write;
14
15#[non_exhaustive]
17#[derive(Clone, Default, Debug)]
18pub struct ListCIAppPipelineEventsOptionalParams {
19 pub filter_query: Option<String>,
21 pub filter_from: Option<chrono::DateTime<chrono::Utc>>,
23 pub filter_to: Option<chrono::DateTime<chrono::Utc>>,
25 pub sort: Option<crate::datadogV2::model::CIAppSort>,
27 pub page_cursor: Option<String>,
29 pub page_limit: Option<i32>,
31}
32
33impl ListCIAppPipelineEventsOptionalParams {
34 pub fn filter_query(mut self, value: String) -> Self {
36 self.filter_query = Some(value);
37 self
38 }
39 pub fn filter_from(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
41 self.filter_from = Some(value);
42 self
43 }
44 pub fn filter_to(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
46 self.filter_to = Some(value);
47 self
48 }
49 pub fn sort(mut self, value: crate::datadogV2::model::CIAppSort) -> Self {
51 self.sort = Some(value);
52 self
53 }
54 pub fn page_cursor(mut self, value: String) -> Self {
56 self.page_cursor = Some(value);
57 self
58 }
59 pub fn page_limit(mut self, value: i32) -> Self {
61 self.page_limit = Some(value);
62 self
63 }
64}
65
66#[non_exhaustive]
68#[derive(Clone, Default, Debug)]
69pub struct SearchCIAppPipelineEventsOptionalParams {
70 pub body: Option<crate::datadogV2::model::CIAppPipelineEventsRequest>,
71}
72
73impl SearchCIAppPipelineEventsOptionalParams {
74 pub fn body(mut self, value: crate::datadogV2::model::CIAppPipelineEventsRequest) -> Self {
75 self.body = Some(value);
76 self
77 }
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum AggregateCIAppPipelineEventsError {
84 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
85 UnknownValue(serde_json::Value),
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum CreateCIAppPipelineEventError {
92 HTTPCIAppErrors(crate::datadogV2::model::HTTPCIAppErrors),
93 UnknownValue(serde_json::Value),
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum ListCIAppPipelineEventsError {
100 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
101 UnknownValue(serde_json::Value),
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum SearchCIAppPipelineEventsError {
108 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
109 UnknownValue(serde_json::Value),
110}
111
112#[derive(Debug, Clone)]
114pub struct CIVisibilityPipelinesAPI {
115 config: datadog::Configuration,
116 client: reqwest_middleware::ClientWithMiddleware,
117}
118
119impl Default for CIVisibilityPipelinesAPI {
120 fn default() -> Self {
121 Self::with_config(datadog::Configuration::default())
122 }
123}
124
125impl CIVisibilityPipelinesAPI {
126 pub fn new() -> Self {
127 Self::default()
128 }
129 pub fn with_config(config: datadog::Configuration) -> Self {
130 let mut reqwest_client_builder = reqwest::Client::builder();
131
132 if let Some(proxy_url) = &config.proxy_url {
133 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
134 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
135 }
136
137 let mut middleware_client_builder =
138 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
139
140 if config.enable_retry {
141 struct RetryableStatus;
142 impl reqwest_retry::RetryableStrategy for RetryableStatus {
143 fn handle(
144 &self,
145 res: &Result<reqwest::Response, reqwest_middleware::Error>,
146 ) -> Option<reqwest_retry::Retryable> {
147 match res {
148 Ok(success) => reqwest_retry::default_on_request_success(success),
149 Err(_) => None,
150 }
151 }
152 }
153 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
154 .build_with_max_retries(config.max_retries);
155
156 let retry_middleware =
157 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
158 backoff_policy,
159 RetryableStatus,
160 );
161
162 middleware_client_builder = middleware_client_builder.with(retry_middleware);
163 }
164
165 let client = middleware_client_builder.build();
166
167 Self { config, client }
168 }
169
170 pub fn with_client_and_config(
171 config: datadog::Configuration,
172 client: reqwest_middleware::ClientWithMiddleware,
173 ) -> Self {
174 Self { config, client }
175 }
176
177 pub async fn aggregate_ci_app_pipeline_events(
179 &self,
180 body: crate::datadogV2::model::CIAppPipelinesAggregateRequest,
181 ) -> Result<
182 crate::datadogV2::model::CIAppPipelinesAnalyticsAggregateResponse,
183 datadog::Error<AggregateCIAppPipelineEventsError>,
184 > {
185 match self
186 .aggregate_ci_app_pipeline_events_with_http_info(body)
187 .await
188 {
189 Ok(response_content) => {
190 if let Some(e) = response_content.entity {
191 Ok(e)
192 } else {
193 Err(datadog::Error::Serde(serde::de::Error::custom(
194 "response content was None",
195 )))
196 }
197 }
198 Err(err) => Err(err),
199 }
200 }
201
202 pub async fn aggregate_ci_app_pipeline_events_with_http_info(
204 &self,
205 body: crate::datadogV2::model::CIAppPipelinesAggregateRequest,
206 ) -> Result<
207 datadog::ResponseContent<crate::datadogV2::model::CIAppPipelinesAnalyticsAggregateResponse>,
208 datadog::Error<AggregateCIAppPipelineEventsError>,
209 > {
210 let local_configuration = &self.config;
211 let operation_id = "v2.aggregate_ci_app_pipeline_events";
212
213 let local_client = &self.client;
214
215 let local_uri_str = format!(
216 "{}/api/v2/ci/pipelines/analytics/aggregate",
217 local_configuration.get_operation_host(operation_id)
218 );
219 let mut local_req_builder =
220 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
221
222 let mut headers = HeaderMap::new();
224 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
225 headers.insert("Accept", HeaderValue::from_static("application/json"));
226
227 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
229 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
230 Err(e) => {
231 log::warn!("Failed to parse user agent header: {e}, falling back to default");
232 headers.insert(
233 reqwest::header::USER_AGENT,
234 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
235 )
236 }
237 };
238
239 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
241 headers.insert(
242 "DD-API-KEY",
243 HeaderValue::from_str(local_key.key.as_str())
244 .expect("failed to parse DD-API-KEY header"),
245 );
246 };
247 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
248 headers.insert(
249 "DD-APPLICATION-KEY",
250 HeaderValue::from_str(local_key.key.as_str())
251 .expect("failed to parse DD-APPLICATION-KEY header"),
252 );
253 };
254
255 let output = Vec::new();
257 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
258 if body.serialize(&mut ser).is_ok() {
259 if let Some(content_encoding) = headers.get("Content-Encoding") {
260 match content_encoding.to_str().unwrap_or_default() {
261 "gzip" => {
262 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
263 let _ = enc.write_all(ser.into_inner().as_slice());
264 match enc.finish() {
265 Ok(buf) => {
266 local_req_builder = local_req_builder.body(buf);
267 }
268 Err(e) => return Err(datadog::Error::Io(e)),
269 }
270 }
271 "deflate" => {
272 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
273 let _ = enc.write_all(ser.into_inner().as_slice());
274 match enc.finish() {
275 Ok(buf) => {
276 local_req_builder = local_req_builder.body(buf);
277 }
278 Err(e) => return Err(datadog::Error::Io(e)),
279 }
280 }
281 "zstd1" => {
282 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
283 let _ = enc.write_all(ser.into_inner().as_slice());
284 match enc.finish() {
285 Ok(buf) => {
286 local_req_builder = local_req_builder.body(buf);
287 }
288 Err(e) => return Err(datadog::Error::Io(e)),
289 }
290 }
291 _ => {
292 local_req_builder = local_req_builder.body(ser.into_inner());
293 }
294 }
295 } else {
296 local_req_builder = local_req_builder.body(ser.into_inner());
297 }
298 }
299
300 local_req_builder = local_req_builder.headers(headers);
301 let local_req = local_req_builder.build()?;
302 log::debug!("request content: {:?}", local_req.body());
303 let local_resp = local_client.execute(local_req).await?;
304
305 let local_status = local_resp.status();
306 let local_content = local_resp.text().await?;
307 log::debug!("response content: {}", local_content);
308
309 if !local_status.is_client_error() && !local_status.is_server_error() {
310 match serde_json::from_str::<
311 crate::datadogV2::model::CIAppPipelinesAnalyticsAggregateResponse,
312 >(&local_content)
313 {
314 Ok(e) => {
315 return Ok(datadog::ResponseContent {
316 status: local_status,
317 content: local_content,
318 entity: Some(e),
319 })
320 }
321 Err(e) => return Err(datadog::Error::Serde(e)),
322 };
323 } else {
324 let local_entity: Option<AggregateCIAppPipelineEventsError> =
325 serde_json::from_str(&local_content).ok();
326 let local_error = datadog::ResponseContent {
327 status: local_status,
328 content: local_content,
329 entity: local_entity,
330 };
331 Err(datadog::Error::ResponseError(local_error))
332 }
333 }
334
335 pub async fn create_ci_app_pipeline_event(
341 &self,
342 body: crate::datadogV2::model::CIAppCreatePipelineEventRequest,
343 ) -> Result<
344 std::collections::BTreeMap<String, serde_json::Value>,
345 datadog::Error<CreateCIAppPipelineEventError>,
346 > {
347 match self.create_ci_app_pipeline_event_with_http_info(body).await {
348 Ok(response_content) => {
349 if let Some(e) = response_content.entity {
350 Ok(e)
351 } else {
352 Err(datadog::Error::Serde(serde::de::Error::custom(
353 "response content was None",
354 )))
355 }
356 }
357 Err(err) => Err(err),
358 }
359 }
360
361 pub async fn create_ci_app_pipeline_event_with_http_info(
367 &self,
368 body: crate::datadogV2::model::CIAppCreatePipelineEventRequest,
369 ) -> Result<
370 datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
371 datadog::Error<CreateCIAppPipelineEventError>,
372 > {
373 let local_configuration = &self.config;
374 let operation_id = "v2.create_ci_app_pipeline_event";
375
376 let local_client = &self.client;
377
378 let local_uri_str = format!(
379 "{}/api/v2/ci/pipeline",
380 local_configuration.get_operation_host(operation_id)
381 );
382 let mut local_req_builder =
383 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
384
385 let mut headers = HeaderMap::new();
387 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
388 headers.insert("Accept", HeaderValue::from_static("application/json"));
389
390 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
392 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
393 Err(e) => {
394 log::warn!("Failed to parse user agent header: {e}, falling back to default");
395 headers.insert(
396 reqwest::header::USER_AGENT,
397 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
398 )
399 }
400 };
401
402 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
404 headers.insert(
405 "DD-API-KEY",
406 HeaderValue::from_str(local_key.key.as_str())
407 .expect("failed to parse DD-API-KEY header"),
408 );
409 };
410
411 let output = Vec::new();
413 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
414 if body.serialize(&mut ser).is_ok() {
415 if let Some(content_encoding) = headers.get("Content-Encoding") {
416 match content_encoding.to_str().unwrap_or_default() {
417 "gzip" => {
418 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
419 let _ = enc.write_all(ser.into_inner().as_slice());
420 match enc.finish() {
421 Ok(buf) => {
422 local_req_builder = local_req_builder.body(buf);
423 }
424 Err(e) => return Err(datadog::Error::Io(e)),
425 }
426 }
427 "deflate" => {
428 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
429 let _ = enc.write_all(ser.into_inner().as_slice());
430 match enc.finish() {
431 Ok(buf) => {
432 local_req_builder = local_req_builder.body(buf);
433 }
434 Err(e) => return Err(datadog::Error::Io(e)),
435 }
436 }
437 "zstd1" => {
438 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
439 let _ = enc.write_all(ser.into_inner().as_slice());
440 match enc.finish() {
441 Ok(buf) => {
442 local_req_builder = local_req_builder.body(buf);
443 }
444 Err(e) => return Err(datadog::Error::Io(e)),
445 }
446 }
447 _ => {
448 local_req_builder = local_req_builder.body(ser.into_inner());
449 }
450 }
451 } else {
452 local_req_builder = local_req_builder.body(ser.into_inner());
453 }
454 }
455
456 local_req_builder = local_req_builder.headers(headers);
457 let local_req = local_req_builder.build()?;
458 log::debug!("request content: {:?}", local_req.body());
459 let local_resp = local_client.execute(local_req).await?;
460
461 let local_status = local_resp.status();
462 let local_content = local_resp.text().await?;
463 log::debug!("response content: {}", local_content);
464
465 if !local_status.is_client_error() && !local_status.is_server_error() {
466 match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
467 &local_content,
468 ) {
469 Ok(e) => {
470 return Ok(datadog::ResponseContent {
471 status: local_status,
472 content: local_content,
473 entity: Some(e),
474 })
475 }
476 Err(e) => return Err(datadog::Error::Serde(e)),
477 };
478 } else {
479 let local_entity: Option<CreateCIAppPipelineEventError> =
480 serde_json::from_str(&local_content).ok();
481 let local_error = datadog::ResponseContent {
482 status: local_status,
483 content: local_content,
484 entity: local_entity,
485 };
486 Err(datadog::Error::ResponseError(local_error))
487 }
488 }
489
490 pub async fn list_ci_app_pipeline_events(
495 &self,
496 params: ListCIAppPipelineEventsOptionalParams,
497 ) -> Result<
498 crate::datadogV2::model::CIAppPipelineEventsResponse,
499 datadog::Error<ListCIAppPipelineEventsError>,
500 > {
501 match self
502 .list_ci_app_pipeline_events_with_http_info(params)
503 .await
504 {
505 Ok(response_content) => {
506 if let Some(e) = response_content.entity {
507 Ok(e)
508 } else {
509 Err(datadog::Error::Serde(serde::de::Error::custom(
510 "response content was None",
511 )))
512 }
513 }
514 Err(err) => Err(err),
515 }
516 }
517
518 pub fn list_ci_app_pipeline_events_with_pagination(
519 &self,
520 mut params: ListCIAppPipelineEventsOptionalParams,
521 ) -> impl Stream<
522 Item = Result<
523 crate::datadogV2::model::CIAppPipelineEvent,
524 datadog::Error<ListCIAppPipelineEventsError>,
525 >,
526 > + '_ {
527 try_stream! {
528 let mut page_size: i32 = 10;
529 if params.page_limit.is_none() {
530 params.page_limit = Some(page_size);
531 } else {
532 page_size = params.page_limit.unwrap().clone();
533 }
534 loop {
535 let resp = self.list_ci_app_pipeline_events(params.clone()).await?;
536 let Some(data) = resp.data else { break };
537
538 let r = data;
539 let count = r.len();
540 for team in r {
541 yield team;
542 }
543
544 if count < page_size as usize {
545 break;
546 }
547 let Some(meta) = resp.meta else { break };
548 let Some(page) = meta.page else { break };
549 let Some(after) = page.after else { break };
550
551 params.page_cursor = Some(after);
552 }
553 }
554 }
555
556 pub async fn list_ci_app_pipeline_events_with_http_info(
561 &self,
562 params: ListCIAppPipelineEventsOptionalParams,
563 ) -> Result<
564 datadog::ResponseContent<crate::datadogV2::model::CIAppPipelineEventsResponse>,
565 datadog::Error<ListCIAppPipelineEventsError>,
566 > {
567 let local_configuration = &self.config;
568 let operation_id = "v2.list_ci_app_pipeline_events";
569
570 let filter_query = params.filter_query;
572 let filter_from = params.filter_from;
573 let filter_to = params.filter_to;
574 let sort = params.sort;
575 let page_cursor = params.page_cursor;
576 let page_limit = params.page_limit;
577
578 let local_client = &self.client;
579
580 let local_uri_str = format!(
581 "{}/api/v2/ci/pipelines/events",
582 local_configuration.get_operation_host(operation_id)
583 );
584 let mut local_req_builder =
585 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
586
587 if let Some(ref local_query_param) = filter_query {
588 local_req_builder =
589 local_req_builder.query(&[("filter[query]", &local_query_param.to_string())]);
590 };
591 if let Some(ref local_query_param) = filter_from {
592 local_req_builder = local_req_builder.query(&[(
593 "filter[from]",
594 &local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
595 )]);
596 };
597 if let Some(ref local_query_param) = filter_to {
598 local_req_builder = local_req_builder.query(&[(
599 "filter[to]",
600 &local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
601 )]);
602 };
603 if let Some(ref local_query_param) = sort {
604 local_req_builder =
605 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
606 };
607 if let Some(ref local_query_param) = page_cursor {
608 local_req_builder =
609 local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
610 };
611 if let Some(ref local_query_param) = page_limit {
612 local_req_builder =
613 local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
614 };
615
616 let mut headers = HeaderMap::new();
618 headers.insert("Accept", HeaderValue::from_static("application/json"));
619
620 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
622 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
623 Err(e) => {
624 log::warn!("Failed to parse user agent header: {e}, falling back to default");
625 headers.insert(
626 reqwest::header::USER_AGENT,
627 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
628 )
629 }
630 };
631
632 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
634 headers.insert(
635 "DD-API-KEY",
636 HeaderValue::from_str(local_key.key.as_str())
637 .expect("failed to parse DD-API-KEY header"),
638 );
639 };
640 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
641 headers.insert(
642 "DD-APPLICATION-KEY",
643 HeaderValue::from_str(local_key.key.as_str())
644 .expect("failed to parse DD-APPLICATION-KEY header"),
645 );
646 };
647
648 local_req_builder = local_req_builder.headers(headers);
649 let local_req = local_req_builder.build()?;
650 log::debug!("request content: {:?}", local_req.body());
651 let local_resp = local_client.execute(local_req).await?;
652
653 let local_status = local_resp.status();
654 let local_content = local_resp.text().await?;
655 log::debug!("response content: {}", local_content);
656
657 if !local_status.is_client_error() && !local_status.is_server_error() {
658 match serde_json::from_str::<crate::datadogV2::model::CIAppPipelineEventsResponse>(
659 &local_content,
660 ) {
661 Ok(e) => {
662 return Ok(datadog::ResponseContent {
663 status: local_status,
664 content: local_content,
665 entity: Some(e),
666 })
667 }
668 Err(e) => return Err(datadog::Error::Serde(e)),
669 };
670 } else {
671 let local_entity: Option<ListCIAppPipelineEventsError> =
672 serde_json::from_str(&local_content).ok();
673 let local_error = datadog::ResponseContent {
674 status: local_status,
675 content: local_content,
676 entity: local_entity,
677 };
678 Err(datadog::Error::ResponseError(local_error))
679 }
680 }
681
682 pub async fn search_ci_app_pipeline_events(
687 &self,
688 params: SearchCIAppPipelineEventsOptionalParams,
689 ) -> Result<
690 crate::datadogV2::model::CIAppPipelineEventsResponse,
691 datadog::Error<SearchCIAppPipelineEventsError>,
692 > {
693 match self
694 .search_ci_app_pipeline_events_with_http_info(params)
695 .await
696 {
697 Ok(response_content) => {
698 if let Some(e) = response_content.entity {
699 Ok(e)
700 } else {
701 Err(datadog::Error::Serde(serde::de::Error::custom(
702 "response content was None",
703 )))
704 }
705 }
706 Err(err) => Err(err),
707 }
708 }
709
710 pub fn search_ci_app_pipeline_events_with_pagination(
711 &self,
712 mut params: SearchCIAppPipelineEventsOptionalParams,
713 ) -> impl Stream<
714 Item = Result<
715 crate::datadogV2::model::CIAppPipelineEvent,
716 datadog::Error<SearchCIAppPipelineEventsError>,
717 >,
718 > + '_ {
719 try_stream! {
720 let mut page_size: i32 = 10;
721 if params.body.is_none() {
722 params.body = Some(crate::datadogV2::model::CIAppPipelineEventsRequest::new());
723 }
724 if params.body.as_ref().unwrap().page.is_none() {
725 params.body.as_mut().unwrap().page = Some(crate::datadogV2::model::CIAppQueryPageOptions::new());
726 }
727 if params.body.as_ref().unwrap().page.as_ref().unwrap().limit.is_none() {
728 params.body.as_mut().unwrap().page.as_mut().unwrap().limit = Some(page_size);
729 } else {
730 page_size = params.body.as_ref().unwrap().page.as_ref().unwrap().limit.unwrap().clone();
731 }
732 loop {
733 let resp = self.search_ci_app_pipeline_events(params.clone()).await?;
734 let Some(data) = resp.data else { break };
735
736 let r = data;
737 let count = r.len();
738 for team in r {
739 yield team;
740 }
741
742 if count < page_size as usize {
743 break;
744 }
745 let Some(meta) = resp.meta else { break };
746 let Some(page) = meta.page else { break };
747 let Some(after) = page.after else { break };
748
749 params.body.as_mut().unwrap().page.as_mut().unwrap().cursor = Some(after);
750 }
751 }
752 }
753
754 pub async fn search_ci_app_pipeline_events_with_http_info(
759 &self,
760 params: SearchCIAppPipelineEventsOptionalParams,
761 ) -> Result<
762 datadog::ResponseContent<crate::datadogV2::model::CIAppPipelineEventsResponse>,
763 datadog::Error<SearchCIAppPipelineEventsError>,
764 > {
765 let local_configuration = &self.config;
766 let operation_id = "v2.search_ci_app_pipeline_events";
767
768 let body = params.body;
770
771 let local_client = &self.client;
772
773 let local_uri_str = format!(
774 "{}/api/v2/ci/pipelines/events/search",
775 local_configuration.get_operation_host(operation_id)
776 );
777 let mut local_req_builder =
778 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
779
780 let mut headers = HeaderMap::new();
782 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
783 headers.insert("Accept", HeaderValue::from_static("application/json"));
784
785 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
787 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
788 Err(e) => {
789 log::warn!("Failed to parse user agent header: {e}, falling back to default");
790 headers.insert(
791 reqwest::header::USER_AGENT,
792 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
793 )
794 }
795 };
796
797 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
799 headers.insert(
800 "DD-API-KEY",
801 HeaderValue::from_str(local_key.key.as_str())
802 .expect("failed to parse DD-API-KEY header"),
803 );
804 };
805 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
806 headers.insert(
807 "DD-APPLICATION-KEY",
808 HeaderValue::from_str(local_key.key.as_str())
809 .expect("failed to parse DD-APPLICATION-KEY header"),
810 );
811 };
812
813 let output = Vec::new();
815 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
816 if body.serialize(&mut ser).is_ok() {
817 if let Some(content_encoding) = headers.get("Content-Encoding") {
818 match content_encoding.to_str().unwrap_or_default() {
819 "gzip" => {
820 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
821 let _ = enc.write_all(ser.into_inner().as_slice());
822 match enc.finish() {
823 Ok(buf) => {
824 local_req_builder = local_req_builder.body(buf);
825 }
826 Err(e) => return Err(datadog::Error::Io(e)),
827 }
828 }
829 "deflate" => {
830 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
831 let _ = enc.write_all(ser.into_inner().as_slice());
832 match enc.finish() {
833 Ok(buf) => {
834 local_req_builder = local_req_builder.body(buf);
835 }
836 Err(e) => return Err(datadog::Error::Io(e)),
837 }
838 }
839 "zstd1" => {
840 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
841 let _ = enc.write_all(ser.into_inner().as_slice());
842 match enc.finish() {
843 Ok(buf) => {
844 local_req_builder = local_req_builder.body(buf);
845 }
846 Err(e) => return Err(datadog::Error::Io(e)),
847 }
848 }
849 _ => {
850 local_req_builder = local_req_builder.body(ser.into_inner());
851 }
852 }
853 } else {
854 local_req_builder = local_req_builder.body(ser.into_inner());
855 }
856 }
857
858 local_req_builder = local_req_builder.headers(headers);
859 let local_req = local_req_builder.build()?;
860 log::debug!("request content: {:?}", local_req.body());
861 let local_resp = local_client.execute(local_req).await?;
862
863 let local_status = local_resp.status();
864 let local_content = local_resp.text().await?;
865 log::debug!("response content: {}", local_content);
866
867 if !local_status.is_client_error() && !local_status.is_server_error() {
868 match serde_json::from_str::<crate::datadogV2::model::CIAppPipelineEventsResponse>(
869 &local_content,
870 ) {
871 Ok(e) => {
872 return Ok(datadog::ResponseContent {
873 status: local_status,
874 content: local_content,
875 entity: Some(e),
876 })
877 }
878 Err(e) => return Err(datadog::Error::Serde(e)),
879 };
880 } else {
881 let local_entity: Option<SearchCIAppPipelineEventsError> =
882 serde_json::from_str(&local_content).ok();
883 let local_error = datadog::ResponseContent {
884 status: local_status,
885 content: local_content,
886 entity: local_entity,
887 };
888 Err(datadog::Error::ResponseError(local_error))
889 }
890 }
891}