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(
342 &self,
343 body: crate::datadogV2::model::CIAppCreatePipelineEventRequest,
344 ) -> Result<
345 std::collections::BTreeMap<String, serde_json::Value>,
346 datadog::Error<CreateCIAppPipelineEventError>,
347 > {
348 match self.create_ci_app_pipeline_event_with_http_info(body).await {
349 Ok(response_content) => {
350 if let Some(e) = response_content.entity {
351 Ok(e)
352 } else {
353 Err(datadog::Error::Serde(serde::de::Error::custom(
354 "response content was None",
355 )))
356 }
357 }
358 Err(err) => Err(err),
359 }
360 }
361
362 pub async fn create_ci_app_pipeline_event_with_http_info(
369 &self,
370 body: crate::datadogV2::model::CIAppCreatePipelineEventRequest,
371 ) -> Result<
372 datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
373 datadog::Error<CreateCIAppPipelineEventError>,
374 > {
375 let local_configuration = &self.config;
376 let operation_id = "v2.create_ci_app_pipeline_event";
377
378 let local_client = &self.client;
379
380 let local_uri_str = format!(
381 "{}/api/v2/ci/pipeline",
382 local_configuration.get_operation_host(operation_id)
383 );
384 let mut local_req_builder =
385 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
386
387 let mut headers = HeaderMap::new();
389 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
390 headers.insert("Accept", HeaderValue::from_static("application/json"));
391
392 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
394 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
395 Err(e) => {
396 log::warn!("Failed to parse user agent header: {e}, falling back to default");
397 headers.insert(
398 reqwest::header::USER_AGENT,
399 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
400 )
401 }
402 };
403
404 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
406 headers.insert(
407 "DD-API-KEY",
408 HeaderValue::from_str(local_key.key.as_str())
409 .expect("failed to parse DD-API-KEY header"),
410 );
411 };
412
413 let output = Vec::new();
415 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
416 if body.serialize(&mut ser).is_ok() {
417 if let Some(content_encoding) = headers.get("Content-Encoding") {
418 match content_encoding.to_str().unwrap_or_default() {
419 "gzip" => {
420 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
421 let _ = enc.write_all(ser.into_inner().as_slice());
422 match enc.finish() {
423 Ok(buf) => {
424 local_req_builder = local_req_builder.body(buf);
425 }
426 Err(e) => return Err(datadog::Error::Io(e)),
427 }
428 }
429 "deflate" => {
430 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
431 let _ = enc.write_all(ser.into_inner().as_slice());
432 match enc.finish() {
433 Ok(buf) => {
434 local_req_builder = local_req_builder.body(buf);
435 }
436 Err(e) => return Err(datadog::Error::Io(e)),
437 }
438 }
439 "zstd1" => {
440 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
441 let _ = enc.write_all(ser.into_inner().as_slice());
442 match enc.finish() {
443 Ok(buf) => {
444 local_req_builder = local_req_builder.body(buf);
445 }
446 Err(e) => return Err(datadog::Error::Io(e)),
447 }
448 }
449 _ => {
450 local_req_builder = local_req_builder.body(ser.into_inner());
451 }
452 }
453 } else {
454 local_req_builder = local_req_builder.body(ser.into_inner());
455 }
456 }
457
458 local_req_builder = local_req_builder.headers(headers);
459 let local_req = local_req_builder.build()?;
460 log::debug!("request content: {:?}", local_req.body());
461 let local_resp = local_client.execute(local_req).await?;
462
463 let local_status = local_resp.status();
464 let local_content = local_resp.text().await?;
465 log::debug!("response content: {}", local_content);
466
467 if !local_status.is_client_error() && !local_status.is_server_error() {
468 match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
469 &local_content,
470 ) {
471 Ok(e) => {
472 return Ok(datadog::ResponseContent {
473 status: local_status,
474 content: local_content,
475 entity: Some(e),
476 })
477 }
478 Err(e) => return Err(datadog::Error::Serde(e)),
479 };
480 } else {
481 let local_entity: Option<CreateCIAppPipelineEventError> =
482 serde_json::from_str(&local_content).ok();
483 let local_error = datadog::ResponseContent {
484 status: local_status,
485 content: local_content,
486 entity: local_entity,
487 };
488 Err(datadog::Error::ResponseError(local_error))
489 }
490 }
491
492 pub async fn list_ci_app_pipeline_events(
497 &self,
498 params: ListCIAppPipelineEventsOptionalParams,
499 ) -> Result<
500 crate::datadogV2::model::CIAppPipelineEventsResponse,
501 datadog::Error<ListCIAppPipelineEventsError>,
502 > {
503 match self
504 .list_ci_app_pipeline_events_with_http_info(params)
505 .await
506 {
507 Ok(response_content) => {
508 if let Some(e) = response_content.entity {
509 Ok(e)
510 } else {
511 Err(datadog::Error::Serde(serde::de::Error::custom(
512 "response content was None",
513 )))
514 }
515 }
516 Err(err) => Err(err),
517 }
518 }
519
520 pub fn list_ci_app_pipeline_events_with_pagination(
521 &self,
522 mut params: ListCIAppPipelineEventsOptionalParams,
523 ) -> impl Stream<
524 Item = Result<
525 crate::datadogV2::model::CIAppPipelineEvent,
526 datadog::Error<ListCIAppPipelineEventsError>,
527 >,
528 > + '_ {
529 try_stream! {
530 let mut page_size: i32 = 10;
531 if params.page_limit.is_none() {
532 params.page_limit = Some(page_size);
533 } else {
534 page_size = params.page_limit.unwrap().clone();
535 }
536 loop {
537 let resp = self.list_ci_app_pipeline_events(params.clone()).await?;
538 let Some(data) = resp.data else { break };
539
540 let r = data;
541 let count = r.len();
542 for team in r {
543 yield team;
544 }
545
546 if count < page_size as usize {
547 break;
548 }
549 let Some(meta) = resp.meta else { break };
550 let Some(page) = meta.page else { break };
551 let Some(after) = page.after else { break };
552
553 params.page_cursor = Some(after);
554 }
555 }
556 }
557
558 pub async fn list_ci_app_pipeline_events_with_http_info(
563 &self,
564 params: ListCIAppPipelineEventsOptionalParams,
565 ) -> Result<
566 datadog::ResponseContent<crate::datadogV2::model::CIAppPipelineEventsResponse>,
567 datadog::Error<ListCIAppPipelineEventsError>,
568 > {
569 let local_configuration = &self.config;
570 let operation_id = "v2.list_ci_app_pipeline_events";
571
572 let filter_query = params.filter_query;
574 let filter_from = params.filter_from;
575 let filter_to = params.filter_to;
576 let sort = params.sort;
577 let page_cursor = params.page_cursor;
578 let page_limit = params.page_limit;
579
580 let local_client = &self.client;
581
582 let local_uri_str = format!(
583 "{}/api/v2/ci/pipelines/events",
584 local_configuration.get_operation_host(operation_id)
585 );
586 let mut local_req_builder =
587 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
588
589 if let Some(ref local_query_param) = filter_query {
590 local_req_builder =
591 local_req_builder.query(&[("filter[query]", &local_query_param.to_string())]);
592 };
593 if let Some(ref local_query_param) = filter_from {
594 local_req_builder = local_req_builder.query(&[(
595 "filter[from]",
596 &local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
597 )]);
598 };
599 if let Some(ref local_query_param) = filter_to {
600 local_req_builder = local_req_builder.query(&[(
601 "filter[to]",
602 &local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
603 )]);
604 };
605 if let Some(ref local_query_param) = sort {
606 local_req_builder =
607 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
608 };
609 if let Some(ref local_query_param) = page_cursor {
610 local_req_builder =
611 local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
612 };
613 if let Some(ref local_query_param) = page_limit {
614 local_req_builder =
615 local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
616 };
617
618 let mut headers = HeaderMap::new();
620 headers.insert("Accept", HeaderValue::from_static("application/json"));
621
622 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
624 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
625 Err(e) => {
626 log::warn!("Failed to parse user agent header: {e}, falling back to default");
627 headers.insert(
628 reqwest::header::USER_AGENT,
629 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
630 )
631 }
632 };
633
634 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
636 headers.insert(
637 "DD-API-KEY",
638 HeaderValue::from_str(local_key.key.as_str())
639 .expect("failed to parse DD-API-KEY header"),
640 );
641 };
642 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
643 headers.insert(
644 "DD-APPLICATION-KEY",
645 HeaderValue::from_str(local_key.key.as_str())
646 .expect("failed to parse DD-APPLICATION-KEY header"),
647 );
648 };
649
650 local_req_builder = local_req_builder.headers(headers);
651 let local_req = local_req_builder.build()?;
652 log::debug!("request content: {:?}", local_req.body());
653 let local_resp = local_client.execute(local_req).await?;
654
655 let local_status = local_resp.status();
656 let local_content = local_resp.text().await?;
657 log::debug!("response content: {}", local_content);
658
659 if !local_status.is_client_error() && !local_status.is_server_error() {
660 match serde_json::from_str::<crate::datadogV2::model::CIAppPipelineEventsResponse>(
661 &local_content,
662 ) {
663 Ok(e) => {
664 return Ok(datadog::ResponseContent {
665 status: local_status,
666 content: local_content,
667 entity: Some(e),
668 })
669 }
670 Err(e) => return Err(datadog::Error::Serde(e)),
671 };
672 } else {
673 let local_entity: Option<ListCIAppPipelineEventsError> =
674 serde_json::from_str(&local_content).ok();
675 let local_error = datadog::ResponseContent {
676 status: local_status,
677 content: local_content,
678 entity: local_entity,
679 };
680 Err(datadog::Error::ResponseError(local_error))
681 }
682 }
683
684 pub async fn search_ci_app_pipeline_events(
689 &self,
690 params: SearchCIAppPipelineEventsOptionalParams,
691 ) -> Result<
692 crate::datadogV2::model::CIAppPipelineEventsResponse,
693 datadog::Error<SearchCIAppPipelineEventsError>,
694 > {
695 match self
696 .search_ci_app_pipeline_events_with_http_info(params)
697 .await
698 {
699 Ok(response_content) => {
700 if let Some(e) = response_content.entity {
701 Ok(e)
702 } else {
703 Err(datadog::Error::Serde(serde::de::Error::custom(
704 "response content was None",
705 )))
706 }
707 }
708 Err(err) => Err(err),
709 }
710 }
711
712 pub fn search_ci_app_pipeline_events_with_pagination(
713 &self,
714 mut params: SearchCIAppPipelineEventsOptionalParams,
715 ) -> impl Stream<
716 Item = Result<
717 crate::datadogV2::model::CIAppPipelineEvent,
718 datadog::Error<SearchCIAppPipelineEventsError>,
719 >,
720 > + '_ {
721 try_stream! {
722 let mut page_size: i32 = 10;
723 if params.body.is_none() {
724 params.body = Some(crate::datadogV2::model::CIAppPipelineEventsRequest::new());
725 }
726 if params.body.as_ref().unwrap().page.is_none() {
727 params.body.as_mut().unwrap().page = Some(crate::datadogV2::model::CIAppQueryPageOptions::new());
728 }
729 if params.body.as_ref().unwrap().page.as_ref().unwrap().limit.is_none() {
730 params.body.as_mut().unwrap().page.as_mut().unwrap().limit = Some(page_size);
731 } else {
732 page_size = params.body.as_ref().unwrap().page.as_ref().unwrap().limit.unwrap().clone();
733 }
734 loop {
735 let resp = self.search_ci_app_pipeline_events(params.clone()).await?;
736 let Some(data) = resp.data else { break };
737
738 let r = data;
739 let count = r.len();
740 for team in r {
741 yield team;
742 }
743
744 if count < page_size as usize {
745 break;
746 }
747 let Some(meta) = resp.meta else { break };
748 let Some(page) = meta.page else { break };
749 let Some(after) = page.after else { break };
750
751 params.body.as_mut().unwrap().page.as_mut().unwrap().cursor = Some(after);
752 }
753 }
754 }
755
756 pub async fn search_ci_app_pipeline_events_with_http_info(
761 &self,
762 params: SearchCIAppPipelineEventsOptionalParams,
763 ) -> Result<
764 datadog::ResponseContent<crate::datadogV2::model::CIAppPipelineEventsResponse>,
765 datadog::Error<SearchCIAppPipelineEventsError>,
766 > {
767 let local_configuration = &self.config;
768 let operation_id = "v2.search_ci_app_pipeline_events";
769
770 let body = params.body;
772
773 let local_client = &self.client;
774
775 let local_uri_str = format!(
776 "{}/api/v2/ci/pipelines/events/search",
777 local_configuration.get_operation_host(operation_id)
778 );
779 let mut local_req_builder =
780 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
781
782 let mut headers = HeaderMap::new();
784 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
785 headers.insert("Accept", HeaderValue::from_static("application/json"));
786
787 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
789 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
790 Err(e) => {
791 log::warn!("Failed to parse user agent header: {e}, falling back to default");
792 headers.insert(
793 reqwest::header::USER_AGENT,
794 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
795 )
796 }
797 };
798
799 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
801 headers.insert(
802 "DD-API-KEY",
803 HeaderValue::from_str(local_key.key.as_str())
804 .expect("failed to parse DD-API-KEY header"),
805 );
806 };
807 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
808 headers.insert(
809 "DD-APPLICATION-KEY",
810 HeaderValue::from_str(local_key.key.as_str())
811 .expect("failed to parse DD-APPLICATION-KEY header"),
812 );
813 };
814
815 let output = Vec::new();
817 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
818 if body.serialize(&mut ser).is_ok() {
819 if let Some(content_encoding) = headers.get("Content-Encoding") {
820 match content_encoding.to_str().unwrap_or_default() {
821 "gzip" => {
822 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
823 let _ = enc.write_all(ser.into_inner().as_slice());
824 match enc.finish() {
825 Ok(buf) => {
826 local_req_builder = local_req_builder.body(buf);
827 }
828 Err(e) => return Err(datadog::Error::Io(e)),
829 }
830 }
831 "deflate" => {
832 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
833 let _ = enc.write_all(ser.into_inner().as_slice());
834 match enc.finish() {
835 Ok(buf) => {
836 local_req_builder = local_req_builder.body(buf);
837 }
838 Err(e) => return Err(datadog::Error::Io(e)),
839 }
840 }
841 "zstd1" => {
842 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
843 let _ = enc.write_all(ser.into_inner().as_slice());
844 match enc.finish() {
845 Ok(buf) => {
846 local_req_builder = local_req_builder.body(buf);
847 }
848 Err(e) => return Err(datadog::Error::Io(e)),
849 }
850 }
851 _ => {
852 local_req_builder = local_req_builder.body(ser.into_inner());
853 }
854 }
855 } else {
856 local_req_builder = local_req_builder.body(ser.into_inner());
857 }
858 }
859
860 local_req_builder = local_req_builder.headers(headers);
861 let local_req = local_req_builder.build()?;
862 log::debug!("request content: {:?}", local_req.body());
863 let local_resp = local_client.execute(local_req).await?;
864
865 let local_status = local_resp.status();
866 let local_content = local_resp.text().await?;
867 log::debug!("response content: {}", local_content);
868
869 if !local_status.is_client_error() && !local_status.is_server_error() {
870 match serde_json::from_str::<crate::datadogV2::model::CIAppPipelineEventsResponse>(
871 &local_content,
872 ) {
873 Ok(e) => {
874 return Ok(datadog::ResponseContent {
875 status: local_status,
876 content: local_content,
877 entity: Some(e),
878 })
879 }
880 Err(e) => return Err(datadog::Error::Serde(e)),
881 };
882 } else {
883 let local_entity: Option<SearchCIAppPipelineEventsError> =
884 serde_json::from_str(&local_content).ok();
885 let local_error = datadog::ResponseContent {
886 status: local_status,
887 content: local_content,
888 entity: local_entity,
889 };
890 Err(datadog::Error::ResponseError(local_error))
891 }
892 }
893}