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