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