datadog_api_client/datadogV2/api/
api_actions_datastores.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/// ListDatastoreItemsOptionalParams is a struct for passing parameters to the method [`ActionsDatastoresAPI::list_datastore_items`]
14#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct ListDatastoreItemsOptionalParams {
17    /// Optional query filter to search items using the [logs search syntax](<https://docs.datadoghq.com/logs/explorer/search_syntax/>).
18    pub filter: Option<String>,
19    /// Optional primary key value to retrieve a specific item. Cannot be used together with the filter parameter.
20    pub item_key: Option<String>,
21    /// Optional field to limit the number of items to return per page for pagination. Up to 100 items can be returned per page.
22    pub page_limit: Option<i64>,
23    /// Optional field to offset the number of items to skip from the beginning of the result set for pagination.
24    pub page_offset: Option<i64>,
25    /// Optional field to sort results by. Prefix with '-' for descending order (e.g., '-created_at').
26    pub sort: Option<String>,
27}
28
29impl ListDatastoreItemsOptionalParams {
30    /// Optional query filter to search items using the [logs search syntax](<https://docs.datadoghq.com/logs/explorer/search_syntax/>).
31    pub fn filter(mut self, value: String) -> Self {
32        self.filter = Some(value);
33        self
34    }
35    /// Optional primary key value to retrieve a specific item. Cannot be used together with the filter parameter.
36    pub fn item_key(mut self, value: String) -> Self {
37        self.item_key = Some(value);
38        self
39    }
40    /// Optional field to limit the number of items to return per page for pagination. Up to 100 items can be returned per page.
41    pub fn page_limit(mut self, value: i64) -> Self {
42        self.page_limit = Some(value);
43        self
44    }
45    /// Optional field to offset the number of items to skip from the beginning of the result set for pagination.
46    pub fn page_offset(mut self, value: i64) -> Self {
47        self.page_offset = Some(value);
48        self
49    }
50    /// Optional field to sort results by. Prefix with '-' for descending order (e.g., '-created_at').
51    pub fn sort(mut self, value: String) -> Self {
52        self.sort = Some(value);
53        self
54    }
55}
56
57/// BulkDeleteDatastoreItemsError is a struct for typed errors of method [`ActionsDatastoresAPI::bulk_delete_datastore_items`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum BulkDeleteDatastoreItemsError {
61    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
62    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66/// BulkWriteDatastoreItemsError is a struct for typed errors of method [`ActionsDatastoresAPI::bulk_write_datastore_items`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum BulkWriteDatastoreItemsError {
70    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
71    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
72    UnknownValue(serde_json::Value),
73}
74
75/// CreateDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::create_datastore`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum CreateDatastoreError {
79    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
80    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
81    UnknownValue(serde_json::Value),
82}
83
84/// DeleteDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::delete_datastore`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum DeleteDatastoreError {
88    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
89    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90    UnknownValue(serde_json::Value),
91}
92
93/// DeleteDatastoreItemError is a struct for typed errors of method [`ActionsDatastoresAPI::delete_datastore_item`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum DeleteDatastoreItemError {
97    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
98    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
99    UnknownValue(serde_json::Value),
100}
101
102/// GetDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::get_datastore`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum GetDatastoreError {
106    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
107    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
108    UnknownValue(serde_json::Value),
109}
110
111/// ListDatastoreItemsError is a struct for typed errors of method [`ActionsDatastoresAPI::list_datastore_items`]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum ListDatastoreItemsError {
115    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
116    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
117    UnknownValue(serde_json::Value),
118}
119
120/// ListDatastoresError is a struct for typed errors of method [`ActionsDatastoresAPI::list_datastores`]
121#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum ListDatastoresError {
124    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
125    UnknownValue(serde_json::Value),
126}
127
128/// UpdateDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::update_datastore`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum UpdateDatastoreError {
132    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
133    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
134    UnknownValue(serde_json::Value),
135}
136
137/// UpdateDatastoreItemError is a struct for typed errors of method [`ActionsDatastoresAPI::update_datastore_item`]
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum UpdateDatastoreItemError {
141    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
142    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
143    UnknownValue(serde_json::Value),
144}
145
146/// Leverage the Actions Datastore API to create, modify, and delete
147/// items in datastores owned by your organization.
148#[derive(Debug, Clone)]
149pub struct ActionsDatastoresAPI {
150    config: datadog::Configuration,
151    client: reqwest_middleware::ClientWithMiddleware,
152}
153
154impl Default for ActionsDatastoresAPI {
155    fn default() -> Self {
156        Self::with_config(datadog::Configuration::default())
157    }
158}
159
160impl ActionsDatastoresAPI {
161    pub fn new() -> Self {
162        Self::default()
163    }
164    pub fn with_config(config: datadog::Configuration) -> Self {
165        let mut reqwest_client_builder = reqwest::Client::builder();
166
167        if let Some(proxy_url) = &config.proxy_url {
168            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
169            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
170        }
171
172        let mut middleware_client_builder =
173            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
174
175        if config.enable_retry {
176            struct RetryableStatus;
177            impl reqwest_retry::RetryableStrategy for RetryableStatus {
178                fn handle(
179                    &self,
180                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
181                ) -> Option<reqwest_retry::Retryable> {
182                    match res {
183                        Ok(success) => reqwest_retry::default_on_request_success(success),
184                        Err(_) => None,
185                    }
186                }
187            }
188            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
189                .build_with_max_retries(config.max_retries);
190
191            let retry_middleware =
192                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
193                    backoff_policy,
194                    RetryableStatus,
195                );
196
197            middleware_client_builder = middleware_client_builder.with(retry_middleware);
198        }
199
200        let client = middleware_client_builder.build();
201
202        Self { config, client }
203    }
204
205    pub fn with_client_and_config(
206        config: datadog::Configuration,
207        client: reqwest_middleware::ClientWithMiddleware,
208    ) -> Self {
209        Self { config, client }
210    }
211
212    /// Deletes multiple items from a datastore by their keys in a single operation.
213    pub async fn bulk_delete_datastore_items(
214        &self,
215        datastore_id: String,
216        body: crate::datadogV2::model::BulkDeleteAppsDatastoreItemsRequest,
217    ) -> Result<
218        crate::datadogV2::model::DeleteAppsDatastoreItemResponseArray,
219        datadog::Error<BulkDeleteDatastoreItemsError>,
220    > {
221        match self
222            .bulk_delete_datastore_items_with_http_info(datastore_id, body)
223            .await
224        {
225            Ok(response_content) => {
226                if let Some(e) = response_content.entity {
227                    Ok(e)
228                } else {
229                    Err(datadog::Error::Serde(serde::de::Error::custom(
230                        "response content was None",
231                    )))
232                }
233            }
234            Err(err) => Err(err),
235        }
236    }
237
238    /// Deletes multiple items from a datastore by their keys in a single operation.
239    pub async fn bulk_delete_datastore_items_with_http_info(
240        &self,
241        datastore_id: String,
242        body: crate::datadogV2::model::BulkDeleteAppsDatastoreItemsRequest,
243    ) -> Result<
244        datadog::ResponseContent<crate::datadogV2::model::DeleteAppsDatastoreItemResponseArray>,
245        datadog::Error<BulkDeleteDatastoreItemsError>,
246    > {
247        let local_configuration = &self.config;
248        let operation_id = "v2.bulk_delete_datastore_items";
249
250        let local_client = &self.client;
251
252        let local_uri_str = format!(
253            "{}/api/v2/actions-datastores/{datastore_id}/items/bulk",
254            local_configuration.get_operation_host(operation_id),
255            datastore_id = datadog::urlencode(datastore_id)
256        );
257        let mut local_req_builder =
258            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
259
260        // build headers
261        let mut headers = HeaderMap::new();
262        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
263        headers.insert("Accept", HeaderValue::from_static("application/json"));
264
265        // build user agent
266        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
267            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
268            Err(e) => {
269                log::warn!("Failed to parse user agent header: {e}, falling back to default");
270                headers.insert(
271                    reqwest::header::USER_AGENT,
272                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
273                )
274            }
275        };
276
277        // build auth
278        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
279            headers.insert(
280                "DD-API-KEY",
281                HeaderValue::from_str(local_key.key.as_str())
282                    .expect("failed to parse DD-API-KEY header"),
283            );
284        };
285        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
286            headers.insert(
287                "DD-APPLICATION-KEY",
288                HeaderValue::from_str(local_key.key.as_str())
289                    .expect("failed to parse DD-APPLICATION-KEY header"),
290            );
291        };
292
293        // build body parameters
294        let output = Vec::new();
295        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
296        if body.serialize(&mut ser).is_ok() {
297            if let Some(content_encoding) = headers.get("Content-Encoding") {
298                match content_encoding.to_str().unwrap_or_default() {
299                    "gzip" => {
300                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
301                        let _ = enc.write_all(ser.into_inner().as_slice());
302                        match enc.finish() {
303                            Ok(buf) => {
304                                local_req_builder = local_req_builder.body(buf);
305                            }
306                            Err(e) => return Err(datadog::Error::Io(e)),
307                        }
308                    }
309                    "deflate" => {
310                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
311                        let _ = enc.write_all(ser.into_inner().as_slice());
312                        match enc.finish() {
313                            Ok(buf) => {
314                                local_req_builder = local_req_builder.body(buf);
315                            }
316                            Err(e) => return Err(datadog::Error::Io(e)),
317                        }
318                    }
319                    "zstd1" => {
320                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
321                        let _ = enc.write_all(ser.into_inner().as_slice());
322                        match enc.finish() {
323                            Ok(buf) => {
324                                local_req_builder = local_req_builder.body(buf);
325                            }
326                            Err(e) => return Err(datadog::Error::Io(e)),
327                        }
328                    }
329                    _ => {
330                        local_req_builder = local_req_builder.body(ser.into_inner());
331                    }
332                }
333            } else {
334                local_req_builder = local_req_builder.body(ser.into_inner());
335            }
336        }
337
338        local_req_builder = local_req_builder.headers(headers);
339        let local_req = local_req_builder.build()?;
340        log::debug!("request content: {:?}", local_req.body());
341        let local_resp = local_client.execute(local_req).await?;
342
343        let local_status = local_resp.status();
344        let local_content = local_resp.text().await?;
345        log::debug!("response content: {}", local_content);
346
347        if !local_status.is_client_error() && !local_status.is_server_error() {
348            match serde_json::from_str::<
349                crate::datadogV2::model::DeleteAppsDatastoreItemResponseArray,
350            >(&local_content)
351            {
352                Ok(e) => {
353                    return Ok(datadog::ResponseContent {
354                        status: local_status,
355                        content: local_content,
356                        entity: Some(e),
357                    })
358                }
359                Err(e) => return Err(datadog::Error::Serde(e)),
360            };
361        } else {
362            let local_entity: Option<BulkDeleteDatastoreItemsError> =
363                serde_json::from_str(&local_content).ok();
364            let local_error = datadog::ResponseContent {
365                status: local_status,
366                content: local_content,
367                entity: local_entity,
368            };
369            Err(datadog::Error::ResponseError(local_error))
370        }
371    }
372
373    /// Creates or replaces multiple items in a datastore by their keys in a single operation.
374    pub async fn bulk_write_datastore_items(
375        &self,
376        datastore_id: String,
377        body: crate::datadogV2::model::BulkPutAppsDatastoreItemsRequest,
378    ) -> Result<
379        crate::datadogV2::model::PutAppsDatastoreItemResponseArray,
380        datadog::Error<BulkWriteDatastoreItemsError>,
381    > {
382        match self
383            .bulk_write_datastore_items_with_http_info(datastore_id, body)
384            .await
385        {
386            Ok(response_content) => {
387                if let Some(e) = response_content.entity {
388                    Ok(e)
389                } else {
390                    Err(datadog::Error::Serde(serde::de::Error::custom(
391                        "response content was None",
392                    )))
393                }
394            }
395            Err(err) => Err(err),
396        }
397    }
398
399    /// Creates or replaces multiple items in a datastore by their keys in a single operation.
400    pub async fn bulk_write_datastore_items_with_http_info(
401        &self,
402        datastore_id: String,
403        body: crate::datadogV2::model::BulkPutAppsDatastoreItemsRequest,
404    ) -> Result<
405        datadog::ResponseContent<crate::datadogV2::model::PutAppsDatastoreItemResponseArray>,
406        datadog::Error<BulkWriteDatastoreItemsError>,
407    > {
408        let local_configuration = &self.config;
409        let operation_id = "v2.bulk_write_datastore_items";
410
411        let local_client = &self.client;
412
413        let local_uri_str = format!(
414            "{}/api/v2/actions-datastores/{datastore_id}/items/bulk",
415            local_configuration.get_operation_host(operation_id),
416            datastore_id = datadog::urlencode(datastore_id)
417        );
418        let mut local_req_builder =
419            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
420
421        // build headers
422        let mut headers = HeaderMap::new();
423        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
424        headers.insert("Accept", HeaderValue::from_static("application/json"));
425
426        // build user agent
427        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
428            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
429            Err(e) => {
430                log::warn!("Failed to parse user agent header: {e}, falling back to default");
431                headers.insert(
432                    reqwest::header::USER_AGENT,
433                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
434                )
435            }
436        };
437
438        // build auth
439        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
440            headers.insert(
441                "DD-API-KEY",
442                HeaderValue::from_str(local_key.key.as_str())
443                    .expect("failed to parse DD-API-KEY header"),
444            );
445        };
446        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
447            headers.insert(
448                "DD-APPLICATION-KEY",
449                HeaderValue::from_str(local_key.key.as_str())
450                    .expect("failed to parse DD-APPLICATION-KEY header"),
451            );
452        };
453
454        // build body parameters
455        let output = Vec::new();
456        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
457        if body.serialize(&mut ser).is_ok() {
458            if let Some(content_encoding) = headers.get("Content-Encoding") {
459                match content_encoding.to_str().unwrap_or_default() {
460                    "gzip" => {
461                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
462                        let _ = enc.write_all(ser.into_inner().as_slice());
463                        match enc.finish() {
464                            Ok(buf) => {
465                                local_req_builder = local_req_builder.body(buf);
466                            }
467                            Err(e) => return Err(datadog::Error::Io(e)),
468                        }
469                    }
470                    "deflate" => {
471                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
472                        let _ = enc.write_all(ser.into_inner().as_slice());
473                        match enc.finish() {
474                            Ok(buf) => {
475                                local_req_builder = local_req_builder.body(buf);
476                            }
477                            Err(e) => return Err(datadog::Error::Io(e)),
478                        }
479                    }
480                    "zstd1" => {
481                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
482                        let _ = enc.write_all(ser.into_inner().as_slice());
483                        match enc.finish() {
484                            Ok(buf) => {
485                                local_req_builder = local_req_builder.body(buf);
486                            }
487                            Err(e) => return Err(datadog::Error::Io(e)),
488                        }
489                    }
490                    _ => {
491                        local_req_builder = local_req_builder.body(ser.into_inner());
492                    }
493                }
494            } else {
495                local_req_builder = local_req_builder.body(ser.into_inner());
496            }
497        }
498
499        local_req_builder = local_req_builder.headers(headers);
500        let local_req = local_req_builder.build()?;
501        log::debug!("request content: {:?}", local_req.body());
502        let local_resp = local_client.execute(local_req).await?;
503
504        let local_status = local_resp.status();
505        let local_content = local_resp.text().await?;
506        log::debug!("response content: {}", local_content);
507
508        if !local_status.is_client_error() && !local_status.is_server_error() {
509            match serde_json::from_str::<crate::datadogV2::model::PutAppsDatastoreItemResponseArray>(
510                &local_content,
511            ) {
512                Ok(e) => {
513                    return Ok(datadog::ResponseContent {
514                        status: local_status,
515                        content: local_content,
516                        entity: Some(e),
517                    })
518                }
519                Err(e) => return Err(datadog::Error::Serde(e)),
520            };
521        } else {
522            let local_entity: Option<BulkWriteDatastoreItemsError> =
523                serde_json::from_str(&local_content).ok();
524            let local_error = datadog::ResponseContent {
525                status: local_status,
526                content: local_content,
527                entity: local_entity,
528            };
529            Err(datadog::Error::ResponseError(local_error))
530        }
531    }
532
533    /// Creates a new datastore.
534    pub async fn create_datastore(
535        &self,
536        body: crate::datadogV2::model::CreateAppsDatastoreRequest,
537    ) -> Result<
538        crate::datadogV2::model::CreateAppsDatastoreResponse,
539        datadog::Error<CreateDatastoreError>,
540    > {
541        match self.create_datastore_with_http_info(body).await {
542            Ok(response_content) => {
543                if let Some(e) = response_content.entity {
544                    Ok(e)
545                } else {
546                    Err(datadog::Error::Serde(serde::de::Error::custom(
547                        "response content was None",
548                    )))
549                }
550            }
551            Err(err) => Err(err),
552        }
553    }
554
555    /// Creates a new datastore.
556    pub async fn create_datastore_with_http_info(
557        &self,
558        body: crate::datadogV2::model::CreateAppsDatastoreRequest,
559    ) -> Result<
560        datadog::ResponseContent<crate::datadogV2::model::CreateAppsDatastoreResponse>,
561        datadog::Error<CreateDatastoreError>,
562    > {
563        let local_configuration = &self.config;
564        let operation_id = "v2.create_datastore";
565
566        let local_client = &self.client;
567
568        let local_uri_str = format!(
569            "{}/api/v2/actions-datastores",
570            local_configuration.get_operation_host(operation_id)
571        );
572        let mut local_req_builder =
573            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
574
575        // build headers
576        let mut headers = HeaderMap::new();
577        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
578        headers.insert("Accept", HeaderValue::from_static("application/json"));
579
580        // build user agent
581        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
582            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
583            Err(e) => {
584                log::warn!("Failed to parse user agent header: {e}, falling back to default");
585                headers.insert(
586                    reqwest::header::USER_AGENT,
587                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
588                )
589            }
590        };
591
592        // build auth
593        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
594            headers.insert(
595                "DD-API-KEY",
596                HeaderValue::from_str(local_key.key.as_str())
597                    .expect("failed to parse DD-API-KEY header"),
598            );
599        };
600        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
601            headers.insert(
602                "DD-APPLICATION-KEY",
603                HeaderValue::from_str(local_key.key.as_str())
604                    .expect("failed to parse DD-APPLICATION-KEY header"),
605            );
606        };
607
608        // build body parameters
609        let output = Vec::new();
610        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
611        if body.serialize(&mut ser).is_ok() {
612            if let Some(content_encoding) = headers.get("Content-Encoding") {
613                match content_encoding.to_str().unwrap_or_default() {
614                    "gzip" => {
615                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
616                        let _ = enc.write_all(ser.into_inner().as_slice());
617                        match enc.finish() {
618                            Ok(buf) => {
619                                local_req_builder = local_req_builder.body(buf);
620                            }
621                            Err(e) => return Err(datadog::Error::Io(e)),
622                        }
623                    }
624                    "deflate" => {
625                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
626                        let _ = enc.write_all(ser.into_inner().as_slice());
627                        match enc.finish() {
628                            Ok(buf) => {
629                                local_req_builder = local_req_builder.body(buf);
630                            }
631                            Err(e) => return Err(datadog::Error::Io(e)),
632                        }
633                    }
634                    "zstd1" => {
635                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
636                        let _ = enc.write_all(ser.into_inner().as_slice());
637                        match enc.finish() {
638                            Ok(buf) => {
639                                local_req_builder = local_req_builder.body(buf);
640                            }
641                            Err(e) => return Err(datadog::Error::Io(e)),
642                        }
643                    }
644                    _ => {
645                        local_req_builder = local_req_builder.body(ser.into_inner());
646                    }
647                }
648            } else {
649                local_req_builder = local_req_builder.body(ser.into_inner());
650            }
651        }
652
653        local_req_builder = local_req_builder.headers(headers);
654        let local_req = local_req_builder.build()?;
655        log::debug!("request content: {:?}", local_req.body());
656        let local_resp = local_client.execute(local_req).await?;
657
658        let local_status = local_resp.status();
659        let local_content = local_resp.text().await?;
660        log::debug!("response content: {}", local_content);
661
662        if !local_status.is_client_error() && !local_status.is_server_error() {
663            match serde_json::from_str::<crate::datadogV2::model::CreateAppsDatastoreResponse>(
664                &local_content,
665            ) {
666                Ok(e) => {
667                    return Ok(datadog::ResponseContent {
668                        status: local_status,
669                        content: local_content,
670                        entity: Some(e),
671                    })
672                }
673                Err(e) => return Err(datadog::Error::Serde(e)),
674            };
675        } else {
676            let local_entity: Option<CreateDatastoreError> =
677                serde_json::from_str(&local_content).ok();
678            let local_error = datadog::ResponseContent {
679                status: local_status,
680                content: local_content,
681                entity: local_entity,
682            };
683            Err(datadog::Error::ResponseError(local_error))
684        }
685    }
686
687    /// Deletes a datastore by its unique identifier.
688    pub async fn delete_datastore(
689        &self,
690        datastore_id: String,
691    ) -> Result<(), datadog::Error<DeleteDatastoreError>> {
692        match self.delete_datastore_with_http_info(datastore_id).await {
693            Ok(_) => Ok(()),
694            Err(err) => Err(err),
695        }
696    }
697
698    /// Deletes a datastore by its unique identifier.
699    pub async fn delete_datastore_with_http_info(
700        &self,
701        datastore_id: String,
702    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteDatastoreError>> {
703        let local_configuration = &self.config;
704        let operation_id = "v2.delete_datastore";
705
706        let local_client = &self.client;
707
708        let local_uri_str = format!(
709            "{}/api/v2/actions-datastores/{datastore_id}",
710            local_configuration.get_operation_host(operation_id),
711            datastore_id = datadog::urlencode(datastore_id)
712        );
713        let mut local_req_builder =
714            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
715
716        // build headers
717        let mut headers = HeaderMap::new();
718        headers.insert("Accept", HeaderValue::from_static("*/*"));
719
720        // build user agent
721        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
722            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
723            Err(e) => {
724                log::warn!("Failed to parse user agent header: {e}, falling back to default");
725                headers.insert(
726                    reqwest::header::USER_AGENT,
727                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
728                )
729            }
730        };
731
732        // build auth
733        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
734            headers.insert(
735                "DD-API-KEY",
736                HeaderValue::from_str(local_key.key.as_str())
737                    .expect("failed to parse DD-API-KEY header"),
738            );
739        };
740        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
741            headers.insert(
742                "DD-APPLICATION-KEY",
743                HeaderValue::from_str(local_key.key.as_str())
744                    .expect("failed to parse DD-APPLICATION-KEY header"),
745            );
746        };
747
748        local_req_builder = local_req_builder.headers(headers);
749        let local_req = local_req_builder.build()?;
750        log::debug!("request content: {:?}", local_req.body());
751        let local_resp = local_client.execute(local_req).await?;
752
753        let local_status = local_resp.status();
754        let local_content = local_resp.text().await?;
755        log::debug!("response content: {}", local_content);
756
757        if !local_status.is_client_error() && !local_status.is_server_error() {
758            Ok(datadog::ResponseContent {
759                status: local_status,
760                content: local_content,
761                entity: None,
762            })
763        } else {
764            let local_entity: Option<DeleteDatastoreError> =
765                serde_json::from_str(&local_content).ok();
766            let local_error = datadog::ResponseContent {
767                status: local_status,
768                content: local_content,
769                entity: local_entity,
770            };
771            Err(datadog::Error::ResponseError(local_error))
772        }
773    }
774
775    /// Deletes an item from a datastore by its key.
776    pub async fn delete_datastore_item(
777        &self,
778        datastore_id: String,
779        body: crate::datadogV2::model::DeleteAppsDatastoreItemRequest,
780    ) -> Result<
781        crate::datadogV2::model::DeleteAppsDatastoreItemResponse,
782        datadog::Error<DeleteDatastoreItemError>,
783    > {
784        match self
785            .delete_datastore_item_with_http_info(datastore_id, body)
786            .await
787        {
788            Ok(response_content) => {
789                if let Some(e) = response_content.entity {
790                    Ok(e)
791                } else {
792                    Err(datadog::Error::Serde(serde::de::Error::custom(
793                        "response content was None",
794                    )))
795                }
796            }
797            Err(err) => Err(err),
798        }
799    }
800
801    /// Deletes an item from a datastore by its key.
802    pub async fn delete_datastore_item_with_http_info(
803        &self,
804        datastore_id: String,
805        body: crate::datadogV2::model::DeleteAppsDatastoreItemRequest,
806    ) -> Result<
807        datadog::ResponseContent<crate::datadogV2::model::DeleteAppsDatastoreItemResponse>,
808        datadog::Error<DeleteDatastoreItemError>,
809    > {
810        let local_configuration = &self.config;
811        let operation_id = "v2.delete_datastore_item";
812
813        let local_client = &self.client;
814
815        let local_uri_str = format!(
816            "{}/api/v2/actions-datastores/{datastore_id}/items",
817            local_configuration.get_operation_host(operation_id),
818            datastore_id = datadog::urlencode(datastore_id)
819        );
820        let mut local_req_builder =
821            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
822
823        // build headers
824        let mut headers = HeaderMap::new();
825        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
826        headers.insert("Accept", HeaderValue::from_static("application/json"));
827
828        // build user agent
829        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
830            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
831            Err(e) => {
832                log::warn!("Failed to parse user agent header: {e}, falling back to default");
833                headers.insert(
834                    reqwest::header::USER_AGENT,
835                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
836                )
837            }
838        };
839
840        // build auth
841        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
842            headers.insert(
843                "DD-API-KEY",
844                HeaderValue::from_str(local_key.key.as_str())
845                    .expect("failed to parse DD-API-KEY header"),
846            );
847        };
848        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
849            headers.insert(
850                "DD-APPLICATION-KEY",
851                HeaderValue::from_str(local_key.key.as_str())
852                    .expect("failed to parse DD-APPLICATION-KEY header"),
853            );
854        };
855
856        // build body parameters
857        let output = Vec::new();
858        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
859        if body.serialize(&mut ser).is_ok() {
860            if let Some(content_encoding) = headers.get("Content-Encoding") {
861                match content_encoding.to_str().unwrap_or_default() {
862                    "gzip" => {
863                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
864                        let _ = enc.write_all(ser.into_inner().as_slice());
865                        match enc.finish() {
866                            Ok(buf) => {
867                                local_req_builder = local_req_builder.body(buf);
868                            }
869                            Err(e) => return Err(datadog::Error::Io(e)),
870                        }
871                    }
872                    "deflate" => {
873                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
874                        let _ = enc.write_all(ser.into_inner().as_slice());
875                        match enc.finish() {
876                            Ok(buf) => {
877                                local_req_builder = local_req_builder.body(buf);
878                            }
879                            Err(e) => return Err(datadog::Error::Io(e)),
880                        }
881                    }
882                    "zstd1" => {
883                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
884                        let _ = enc.write_all(ser.into_inner().as_slice());
885                        match enc.finish() {
886                            Ok(buf) => {
887                                local_req_builder = local_req_builder.body(buf);
888                            }
889                            Err(e) => return Err(datadog::Error::Io(e)),
890                        }
891                    }
892                    _ => {
893                        local_req_builder = local_req_builder.body(ser.into_inner());
894                    }
895                }
896            } else {
897                local_req_builder = local_req_builder.body(ser.into_inner());
898            }
899        }
900
901        local_req_builder = local_req_builder.headers(headers);
902        let local_req = local_req_builder.build()?;
903        log::debug!("request content: {:?}", local_req.body());
904        let local_resp = local_client.execute(local_req).await?;
905
906        let local_status = local_resp.status();
907        let local_content = local_resp.text().await?;
908        log::debug!("response content: {}", local_content);
909
910        if !local_status.is_client_error() && !local_status.is_server_error() {
911            match serde_json::from_str::<crate::datadogV2::model::DeleteAppsDatastoreItemResponse>(
912                &local_content,
913            ) {
914                Ok(e) => {
915                    return Ok(datadog::ResponseContent {
916                        status: local_status,
917                        content: local_content,
918                        entity: Some(e),
919                    })
920                }
921                Err(e) => return Err(datadog::Error::Serde(e)),
922            };
923        } else {
924            let local_entity: Option<DeleteDatastoreItemError> =
925                serde_json::from_str(&local_content).ok();
926            let local_error = datadog::ResponseContent {
927                status: local_status,
928                content: local_content,
929                entity: local_entity,
930            };
931            Err(datadog::Error::ResponseError(local_error))
932        }
933    }
934
935    /// Retrieves a specific datastore by its ID.
936    pub async fn get_datastore(
937        &self,
938        datastore_id: String,
939    ) -> Result<crate::datadogV2::model::Datastore, datadog::Error<GetDatastoreError>> {
940        match self.get_datastore_with_http_info(datastore_id).await {
941            Ok(response_content) => {
942                if let Some(e) = response_content.entity {
943                    Ok(e)
944                } else {
945                    Err(datadog::Error::Serde(serde::de::Error::custom(
946                        "response content was None",
947                    )))
948                }
949            }
950            Err(err) => Err(err),
951        }
952    }
953
954    /// Retrieves a specific datastore by its ID.
955    pub async fn get_datastore_with_http_info(
956        &self,
957        datastore_id: String,
958    ) -> Result<
959        datadog::ResponseContent<crate::datadogV2::model::Datastore>,
960        datadog::Error<GetDatastoreError>,
961    > {
962        let local_configuration = &self.config;
963        let operation_id = "v2.get_datastore";
964
965        let local_client = &self.client;
966
967        let local_uri_str = format!(
968            "{}/api/v2/actions-datastores/{datastore_id}",
969            local_configuration.get_operation_host(operation_id),
970            datastore_id = datadog::urlencode(datastore_id)
971        );
972        let mut local_req_builder =
973            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
974
975        // build headers
976        let mut headers = HeaderMap::new();
977        headers.insert("Accept", HeaderValue::from_static("application/json"));
978
979        // build user agent
980        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
981            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
982            Err(e) => {
983                log::warn!("Failed to parse user agent header: {e}, falling back to default");
984                headers.insert(
985                    reqwest::header::USER_AGENT,
986                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
987                )
988            }
989        };
990
991        // build auth
992        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
993            headers.insert(
994                "DD-API-KEY",
995                HeaderValue::from_str(local_key.key.as_str())
996                    .expect("failed to parse DD-API-KEY header"),
997            );
998        };
999        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1000            headers.insert(
1001                "DD-APPLICATION-KEY",
1002                HeaderValue::from_str(local_key.key.as_str())
1003                    .expect("failed to parse DD-APPLICATION-KEY header"),
1004            );
1005        };
1006
1007        local_req_builder = local_req_builder.headers(headers);
1008        let local_req = local_req_builder.build()?;
1009        log::debug!("request content: {:?}", local_req.body());
1010        let local_resp = local_client.execute(local_req).await?;
1011
1012        let local_status = local_resp.status();
1013        let local_content = local_resp.text().await?;
1014        log::debug!("response content: {}", local_content);
1015
1016        if !local_status.is_client_error() && !local_status.is_server_error() {
1017            match serde_json::from_str::<crate::datadogV2::model::Datastore>(&local_content) {
1018                Ok(e) => {
1019                    return Ok(datadog::ResponseContent {
1020                        status: local_status,
1021                        content: local_content,
1022                        entity: Some(e),
1023                    })
1024                }
1025                Err(e) => return Err(datadog::Error::Serde(e)),
1026            };
1027        } else {
1028            let local_entity: Option<GetDatastoreError> = serde_json::from_str(&local_content).ok();
1029            let local_error = datadog::ResponseContent {
1030                status: local_status,
1031                content: local_content,
1032                entity: local_entity,
1033            };
1034            Err(datadog::Error::ResponseError(local_error))
1035        }
1036    }
1037
1038    /// Lists items from a datastore. You can filter the results by specifying either an item key or a filter query parameter, but not both at the same time. Supports server-side pagination for large datasets.
1039    pub async fn list_datastore_items(
1040        &self,
1041        datastore_id: String,
1042        params: ListDatastoreItemsOptionalParams,
1043    ) -> Result<crate::datadogV2::model::ItemApiPayloadArray, datadog::Error<ListDatastoreItemsError>>
1044    {
1045        match self
1046            .list_datastore_items_with_http_info(datastore_id, params)
1047            .await
1048        {
1049            Ok(response_content) => {
1050                if let Some(e) = response_content.entity {
1051                    Ok(e)
1052                } else {
1053                    Err(datadog::Error::Serde(serde::de::Error::custom(
1054                        "response content was None",
1055                    )))
1056                }
1057            }
1058            Err(err) => Err(err),
1059        }
1060    }
1061
1062    /// Lists items from a datastore. You can filter the results by specifying either an item key or a filter query parameter, but not both at the same time. Supports server-side pagination for large datasets.
1063    pub async fn list_datastore_items_with_http_info(
1064        &self,
1065        datastore_id: String,
1066        params: ListDatastoreItemsOptionalParams,
1067    ) -> Result<
1068        datadog::ResponseContent<crate::datadogV2::model::ItemApiPayloadArray>,
1069        datadog::Error<ListDatastoreItemsError>,
1070    > {
1071        let local_configuration = &self.config;
1072        let operation_id = "v2.list_datastore_items";
1073
1074        // unbox and build optional parameters
1075        let filter = params.filter;
1076        let item_key = params.item_key;
1077        let page_limit = params.page_limit;
1078        let page_offset = params.page_offset;
1079        let sort = params.sort;
1080
1081        let local_client = &self.client;
1082
1083        let local_uri_str = format!(
1084            "{}/api/v2/actions-datastores/{datastore_id}/items",
1085            local_configuration.get_operation_host(operation_id),
1086            datastore_id = datadog::urlencode(datastore_id)
1087        );
1088        let mut local_req_builder =
1089            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1090
1091        if let Some(ref local_query_param) = filter {
1092            local_req_builder =
1093                local_req_builder.query(&[("filter", &local_query_param.to_string())]);
1094        };
1095        if let Some(ref local_query_param) = item_key {
1096            local_req_builder =
1097                local_req_builder.query(&[("item_key", &local_query_param.to_string())]);
1098        };
1099        if let Some(ref local_query_param) = page_limit {
1100            local_req_builder =
1101                local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
1102        };
1103        if let Some(ref local_query_param) = page_offset {
1104            local_req_builder =
1105                local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
1106        };
1107        if let Some(ref local_query_param) = sort {
1108            local_req_builder =
1109                local_req_builder.query(&[("sort", &local_query_param.to_string())]);
1110        };
1111
1112        // build headers
1113        let mut headers = HeaderMap::new();
1114        headers.insert("Accept", HeaderValue::from_static("application/json"));
1115
1116        // build user agent
1117        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1118            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1119            Err(e) => {
1120                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1121                headers.insert(
1122                    reqwest::header::USER_AGENT,
1123                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1124                )
1125            }
1126        };
1127
1128        // build auth
1129        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1130            headers.insert(
1131                "DD-API-KEY",
1132                HeaderValue::from_str(local_key.key.as_str())
1133                    .expect("failed to parse DD-API-KEY header"),
1134            );
1135        };
1136        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1137            headers.insert(
1138                "DD-APPLICATION-KEY",
1139                HeaderValue::from_str(local_key.key.as_str())
1140                    .expect("failed to parse DD-APPLICATION-KEY header"),
1141            );
1142        };
1143
1144        local_req_builder = local_req_builder.headers(headers);
1145        let local_req = local_req_builder.build()?;
1146        log::debug!("request content: {:?}", local_req.body());
1147        let local_resp = local_client.execute(local_req).await?;
1148
1149        let local_status = local_resp.status();
1150        let local_content = local_resp.text().await?;
1151        log::debug!("response content: {}", local_content);
1152
1153        if !local_status.is_client_error() && !local_status.is_server_error() {
1154            match serde_json::from_str::<crate::datadogV2::model::ItemApiPayloadArray>(
1155                &local_content,
1156            ) {
1157                Ok(e) => {
1158                    return Ok(datadog::ResponseContent {
1159                        status: local_status,
1160                        content: local_content,
1161                        entity: Some(e),
1162                    })
1163                }
1164                Err(e) => return Err(datadog::Error::Serde(e)),
1165            };
1166        } else {
1167            let local_entity: Option<ListDatastoreItemsError> =
1168                serde_json::from_str(&local_content).ok();
1169            let local_error = datadog::ResponseContent {
1170                status: local_status,
1171                content: local_content,
1172                entity: local_entity,
1173            };
1174            Err(datadog::Error::ResponseError(local_error))
1175        }
1176    }
1177
1178    /// Lists all datastores for the organization.
1179    pub async fn list_datastores(
1180        &self,
1181    ) -> Result<crate::datadogV2::model::DatastoreArray, datadog::Error<ListDatastoresError>> {
1182        match self.list_datastores_with_http_info().await {
1183            Ok(response_content) => {
1184                if let Some(e) = response_content.entity {
1185                    Ok(e)
1186                } else {
1187                    Err(datadog::Error::Serde(serde::de::Error::custom(
1188                        "response content was None",
1189                    )))
1190                }
1191            }
1192            Err(err) => Err(err),
1193        }
1194    }
1195
1196    /// Lists all datastores for the organization.
1197    pub async fn list_datastores_with_http_info(
1198        &self,
1199    ) -> Result<
1200        datadog::ResponseContent<crate::datadogV2::model::DatastoreArray>,
1201        datadog::Error<ListDatastoresError>,
1202    > {
1203        let local_configuration = &self.config;
1204        let operation_id = "v2.list_datastores";
1205
1206        let local_client = &self.client;
1207
1208        let local_uri_str = format!(
1209            "{}/api/v2/actions-datastores",
1210            local_configuration.get_operation_host(operation_id)
1211        );
1212        let mut local_req_builder =
1213            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1214
1215        // build headers
1216        let mut headers = HeaderMap::new();
1217        headers.insert("Accept", HeaderValue::from_static("application/json"));
1218
1219        // build user agent
1220        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1221            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1222            Err(e) => {
1223                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1224                headers.insert(
1225                    reqwest::header::USER_AGENT,
1226                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1227                )
1228            }
1229        };
1230
1231        // build auth
1232        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1233            headers.insert(
1234                "DD-API-KEY",
1235                HeaderValue::from_str(local_key.key.as_str())
1236                    .expect("failed to parse DD-API-KEY header"),
1237            );
1238        };
1239        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1240            headers.insert(
1241                "DD-APPLICATION-KEY",
1242                HeaderValue::from_str(local_key.key.as_str())
1243                    .expect("failed to parse DD-APPLICATION-KEY header"),
1244            );
1245        };
1246
1247        local_req_builder = local_req_builder.headers(headers);
1248        let local_req = local_req_builder.build()?;
1249        log::debug!("request content: {:?}", local_req.body());
1250        let local_resp = local_client.execute(local_req).await?;
1251
1252        let local_status = local_resp.status();
1253        let local_content = local_resp.text().await?;
1254        log::debug!("response content: {}", local_content);
1255
1256        if !local_status.is_client_error() && !local_status.is_server_error() {
1257            match serde_json::from_str::<crate::datadogV2::model::DatastoreArray>(&local_content) {
1258                Ok(e) => {
1259                    return Ok(datadog::ResponseContent {
1260                        status: local_status,
1261                        content: local_content,
1262                        entity: Some(e),
1263                    })
1264                }
1265                Err(e) => return Err(datadog::Error::Serde(e)),
1266            };
1267        } else {
1268            let local_entity: Option<ListDatastoresError> =
1269                serde_json::from_str(&local_content).ok();
1270            let local_error = datadog::ResponseContent {
1271                status: local_status,
1272                content: local_content,
1273                entity: local_entity,
1274            };
1275            Err(datadog::Error::ResponseError(local_error))
1276        }
1277    }
1278
1279    /// Updates an existing datastore's attributes.
1280    pub async fn update_datastore(
1281        &self,
1282        datastore_id: String,
1283        body: crate::datadogV2::model::UpdateAppsDatastoreRequest,
1284    ) -> Result<crate::datadogV2::model::Datastore, datadog::Error<UpdateDatastoreError>> {
1285        match self
1286            .update_datastore_with_http_info(datastore_id, body)
1287            .await
1288        {
1289            Ok(response_content) => {
1290                if let Some(e) = response_content.entity {
1291                    Ok(e)
1292                } else {
1293                    Err(datadog::Error::Serde(serde::de::Error::custom(
1294                        "response content was None",
1295                    )))
1296                }
1297            }
1298            Err(err) => Err(err),
1299        }
1300    }
1301
1302    /// Updates an existing datastore's attributes.
1303    pub async fn update_datastore_with_http_info(
1304        &self,
1305        datastore_id: String,
1306        body: crate::datadogV2::model::UpdateAppsDatastoreRequest,
1307    ) -> Result<
1308        datadog::ResponseContent<crate::datadogV2::model::Datastore>,
1309        datadog::Error<UpdateDatastoreError>,
1310    > {
1311        let local_configuration = &self.config;
1312        let operation_id = "v2.update_datastore";
1313
1314        let local_client = &self.client;
1315
1316        let local_uri_str = format!(
1317            "{}/api/v2/actions-datastores/{datastore_id}",
1318            local_configuration.get_operation_host(operation_id),
1319            datastore_id = datadog::urlencode(datastore_id)
1320        );
1321        let mut local_req_builder =
1322            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1323
1324        // build headers
1325        let mut headers = HeaderMap::new();
1326        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1327        headers.insert("Accept", HeaderValue::from_static("application/json"));
1328
1329        // build user agent
1330        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1331            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1332            Err(e) => {
1333                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1334                headers.insert(
1335                    reqwest::header::USER_AGENT,
1336                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1337                )
1338            }
1339        };
1340
1341        // build auth
1342        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1343            headers.insert(
1344                "DD-API-KEY",
1345                HeaderValue::from_str(local_key.key.as_str())
1346                    .expect("failed to parse DD-API-KEY header"),
1347            );
1348        };
1349        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1350            headers.insert(
1351                "DD-APPLICATION-KEY",
1352                HeaderValue::from_str(local_key.key.as_str())
1353                    .expect("failed to parse DD-APPLICATION-KEY header"),
1354            );
1355        };
1356
1357        // build body parameters
1358        let output = Vec::new();
1359        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1360        if body.serialize(&mut ser).is_ok() {
1361            if let Some(content_encoding) = headers.get("Content-Encoding") {
1362                match content_encoding.to_str().unwrap_or_default() {
1363                    "gzip" => {
1364                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1365                        let _ = enc.write_all(ser.into_inner().as_slice());
1366                        match enc.finish() {
1367                            Ok(buf) => {
1368                                local_req_builder = local_req_builder.body(buf);
1369                            }
1370                            Err(e) => return Err(datadog::Error::Io(e)),
1371                        }
1372                    }
1373                    "deflate" => {
1374                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1375                        let _ = enc.write_all(ser.into_inner().as_slice());
1376                        match enc.finish() {
1377                            Ok(buf) => {
1378                                local_req_builder = local_req_builder.body(buf);
1379                            }
1380                            Err(e) => return Err(datadog::Error::Io(e)),
1381                        }
1382                    }
1383                    "zstd1" => {
1384                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1385                        let _ = enc.write_all(ser.into_inner().as_slice());
1386                        match enc.finish() {
1387                            Ok(buf) => {
1388                                local_req_builder = local_req_builder.body(buf);
1389                            }
1390                            Err(e) => return Err(datadog::Error::Io(e)),
1391                        }
1392                    }
1393                    _ => {
1394                        local_req_builder = local_req_builder.body(ser.into_inner());
1395                    }
1396                }
1397            } else {
1398                local_req_builder = local_req_builder.body(ser.into_inner());
1399            }
1400        }
1401
1402        local_req_builder = local_req_builder.headers(headers);
1403        let local_req = local_req_builder.build()?;
1404        log::debug!("request content: {:?}", local_req.body());
1405        let local_resp = local_client.execute(local_req).await?;
1406
1407        let local_status = local_resp.status();
1408        let local_content = local_resp.text().await?;
1409        log::debug!("response content: {}", local_content);
1410
1411        if !local_status.is_client_error() && !local_status.is_server_error() {
1412            match serde_json::from_str::<crate::datadogV2::model::Datastore>(&local_content) {
1413                Ok(e) => {
1414                    return Ok(datadog::ResponseContent {
1415                        status: local_status,
1416                        content: local_content,
1417                        entity: Some(e),
1418                    })
1419                }
1420                Err(e) => return Err(datadog::Error::Serde(e)),
1421            };
1422        } else {
1423            let local_entity: Option<UpdateDatastoreError> =
1424                serde_json::from_str(&local_content).ok();
1425            let local_error = datadog::ResponseContent {
1426                status: local_status,
1427                content: local_content,
1428                entity: local_entity,
1429            };
1430            Err(datadog::Error::ResponseError(local_error))
1431        }
1432    }
1433
1434    /// Partially updates an item in a datastore by its key.
1435    pub async fn update_datastore_item(
1436        &self,
1437        datastore_id: String,
1438        body: crate::datadogV2::model::UpdateAppsDatastoreItemRequest,
1439    ) -> Result<crate::datadogV2::model::ItemApiPayload, datadog::Error<UpdateDatastoreItemError>>
1440    {
1441        match self
1442            .update_datastore_item_with_http_info(datastore_id, body)
1443            .await
1444        {
1445            Ok(response_content) => {
1446                if let Some(e) = response_content.entity {
1447                    Ok(e)
1448                } else {
1449                    Err(datadog::Error::Serde(serde::de::Error::custom(
1450                        "response content was None",
1451                    )))
1452                }
1453            }
1454            Err(err) => Err(err),
1455        }
1456    }
1457
1458    /// Partially updates an item in a datastore by its key.
1459    pub async fn update_datastore_item_with_http_info(
1460        &self,
1461        datastore_id: String,
1462        body: crate::datadogV2::model::UpdateAppsDatastoreItemRequest,
1463    ) -> Result<
1464        datadog::ResponseContent<crate::datadogV2::model::ItemApiPayload>,
1465        datadog::Error<UpdateDatastoreItemError>,
1466    > {
1467        let local_configuration = &self.config;
1468        let operation_id = "v2.update_datastore_item";
1469
1470        let local_client = &self.client;
1471
1472        let local_uri_str = format!(
1473            "{}/api/v2/actions-datastores/{datastore_id}/items",
1474            local_configuration.get_operation_host(operation_id),
1475            datastore_id = datadog::urlencode(datastore_id)
1476        );
1477        let mut local_req_builder =
1478            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1479
1480        // build headers
1481        let mut headers = HeaderMap::new();
1482        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1483        headers.insert("Accept", HeaderValue::from_static("application/json"));
1484
1485        // build user agent
1486        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1487            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1488            Err(e) => {
1489                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1490                headers.insert(
1491                    reqwest::header::USER_AGENT,
1492                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1493                )
1494            }
1495        };
1496
1497        // build auth
1498        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1499            headers.insert(
1500                "DD-API-KEY",
1501                HeaderValue::from_str(local_key.key.as_str())
1502                    .expect("failed to parse DD-API-KEY header"),
1503            );
1504        };
1505        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1506            headers.insert(
1507                "DD-APPLICATION-KEY",
1508                HeaderValue::from_str(local_key.key.as_str())
1509                    .expect("failed to parse DD-APPLICATION-KEY header"),
1510            );
1511        };
1512
1513        // build body parameters
1514        let output = Vec::new();
1515        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1516        if body.serialize(&mut ser).is_ok() {
1517            if let Some(content_encoding) = headers.get("Content-Encoding") {
1518                match content_encoding.to_str().unwrap_or_default() {
1519                    "gzip" => {
1520                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1521                        let _ = enc.write_all(ser.into_inner().as_slice());
1522                        match enc.finish() {
1523                            Ok(buf) => {
1524                                local_req_builder = local_req_builder.body(buf);
1525                            }
1526                            Err(e) => return Err(datadog::Error::Io(e)),
1527                        }
1528                    }
1529                    "deflate" => {
1530                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1531                        let _ = enc.write_all(ser.into_inner().as_slice());
1532                        match enc.finish() {
1533                            Ok(buf) => {
1534                                local_req_builder = local_req_builder.body(buf);
1535                            }
1536                            Err(e) => return Err(datadog::Error::Io(e)),
1537                        }
1538                    }
1539                    "zstd1" => {
1540                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1541                        let _ = enc.write_all(ser.into_inner().as_slice());
1542                        match enc.finish() {
1543                            Ok(buf) => {
1544                                local_req_builder = local_req_builder.body(buf);
1545                            }
1546                            Err(e) => return Err(datadog::Error::Io(e)),
1547                        }
1548                    }
1549                    _ => {
1550                        local_req_builder = local_req_builder.body(ser.into_inner());
1551                    }
1552                }
1553            } else {
1554                local_req_builder = local_req_builder.body(ser.into_inner());
1555            }
1556        }
1557
1558        local_req_builder = local_req_builder.headers(headers);
1559        let local_req = local_req_builder.build()?;
1560        log::debug!("request content: {:?}", local_req.body());
1561        let local_resp = local_client.execute(local_req).await?;
1562
1563        let local_status = local_resp.status();
1564        let local_content = local_resp.text().await?;
1565        log::debug!("response content: {}", local_content);
1566
1567        if !local_status.is_client_error() && !local_status.is_server_error() {
1568            match serde_json::from_str::<crate::datadogV2::model::ItemApiPayload>(&local_content) {
1569                Ok(e) => {
1570                    return Ok(datadog::ResponseContent {
1571                        status: local_status,
1572                        content: local_content,
1573                        entity: Some(e),
1574                    })
1575                }
1576                Err(e) => return Err(datadog::Error::Serde(e)),
1577            };
1578        } else {
1579            let local_entity: Option<UpdateDatastoreItemError> =
1580                serde_json::from_str(&local_content).ok();
1581            let local_error = datadog::ResponseContent {
1582                status: local_status,
1583                content: local_content,
1584                entity: local_entity,
1585            };
1586            Err(datadog::Error::ResponseError(local_error))
1587        }
1588    }
1589}