datadog_api_client/datadogV1/api/
api_logs_pipelines.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use 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/// CreateLogsPipelineError is a struct for typed errors of method [`LogsPipelinesAPI::create_logs_pipeline`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateLogsPipelineError {
17    LogsAPIErrorResponse(crate::datadogV1::model::LogsAPIErrorResponse),
18    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
19    UnknownValue(serde_json::Value),
20}
21
22/// DeleteLogsPipelineError is a struct for typed errors of method [`LogsPipelinesAPI::delete_logs_pipeline`]
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum DeleteLogsPipelineError {
26    LogsAPIErrorResponse(crate::datadogV1::model::LogsAPIErrorResponse),
27    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
28    UnknownValue(serde_json::Value),
29}
30
31/// GetLogsPipelineError is a struct for typed errors of method [`LogsPipelinesAPI::get_logs_pipeline`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetLogsPipelineError {
35    LogsAPIErrorResponse(crate::datadogV1::model::LogsAPIErrorResponse),
36    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
37    UnknownValue(serde_json::Value),
38}
39
40/// GetLogsPipelineOrderError is a struct for typed errors of method [`LogsPipelinesAPI::get_logs_pipeline_order`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetLogsPipelineOrderError {
44    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
45    UnknownValue(serde_json::Value),
46}
47
48/// ListLogsPipelinesError is a struct for typed errors of method [`LogsPipelinesAPI::list_logs_pipelines`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum ListLogsPipelinesError {
52    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
53    UnknownValue(serde_json::Value),
54}
55
56/// UpdateLogsPipelineError is a struct for typed errors of method [`LogsPipelinesAPI::update_logs_pipeline`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum UpdateLogsPipelineError {
60    LogsAPIErrorResponse(crate::datadogV1::model::LogsAPIErrorResponse),
61    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
62    UnknownValue(serde_json::Value),
63}
64
65/// UpdateLogsPipelineOrderError is a struct for typed errors of method [`LogsPipelinesAPI::update_logs_pipeline_order`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum UpdateLogsPipelineOrderError {
69    LogsAPIErrorResponse(crate::datadogV1::model::LogsAPIErrorResponse),
70    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
71    UnknownValue(serde_json::Value),
72}
73
74/// Pipelines and processors operate on incoming logs, parsing
75/// and transforming them into structured attributes for easier querying.
76///
77/// - See the [pipelines configuration page](<https://app.datadoghq.com/logs/pipelines>)
78///   for a list of the pipelines and processors currently configured in web UI.
79///
80/// - Additional API-related information about processors can be found in the
81///   [processors documentation](<https://docs.datadoghq.com/logs/log_configuration/processors/?tab=api#lookup-processor>).
82///
83/// - For more information about Pipelines, see the
84///   [pipeline documentation](<https://docs.datadoghq.com/logs/log_configuration/pipelines>).
85///
86/// **Notes:**
87///
88/// **Grok parsing rules may effect JSON output and require
89/// returned data to be configured before using in a request.**
90/// For example, if you are using the data returned from a
91/// request for another request body, and have a parsing rule
92/// that uses a regex pattern like `\s` for spaces, you will
93/// need to configure all escaped spaces as `%{space}` to use
94/// in the body data.
95#[derive(Debug, Clone)]
96pub struct LogsPipelinesAPI {
97    config: datadog::Configuration,
98    client: reqwest_middleware::ClientWithMiddleware,
99}
100
101impl Default for LogsPipelinesAPI {
102    fn default() -> Self {
103        Self::with_config(datadog::Configuration::default())
104    }
105}
106
107impl LogsPipelinesAPI {
108    pub fn new() -> Self {
109        Self::default()
110    }
111    pub fn with_config(config: datadog::Configuration) -> Self {
112        let mut reqwest_client_builder = reqwest::Client::builder();
113
114        if let Some(proxy_url) = &config.proxy_url {
115            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
116            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
117        }
118
119        let mut middleware_client_builder =
120            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
121
122        if config.enable_retry {
123            struct RetryableStatus;
124            impl reqwest_retry::RetryableStrategy for RetryableStatus {
125                fn handle(
126                    &self,
127                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
128                ) -> Option<reqwest_retry::Retryable> {
129                    match res {
130                        Ok(success) => reqwest_retry::default_on_request_success(success),
131                        Err(_) => None,
132                    }
133                }
134            }
135            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
136                .build_with_max_retries(config.max_retries);
137
138            let retry_middleware =
139                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
140                    backoff_policy,
141                    RetryableStatus,
142                );
143
144            middleware_client_builder = middleware_client_builder.with(retry_middleware);
145        }
146
147        let client = middleware_client_builder.build();
148
149        Self { config, client }
150    }
151
152    pub fn with_client_and_config(
153        config: datadog::Configuration,
154        client: reqwest_middleware::ClientWithMiddleware,
155    ) -> Self {
156        Self { config, client }
157    }
158
159    /// Create a pipeline in your organization.
160    pub async fn create_logs_pipeline(
161        &self,
162        body: crate::datadogV1::model::LogsPipeline,
163    ) -> Result<crate::datadogV1::model::LogsPipeline, datadog::Error<CreateLogsPipelineError>>
164    {
165        match self.create_logs_pipeline_with_http_info(body).await {
166            Ok(response_content) => {
167                if let Some(e) = response_content.entity {
168                    Ok(e)
169                } else {
170                    Err(datadog::Error::Serde(serde::de::Error::custom(
171                        "response content was None",
172                    )))
173                }
174            }
175            Err(err) => Err(err),
176        }
177    }
178
179    /// Create a pipeline in your organization.
180    pub async fn create_logs_pipeline_with_http_info(
181        &self,
182        body: crate::datadogV1::model::LogsPipeline,
183    ) -> Result<
184        datadog::ResponseContent<crate::datadogV1::model::LogsPipeline>,
185        datadog::Error<CreateLogsPipelineError>,
186    > {
187        let local_configuration = &self.config;
188        let operation_id = "v1.create_logs_pipeline";
189
190        let local_client = &self.client;
191
192        let local_uri_str = format!(
193            "{}/api/v1/logs/config/pipelines",
194            local_configuration.get_operation_host(operation_id)
195        );
196        let mut local_req_builder =
197            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
198
199        // build headers
200        let mut headers = HeaderMap::new();
201        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
202        headers.insert("Accept", HeaderValue::from_static("application/json"));
203
204        // build user agent
205        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
206            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
207            Err(e) => {
208                log::warn!("Failed to parse user agent header: {e}, falling back to default");
209                headers.insert(
210                    reqwest::header::USER_AGENT,
211                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
212                )
213            }
214        };
215
216        // build auth
217        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
218            headers.insert(
219                "DD-API-KEY",
220                HeaderValue::from_str(local_key.key.as_str())
221                    .expect("failed to parse DD-API-KEY header"),
222            );
223        };
224        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
225            headers.insert(
226                "DD-APPLICATION-KEY",
227                HeaderValue::from_str(local_key.key.as_str())
228                    .expect("failed to parse DD-APPLICATION-KEY header"),
229            );
230        };
231
232        // build body parameters
233        let output = Vec::new();
234        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
235        if body.serialize(&mut ser).is_ok() {
236            if let Some(content_encoding) = headers.get("Content-Encoding") {
237                match content_encoding.to_str().unwrap_or_default() {
238                    "gzip" => {
239                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
240                        let _ = enc.write_all(ser.into_inner().as_slice());
241                        match enc.finish() {
242                            Ok(buf) => {
243                                local_req_builder = local_req_builder.body(buf);
244                            }
245                            Err(e) => return Err(datadog::Error::Io(e)),
246                        }
247                    }
248                    "deflate" => {
249                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
250                        let _ = enc.write_all(ser.into_inner().as_slice());
251                        match enc.finish() {
252                            Ok(buf) => {
253                                local_req_builder = local_req_builder.body(buf);
254                            }
255                            Err(e) => return Err(datadog::Error::Io(e)),
256                        }
257                    }
258                    "zstd1" => {
259                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
260                        let _ = enc.write_all(ser.into_inner().as_slice());
261                        match enc.finish() {
262                            Ok(buf) => {
263                                local_req_builder = local_req_builder.body(buf);
264                            }
265                            Err(e) => return Err(datadog::Error::Io(e)),
266                        }
267                    }
268                    _ => {
269                        local_req_builder = local_req_builder.body(ser.into_inner());
270                    }
271                }
272            } else {
273                local_req_builder = local_req_builder.body(ser.into_inner());
274            }
275        }
276
277        local_req_builder = local_req_builder.headers(headers);
278        let local_req = local_req_builder.build()?;
279        log::debug!("request content: {:?}", local_req.body());
280        let local_resp = local_client.execute(local_req).await?;
281
282        let local_status = local_resp.status();
283        let local_content = local_resp.text().await?;
284        log::debug!("response content: {}", local_content);
285
286        if !local_status.is_client_error() && !local_status.is_server_error() {
287            match serde_json::from_str::<crate::datadogV1::model::LogsPipeline>(&local_content) {
288                Ok(e) => {
289                    return Ok(datadog::ResponseContent {
290                        status: local_status,
291                        content: local_content,
292                        entity: Some(e),
293                    })
294                }
295                Err(e) => return Err(datadog::Error::Serde(e)),
296            };
297        } else {
298            let local_entity: Option<CreateLogsPipelineError> =
299                serde_json::from_str(&local_content).ok();
300            let local_error = datadog::ResponseContent {
301                status: local_status,
302                content: local_content,
303                entity: local_entity,
304            };
305            Err(datadog::Error::ResponseError(local_error))
306        }
307    }
308
309    /// Delete a given pipeline from your organization.
310    /// This endpoint takes no JSON arguments.
311    pub async fn delete_logs_pipeline(
312        &self,
313        pipeline_id: String,
314    ) -> Result<(), datadog::Error<DeleteLogsPipelineError>> {
315        match self.delete_logs_pipeline_with_http_info(pipeline_id).await {
316            Ok(_) => Ok(()),
317            Err(err) => Err(err),
318        }
319    }
320
321    /// Delete a given pipeline from your organization.
322    /// This endpoint takes no JSON arguments.
323    pub async fn delete_logs_pipeline_with_http_info(
324        &self,
325        pipeline_id: String,
326    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteLogsPipelineError>> {
327        let local_configuration = &self.config;
328        let operation_id = "v1.delete_logs_pipeline";
329
330        let local_client = &self.client;
331
332        let local_uri_str = format!(
333            "{}/api/v1/logs/config/pipelines/{pipeline_id}",
334            local_configuration.get_operation_host(operation_id),
335            pipeline_id = datadog::urlencode(pipeline_id)
336        );
337        let mut local_req_builder =
338            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
339
340        // build headers
341        let mut headers = HeaderMap::new();
342        headers.insert("Accept", HeaderValue::from_static("*/*"));
343
344        // build user agent
345        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
346            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
347            Err(e) => {
348                log::warn!("Failed to parse user agent header: {e}, falling back to default");
349                headers.insert(
350                    reqwest::header::USER_AGENT,
351                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
352                )
353            }
354        };
355
356        // build auth
357        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
358            headers.insert(
359                "DD-API-KEY",
360                HeaderValue::from_str(local_key.key.as_str())
361                    .expect("failed to parse DD-API-KEY header"),
362            );
363        };
364        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
365            headers.insert(
366                "DD-APPLICATION-KEY",
367                HeaderValue::from_str(local_key.key.as_str())
368                    .expect("failed to parse DD-APPLICATION-KEY header"),
369            );
370        };
371
372        local_req_builder = local_req_builder.headers(headers);
373        let local_req = local_req_builder.build()?;
374        log::debug!("request content: {:?}", local_req.body());
375        let local_resp = local_client.execute(local_req).await?;
376
377        let local_status = local_resp.status();
378        let local_content = local_resp.text().await?;
379        log::debug!("response content: {}", local_content);
380
381        if !local_status.is_client_error() && !local_status.is_server_error() {
382            Ok(datadog::ResponseContent {
383                status: local_status,
384                content: local_content,
385                entity: None,
386            })
387        } else {
388            let local_entity: Option<DeleteLogsPipelineError> =
389                serde_json::from_str(&local_content).ok();
390            let local_error = datadog::ResponseContent {
391                status: local_status,
392                content: local_content,
393                entity: local_entity,
394            };
395            Err(datadog::Error::ResponseError(local_error))
396        }
397    }
398
399    /// Get a specific pipeline from your organization.
400    /// This endpoint takes no JSON arguments.
401    pub async fn get_logs_pipeline(
402        &self,
403        pipeline_id: String,
404    ) -> Result<crate::datadogV1::model::LogsPipeline, datadog::Error<GetLogsPipelineError>> {
405        match self.get_logs_pipeline_with_http_info(pipeline_id).await {
406            Ok(response_content) => {
407                if let Some(e) = response_content.entity {
408                    Ok(e)
409                } else {
410                    Err(datadog::Error::Serde(serde::de::Error::custom(
411                        "response content was None",
412                    )))
413                }
414            }
415            Err(err) => Err(err),
416        }
417    }
418
419    /// Get a specific pipeline from your organization.
420    /// This endpoint takes no JSON arguments.
421    pub async fn get_logs_pipeline_with_http_info(
422        &self,
423        pipeline_id: String,
424    ) -> Result<
425        datadog::ResponseContent<crate::datadogV1::model::LogsPipeline>,
426        datadog::Error<GetLogsPipelineError>,
427    > {
428        let local_configuration = &self.config;
429        let operation_id = "v1.get_logs_pipeline";
430
431        let local_client = &self.client;
432
433        let local_uri_str = format!(
434            "{}/api/v1/logs/config/pipelines/{pipeline_id}",
435            local_configuration.get_operation_host(operation_id),
436            pipeline_id = datadog::urlencode(pipeline_id)
437        );
438        let mut local_req_builder =
439            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
440
441        // build headers
442        let mut headers = HeaderMap::new();
443        headers.insert("Accept", HeaderValue::from_static("application/json"));
444
445        // build user agent
446        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
447            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
448            Err(e) => {
449                log::warn!("Failed to parse user agent header: {e}, falling back to default");
450                headers.insert(
451                    reqwest::header::USER_AGENT,
452                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
453                )
454            }
455        };
456
457        // build auth
458        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
459            headers.insert(
460                "DD-API-KEY",
461                HeaderValue::from_str(local_key.key.as_str())
462                    .expect("failed to parse DD-API-KEY header"),
463            );
464        };
465        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
466            headers.insert(
467                "DD-APPLICATION-KEY",
468                HeaderValue::from_str(local_key.key.as_str())
469                    .expect("failed to parse DD-APPLICATION-KEY header"),
470            );
471        };
472
473        local_req_builder = local_req_builder.headers(headers);
474        let local_req = local_req_builder.build()?;
475        log::debug!("request content: {:?}", local_req.body());
476        let local_resp = local_client.execute(local_req).await?;
477
478        let local_status = local_resp.status();
479        let local_content = local_resp.text().await?;
480        log::debug!("response content: {}", local_content);
481
482        if !local_status.is_client_error() && !local_status.is_server_error() {
483            match serde_json::from_str::<crate::datadogV1::model::LogsPipeline>(&local_content) {
484                Ok(e) => {
485                    return Ok(datadog::ResponseContent {
486                        status: local_status,
487                        content: local_content,
488                        entity: Some(e),
489                    })
490                }
491                Err(e) => return Err(datadog::Error::Serde(e)),
492            };
493        } else {
494            let local_entity: Option<GetLogsPipelineError> =
495                serde_json::from_str(&local_content).ok();
496            let local_error = datadog::ResponseContent {
497                status: local_status,
498                content: local_content,
499                entity: local_entity,
500            };
501            Err(datadog::Error::ResponseError(local_error))
502        }
503    }
504
505    /// Get the current order of your pipelines.
506    /// This endpoint takes no JSON arguments.
507    pub async fn get_logs_pipeline_order(
508        &self,
509    ) -> Result<
510        crate::datadogV1::model::LogsPipelinesOrder,
511        datadog::Error<GetLogsPipelineOrderError>,
512    > {
513        match self.get_logs_pipeline_order_with_http_info().await {
514            Ok(response_content) => {
515                if let Some(e) = response_content.entity {
516                    Ok(e)
517                } else {
518                    Err(datadog::Error::Serde(serde::de::Error::custom(
519                        "response content was None",
520                    )))
521                }
522            }
523            Err(err) => Err(err),
524        }
525    }
526
527    /// Get the current order of your pipelines.
528    /// This endpoint takes no JSON arguments.
529    pub async fn get_logs_pipeline_order_with_http_info(
530        &self,
531    ) -> Result<
532        datadog::ResponseContent<crate::datadogV1::model::LogsPipelinesOrder>,
533        datadog::Error<GetLogsPipelineOrderError>,
534    > {
535        let local_configuration = &self.config;
536        let operation_id = "v1.get_logs_pipeline_order";
537
538        let local_client = &self.client;
539
540        let local_uri_str = format!(
541            "{}/api/v1/logs/config/pipeline-order",
542            local_configuration.get_operation_host(operation_id)
543        );
544        let mut local_req_builder =
545            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
546
547        // build headers
548        let mut headers = HeaderMap::new();
549        headers.insert("Accept", HeaderValue::from_static("application/json"));
550
551        // build user agent
552        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
553            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
554            Err(e) => {
555                log::warn!("Failed to parse user agent header: {e}, falling back to default");
556                headers.insert(
557                    reqwest::header::USER_AGENT,
558                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
559                )
560            }
561        };
562
563        // build auth
564        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
565            headers.insert(
566                "DD-API-KEY",
567                HeaderValue::from_str(local_key.key.as_str())
568                    .expect("failed to parse DD-API-KEY header"),
569            );
570        };
571        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
572            headers.insert(
573                "DD-APPLICATION-KEY",
574                HeaderValue::from_str(local_key.key.as_str())
575                    .expect("failed to parse DD-APPLICATION-KEY header"),
576            );
577        };
578
579        local_req_builder = local_req_builder.headers(headers);
580        let local_req = local_req_builder.build()?;
581        log::debug!("request content: {:?}", local_req.body());
582        let local_resp = local_client.execute(local_req).await?;
583
584        let local_status = local_resp.status();
585        let local_content = local_resp.text().await?;
586        log::debug!("response content: {}", local_content);
587
588        if !local_status.is_client_error() && !local_status.is_server_error() {
589            match serde_json::from_str::<crate::datadogV1::model::LogsPipelinesOrder>(
590                &local_content,
591            ) {
592                Ok(e) => {
593                    return Ok(datadog::ResponseContent {
594                        status: local_status,
595                        content: local_content,
596                        entity: Some(e),
597                    })
598                }
599                Err(e) => return Err(datadog::Error::Serde(e)),
600            };
601        } else {
602            let local_entity: Option<GetLogsPipelineOrderError> =
603                serde_json::from_str(&local_content).ok();
604            let local_error = datadog::ResponseContent {
605                status: local_status,
606                content: local_content,
607                entity: local_entity,
608            };
609            Err(datadog::Error::ResponseError(local_error))
610        }
611    }
612
613    /// Get all pipelines from your organization.
614    /// This endpoint takes no JSON arguments.
615    pub async fn list_logs_pipelines(
616        &self,
617    ) -> Result<Vec<crate::datadogV1::model::LogsPipeline>, datadog::Error<ListLogsPipelinesError>>
618    {
619        match self.list_logs_pipelines_with_http_info().await {
620            Ok(response_content) => {
621                if let Some(e) = response_content.entity {
622                    Ok(e)
623                } else {
624                    Err(datadog::Error::Serde(serde::de::Error::custom(
625                        "response content was None",
626                    )))
627                }
628            }
629            Err(err) => Err(err),
630        }
631    }
632
633    /// Get all pipelines from your organization.
634    /// This endpoint takes no JSON arguments.
635    pub async fn list_logs_pipelines_with_http_info(
636        &self,
637    ) -> Result<
638        datadog::ResponseContent<Vec<crate::datadogV1::model::LogsPipeline>>,
639        datadog::Error<ListLogsPipelinesError>,
640    > {
641        let local_configuration = &self.config;
642        let operation_id = "v1.list_logs_pipelines";
643
644        let local_client = &self.client;
645
646        let local_uri_str = format!(
647            "{}/api/v1/logs/config/pipelines",
648            local_configuration.get_operation_host(operation_id)
649        );
650        let mut local_req_builder =
651            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
652
653        // build headers
654        let mut headers = HeaderMap::new();
655        headers.insert("Accept", HeaderValue::from_static("application/json"));
656
657        // build user agent
658        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
659            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
660            Err(e) => {
661                log::warn!("Failed to parse user agent header: {e}, falling back to default");
662                headers.insert(
663                    reqwest::header::USER_AGENT,
664                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
665                )
666            }
667        };
668
669        // build auth
670        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
671            headers.insert(
672                "DD-API-KEY",
673                HeaderValue::from_str(local_key.key.as_str())
674                    .expect("failed to parse DD-API-KEY header"),
675            );
676        };
677        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
678            headers.insert(
679                "DD-APPLICATION-KEY",
680                HeaderValue::from_str(local_key.key.as_str())
681                    .expect("failed to parse DD-APPLICATION-KEY header"),
682            );
683        };
684
685        local_req_builder = local_req_builder.headers(headers);
686        let local_req = local_req_builder.build()?;
687        log::debug!("request content: {:?}", local_req.body());
688        let local_resp = local_client.execute(local_req).await?;
689
690        let local_status = local_resp.status();
691        let local_content = local_resp.text().await?;
692        log::debug!("response content: {}", local_content);
693
694        if !local_status.is_client_error() && !local_status.is_server_error() {
695            match serde_json::from_str::<Vec<crate::datadogV1::model::LogsPipeline>>(&local_content)
696            {
697                Ok(e) => {
698                    return Ok(datadog::ResponseContent {
699                        status: local_status,
700                        content: local_content,
701                        entity: Some(e),
702                    })
703                }
704                Err(e) => return Err(datadog::Error::Serde(e)),
705            };
706        } else {
707            let local_entity: Option<ListLogsPipelinesError> =
708                serde_json::from_str(&local_content).ok();
709            let local_error = datadog::ResponseContent {
710                status: local_status,
711                content: local_content,
712                entity: local_entity,
713            };
714            Err(datadog::Error::ResponseError(local_error))
715        }
716    }
717
718    /// Update a given pipeline configuration to change it’s processors or their order.
719    ///
720    /// **Note**: Using this method updates your pipeline configuration by **replacing**
721    /// your current configuration with the new one sent to your Datadog organization.
722    pub async fn update_logs_pipeline(
723        &self,
724        pipeline_id: String,
725        body: crate::datadogV1::model::LogsPipeline,
726    ) -> Result<crate::datadogV1::model::LogsPipeline, datadog::Error<UpdateLogsPipelineError>>
727    {
728        match self
729            .update_logs_pipeline_with_http_info(pipeline_id, body)
730            .await
731        {
732            Ok(response_content) => {
733                if let Some(e) = response_content.entity {
734                    Ok(e)
735                } else {
736                    Err(datadog::Error::Serde(serde::de::Error::custom(
737                        "response content was None",
738                    )))
739                }
740            }
741            Err(err) => Err(err),
742        }
743    }
744
745    /// Update a given pipeline configuration to change it’s processors or their order.
746    ///
747    /// **Note**: Using this method updates your pipeline configuration by **replacing**
748    /// your current configuration with the new one sent to your Datadog organization.
749    pub async fn update_logs_pipeline_with_http_info(
750        &self,
751        pipeline_id: String,
752        body: crate::datadogV1::model::LogsPipeline,
753    ) -> Result<
754        datadog::ResponseContent<crate::datadogV1::model::LogsPipeline>,
755        datadog::Error<UpdateLogsPipelineError>,
756    > {
757        let local_configuration = &self.config;
758        let operation_id = "v1.update_logs_pipeline";
759
760        let local_client = &self.client;
761
762        let local_uri_str = format!(
763            "{}/api/v1/logs/config/pipelines/{pipeline_id}",
764            local_configuration.get_operation_host(operation_id),
765            pipeline_id = datadog::urlencode(pipeline_id)
766        );
767        let mut local_req_builder =
768            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
769
770        // build headers
771        let mut headers = HeaderMap::new();
772        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
773        headers.insert("Accept", HeaderValue::from_static("application/json"));
774
775        // build user agent
776        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
777            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
778            Err(e) => {
779                log::warn!("Failed to parse user agent header: {e}, falling back to default");
780                headers.insert(
781                    reqwest::header::USER_AGENT,
782                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
783                )
784            }
785        };
786
787        // build auth
788        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
789            headers.insert(
790                "DD-API-KEY",
791                HeaderValue::from_str(local_key.key.as_str())
792                    .expect("failed to parse DD-API-KEY header"),
793            );
794        };
795        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
796            headers.insert(
797                "DD-APPLICATION-KEY",
798                HeaderValue::from_str(local_key.key.as_str())
799                    .expect("failed to parse DD-APPLICATION-KEY header"),
800            );
801        };
802
803        // build body parameters
804        let output = Vec::new();
805        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
806        if body.serialize(&mut ser).is_ok() {
807            if let Some(content_encoding) = headers.get("Content-Encoding") {
808                match content_encoding.to_str().unwrap_or_default() {
809                    "gzip" => {
810                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
811                        let _ = enc.write_all(ser.into_inner().as_slice());
812                        match enc.finish() {
813                            Ok(buf) => {
814                                local_req_builder = local_req_builder.body(buf);
815                            }
816                            Err(e) => return Err(datadog::Error::Io(e)),
817                        }
818                    }
819                    "deflate" => {
820                        let mut enc = ZlibEncoder::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                    "zstd1" => {
830                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
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                    _ => {
840                        local_req_builder = local_req_builder.body(ser.into_inner());
841                    }
842                }
843            } else {
844                local_req_builder = local_req_builder.body(ser.into_inner());
845            }
846        }
847
848        local_req_builder = local_req_builder.headers(headers);
849        let local_req = local_req_builder.build()?;
850        log::debug!("request content: {:?}", local_req.body());
851        let local_resp = local_client.execute(local_req).await?;
852
853        let local_status = local_resp.status();
854        let local_content = local_resp.text().await?;
855        log::debug!("response content: {}", local_content);
856
857        if !local_status.is_client_error() && !local_status.is_server_error() {
858            match serde_json::from_str::<crate::datadogV1::model::LogsPipeline>(&local_content) {
859                Ok(e) => {
860                    return Ok(datadog::ResponseContent {
861                        status: local_status,
862                        content: local_content,
863                        entity: Some(e),
864                    })
865                }
866                Err(e) => return Err(datadog::Error::Serde(e)),
867            };
868        } else {
869            let local_entity: Option<UpdateLogsPipelineError> =
870                serde_json::from_str(&local_content).ok();
871            let local_error = datadog::ResponseContent {
872                status: local_status,
873                content: local_content,
874                entity: local_entity,
875            };
876            Err(datadog::Error::ResponseError(local_error))
877        }
878    }
879
880    /// Update the order of your pipelines. Since logs are processed sequentially, reordering a pipeline may change
881    /// the structure and content of the data processed by other pipelines and their processors.
882    ///
883    /// **Note**: Using the `PUT` method updates your pipeline order by replacing your current order
884    /// with the new one sent to your Datadog organization.
885    pub async fn update_logs_pipeline_order(
886        &self,
887        body: crate::datadogV1::model::LogsPipelinesOrder,
888    ) -> Result<
889        crate::datadogV1::model::LogsPipelinesOrder,
890        datadog::Error<UpdateLogsPipelineOrderError>,
891    > {
892        match self.update_logs_pipeline_order_with_http_info(body).await {
893            Ok(response_content) => {
894                if let Some(e) = response_content.entity {
895                    Ok(e)
896                } else {
897                    Err(datadog::Error::Serde(serde::de::Error::custom(
898                        "response content was None",
899                    )))
900                }
901            }
902            Err(err) => Err(err),
903        }
904    }
905
906    /// Update the order of your pipelines. Since logs are processed sequentially, reordering a pipeline may change
907    /// the structure and content of the data processed by other pipelines and their processors.
908    ///
909    /// **Note**: Using the `PUT` method updates your pipeline order by replacing your current order
910    /// with the new one sent to your Datadog organization.
911    pub async fn update_logs_pipeline_order_with_http_info(
912        &self,
913        body: crate::datadogV1::model::LogsPipelinesOrder,
914    ) -> Result<
915        datadog::ResponseContent<crate::datadogV1::model::LogsPipelinesOrder>,
916        datadog::Error<UpdateLogsPipelineOrderError>,
917    > {
918        let local_configuration = &self.config;
919        let operation_id = "v1.update_logs_pipeline_order";
920
921        let local_client = &self.client;
922
923        let local_uri_str = format!(
924            "{}/api/v1/logs/config/pipeline-order",
925            local_configuration.get_operation_host(operation_id)
926        );
927        let mut local_req_builder =
928            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
929
930        // build headers
931        let mut headers = HeaderMap::new();
932        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
933        headers.insert("Accept", HeaderValue::from_static("application/json"));
934
935        // build user agent
936        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
937            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
938            Err(e) => {
939                log::warn!("Failed to parse user agent header: {e}, falling back to default");
940                headers.insert(
941                    reqwest::header::USER_AGENT,
942                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
943                )
944            }
945        };
946
947        // build auth
948        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
949            headers.insert(
950                "DD-API-KEY",
951                HeaderValue::from_str(local_key.key.as_str())
952                    .expect("failed to parse DD-API-KEY header"),
953            );
954        };
955        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
956            headers.insert(
957                "DD-APPLICATION-KEY",
958                HeaderValue::from_str(local_key.key.as_str())
959                    .expect("failed to parse DD-APPLICATION-KEY header"),
960            );
961        };
962
963        // build body parameters
964        let output = Vec::new();
965        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
966        if body.serialize(&mut ser).is_ok() {
967            if let Some(content_encoding) = headers.get("Content-Encoding") {
968                match content_encoding.to_str().unwrap_or_default() {
969                    "gzip" => {
970                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
971                        let _ = enc.write_all(ser.into_inner().as_slice());
972                        match enc.finish() {
973                            Ok(buf) => {
974                                local_req_builder = local_req_builder.body(buf);
975                            }
976                            Err(e) => return Err(datadog::Error::Io(e)),
977                        }
978                    }
979                    "deflate" => {
980                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
981                        let _ = enc.write_all(ser.into_inner().as_slice());
982                        match enc.finish() {
983                            Ok(buf) => {
984                                local_req_builder = local_req_builder.body(buf);
985                            }
986                            Err(e) => return Err(datadog::Error::Io(e)),
987                        }
988                    }
989                    "zstd1" => {
990                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
991                        let _ = enc.write_all(ser.into_inner().as_slice());
992                        match enc.finish() {
993                            Ok(buf) => {
994                                local_req_builder = local_req_builder.body(buf);
995                            }
996                            Err(e) => return Err(datadog::Error::Io(e)),
997                        }
998                    }
999                    _ => {
1000                        local_req_builder = local_req_builder.body(ser.into_inner());
1001                    }
1002                }
1003            } else {
1004                local_req_builder = local_req_builder.body(ser.into_inner());
1005            }
1006        }
1007
1008        local_req_builder = local_req_builder.headers(headers);
1009        let local_req = local_req_builder.build()?;
1010        log::debug!("request content: {:?}", local_req.body());
1011        let local_resp = local_client.execute(local_req).await?;
1012
1013        let local_status = local_resp.status();
1014        let local_content = local_resp.text().await?;
1015        log::debug!("response content: {}", local_content);
1016
1017        if !local_status.is_client_error() && !local_status.is_server_error() {
1018            match serde_json::from_str::<crate::datadogV1::model::LogsPipelinesOrder>(
1019                &local_content,
1020            ) {
1021                Ok(e) => {
1022                    return Ok(datadog::ResponseContent {
1023                        status: local_status,
1024                        content: local_content,
1025                        entity: Some(e),
1026                    })
1027                }
1028                Err(e) => return Err(datadog::Error::Serde(e)),
1029            };
1030        } else {
1031            let local_entity: Option<UpdateLogsPipelineOrderError> =
1032                serde_json::from_str(&local_content).ok();
1033            let local_error = datadog::ResponseContent {
1034                status: local_status,
1035                content: local_content,
1036                entity: local_entity,
1037            };
1038            Err(datadog::Error::ResponseError(local_error))
1039        }
1040    }
1041}