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 AddReadRoleToArchiveError {
17 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
18 UnknownValue(serde_json::Value),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CreateLogsArchiveError {
25 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteLogsArchiveError {
33 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum GetLogsArchiveError {
41 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetLogsArchiveOrderError {
49 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ListArchiveReadRolesError {
57 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListLogsArchivesError {
65 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum RemoveRoleFromArchiveError {
73 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum UpdateLogsArchiveError {
81 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum UpdateLogsArchiveOrderError {
89 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone)]
98pub struct LogsArchivesAPI {
99 config: datadog::Configuration,
100 client: reqwest_middleware::ClientWithMiddleware,
101}
102
103impl Default for LogsArchivesAPI {
104 fn default() -> Self {
105 Self::with_config(datadog::Configuration::default())
106 }
107}
108
109impl LogsArchivesAPI {
110 pub fn new() -> Self {
111 Self::default()
112 }
113 pub fn with_config(config: datadog::Configuration) -> Self {
114 let mut reqwest_client_builder = reqwest::Client::builder();
115
116 if let Some(proxy_url) = &config.proxy_url {
117 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
118 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
119 }
120
121 let mut middleware_client_builder =
122 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
123
124 if config.enable_retry {
125 struct RetryableStatus;
126 impl reqwest_retry::RetryableStrategy for RetryableStatus {
127 fn handle(
128 &self,
129 res: &Result<reqwest::Response, reqwest_middleware::Error>,
130 ) -> Option<reqwest_retry::Retryable> {
131 match res {
132 Ok(success) => reqwest_retry::default_on_request_success(success),
133 Err(_) => None,
134 }
135 }
136 }
137 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
138 .build_with_max_retries(config.max_retries);
139
140 let retry_middleware =
141 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
142 backoff_policy,
143 RetryableStatus,
144 );
145
146 middleware_client_builder = middleware_client_builder.with(retry_middleware);
147 }
148
149 let client = middleware_client_builder.build();
150
151 Self { config, client }
152 }
153
154 pub fn with_client_and_config(
155 config: datadog::Configuration,
156 client: reqwest_middleware::ClientWithMiddleware,
157 ) -> Self {
158 Self { config, client }
159 }
160
161 pub async fn add_read_role_to_archive(
163 &self,
164 archive_id: String,
165 body: crate::datadogV2::model::RelationshipToRole,
166 ) -> Result<(), datadog::Error<AddReadRoleToArchiveError>> {
167 match self
168 .add_read_role_to_archive_with_http_info(archive_id, body)
169 .await
170 {
171 Ok(_) => Ok(()),
172 Err(err) => Err(err),
173 }
174 }
175
176 pub async fn add_read_role_to_archive_with_http_info(
178 &self,
179 archive_id: String,
180 body: crate::datadogV2::model::RelationshipToRole,
181 ) -> Result<datadog::ResponseContent<()>, datadog::Error<AddReadRoleToArchiveError>> {
182 let local_configuration = &self.config;
183 let operation_id = "v2.add_read_role_to_archive";
184
185 let local_client = &self.client;
186
187 let local_uri_str = format!(
188 "{}/api/v2/logs/config/archives/{archive_id}/readers",
189 local_configuration.get_operation_host(operation_id),
190 archive_id = datadog::urlencode(archive_id)
191 );
192 let mut local_req_builder =
193 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
194
195 let mut headers = HeaderMap::new();
197 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
198 headers.insert("Accept", HeaderValue::from_static("*/*"));
199
200 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
202 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
203 Err(e) => {
204 log::warn!("Failed to parse user agent header: {e}, falling back to default");
205 headers.insert(
206 reqwest::header::USER_AGENT,
207 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
208 )
209 }
210 };
211
212 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
214 headers.insert(
215 "DD-API-KEY",
216 HeaderValue::from_str(local_key.key.as_str())
217 .expect("failed to parse DD-API-KEY header"),
218 );
219 };
220 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
221 headers.insert(
222 "DD-APPLICATION-KEY",
223 HeaderValue::from_str(local_key.key.as_str())
224 .expect("failed to parse DD-APPLICATION-KEY header"),
225 );
226 };
227
228 let output = Vec::new();
230 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
231 if body.serialize(&mut ser).is_ok() {
232 if let Some(content_encoding) = headers.get("Content-Encoding") {
233 match content_encoding.to_str().unwrap_or_default() {
234 "gzip" => {
235 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
236 let _ = enc.write_all(ser.into_inner().as_slice());
237 match enc.finish() {
238 Ok(buf) => {
239 local_req_builder = local_req_builder.body(buf);
240 }
241 Err(e) => return Err(datadog::Error::Io(e)),
242 }
243 }
244 "deflate" => {
245 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
246 let _ = enc.write_all(ser.into_inner().as_slice());
247 match enc.finish() {
248 Ok(buf) => {
249 local_req_builder = local_req_builder.body(buf);
250 }
251 Err(e) => return Err(datadog::Error::Io(e)),
252 }
253 }
254 "zstd1" => {
255 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
256 let _ = enc.write_all(ser.into_inner().as_slice());
257 match enc.finish() {
258 Ok(buf) => {
259 local_req_builder = local_req_builder.body(buf);
260 }
261 Err(e) => return Err(datadog::Error::Io(e)),
262 }
263 }
264 _ => {
265 local_req_builder = local_req_builder.body(ser.into_inner());
266 }
267 }
268 } else {
269 local_req_builder = local_req_builder.body(ser.into_inner());
270 }
271 }
272
273 local_req_builder = local_req_builder.headers(headers);
274 let local_req = local_req_builder.build()?;
275 log::debug!("request content: {:?}", local_req.body());
276 let local_resp = local_client.execute(local_req).await?;
277
278 let local_status = local_resp.status();
279 let local_content = local_resp.text().await?;
280 log::debug!("response content: {}", local_content);
281
282 if !local_status.is_client_error() && !local_status.is_server_error() {
283 Ok(datadog::ResponseContent {
284 status: local_status,
285 content: local_content,
286 entity: None,
287 })
288 } else {
289 let local_entity: Option<AddReadRoleToArchiveError> =
290 serde_json::from_str(&local_content).ok();
291 let local_error = datadog::ResponseContent {
292 status: local_status,
293 content: local_content,
294 entity: local_entity,
295 };
296 Err(datadog::Error::ResponseError(local_error))
297 }
298 }
299
300 pub async fn create_logs_archive(
302 &self,
303 body: crate::datadogV2::model::LogsArchiveCreateRequest,
304 ) -> Result<crate::datadogV2::model::LogsArchive, datadog::Error<CreateLogsArchiveError>> {
305 match self.create_logs_archive_with_http_info(body).await {
306 Ok(response_content) => {
307 if let Some(e) = response_content.entity {
308 Ok(e)
309 } else {
310 Err(datadog::Error::Serde(serde::de::Error::custom(
311 "response content was None",
312 )))
313 }
314 }
315 Err(err) => Err(err),
316 }
317 }
318
319 pub async fn create_logs_archive_with_http_info(
321 &self,
322 body: crate::datadogV2::model::LogsArchiveCreateRequest,
323 ) -> Result<
324 datadog::ResponseContent<crate::datadogV2::model::LogsArchive>,
325 datadog::Error<CreateLogsArchiveError>,
326 > {
327 let local_configuration = &self.config;
328 let operation_id = "v2.create_logs_archive";
329
330 let local_client = &self.client;
331
332 let local_uri_str = format!(
333 "{}/api/v2/logs/config/archives",
334 local_configuration.get_operation_host(operation_id)
335 );
336 let mut local_req_builder =
337 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
338
339 let mut headers = HeaderMap::new();
341 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
342 headers.insert("Accept", HeaderValue::from_static("application/json"));
343
344 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
346 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
347 Err(e) => {
348 log::warn!("Failed to parse user agent header: {e}, falling back to default");
349 headers.insert(
350 reqwest::header::USER_AGENT,
351 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
352 )
353 }
354 };
355
356 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
358 headers.insert(
359 "DD-API-KEY",
360 HeaderValue::from_str(local_key.key.as_str())
361 .expect("failed to parse DD-API-KEY header"),
362 );
363 };
364 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
365 headers.insert(
366 "DD-APPLICATION-KEY",
367 HeaderValue::from_str(local_key.key.as_str())
368 .expect("failed to parse DD-APPLICATION-KEY header"),
369 );
370 };
371
372 let output = Vec::new();
374 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
375 if body.serialize(&mut ser).is_ok() {
376 if let Some(content_encoding) = headers.get("Content-Encoding") {
377 match content_encoding.to_str().unwrap_or_default() {
378 "gzip" => {
379 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
380 let _ = enc.write_all(ser.into_inner().as_slice());
381 match enc.finish() {
382 Ok(buf) => {
383 local_req_builder = local_req_builder.body(buf);
384 }
385 Err(e) => return Err(datadog::Error::Io(e)),
386 }
387 }
388 "deflate" => {
389 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
390 let _ = enc.write_all(ser.into_inner().as_slice());
391 match enc.finish() {
392 Ok(buf) => {
393 local_req_builder = local_req_builder.body(buf);
394 }
395 Err(e) => return Err(datadog::Error::Io(e)),
396 }
397 }
398 "zstd1" => {
399 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
400 let _ = enc.write_all(ser.into_inner().as_slice());
401 match enc.finish() {
402 Ok(buf) => {
403 local_req_builder = local_req_builder.body(buf);
404 }
405 Err(e) => return Err(datadog::Error::Io(e)),
406 }
407 }
408 _ => {
409 local_req_builder = local_req_builder.body(ser.into_inner());
410 }
411 }
412 } else {
413 local_req_builder = local_req_builder.body(ser.into_inner());
414 }
415 }
416
417 local_req_builder = local_req_builder.headers(headers);
418 let local_req = local_req_builder.build()?;
419 log::debug!("request content: {:?}", local_req.body());
420 let local_resp = local_client.execute(local_req).await?;
421
422 let local_status = local_resp.status();
423 let local_content = local_resp.text().await?;
424 log::debug!("response content: {}", local_content);
425
426 if !local_status.is_client_error() && !local_status.is_server_error() {
427 match serde_json::from_str::<crate::datadogV2::model::LogsArchive>(&local_content) {
428 Ok(e) => {
429 return Ok(datadog::ResponseContent {
430 status: local_status,
431 content: local_content,
432 entity: Some(e),
433 })
434 }
435 Err(e) => return Err(datadog::Error::Serde(e)),
436 };
437 } else {
438 let local_entity: Option<CreateLogsArchiveError> =
439 serde_json::from_str(&local_content).ok();
440 let local_error = datadog::ResponseContent {
441 status: local_status,
442 content: local_content,
443 entity: local_entity,
444 };
445 Err(datadog::Error::ResponseError(local_error))
446 }
447 }
448
449 pub async fn delete_logs_archive(
451 &self,
452 archive_id: String,
453 ) -> Result<(), datadog::Error<DeleteLogsArchiveError>> {
454 match self.delete_logs_archive_with_http_info(archive_id).await {
455 Ok(_) => Ok(()),
456 Err(err) => Err(err),
457 }
458 }
459
460 pub async fn delete_logs_archive_with_http_info(
462 &self,
463 archive_id: String,
464 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteLogsArchiveError>> {
465 let local_configuration = &self.config;
466 let operation_id = "v2.delete_logs_archive";
467
468 let local_client = &self.client;
469
470 let local_uri_str = format!(
471 "{}/api/v2/logs/config/archives/{archive_id}",
472 local_configuration.get_operation_host(operation_id),
473 archive_id = datadog::urlencode(archive_id)
474 );
475 let mut local_req_builder =
476 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
477
478 let mut headers = HeaderMap::new();
480 headers.insert("Accept", HeaderValue::from_static("*/*"));
481
482 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
484 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
485 Err(e) => {
486 log::warn!("Failed to parse user agent header: {e}, falling back to default");
487 headers.insert(
488 reqwest::header::USER_AGENT,
489 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
490 )
491 }
492 };
493
494 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
496 headers.insert(
497 "DD-API-KEY",
498 HeaderValue::from_str(local_key.key.as_str())
499 .expect("failed to parse DD-API-KEY header"),
500 );
501 };
502 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
503 headers.insert(
504 "DD-APPLICATION-KEY",
505 HeaderValue::from_str(local_key.key.as_str())
506 .expect("failed to parse DD-APPLICATION-KEY header"),
507 );
508 };
509
510 local_req_builder = local_req_builder.headers(headers);
511 let local_req = local_req_builder.build()?;
512 log::debug!("request content: {:?}", local_req.body());
513 let local_resp = local_client.execute(local_req).await?;
514
515 let local_status = local_resp.status();
516 let local_content = local_resp.text().await?;
517 log::debug!("response content: {}", local_content);
518
519 if !local_status.is_client_error() && !local_status.is_server_error() {
520 Ok(datadog::ResponseContent {
521 status: local_status,
522 content: local_content,
523 entity: None,
524 })
525 } else {
526 let local_entity: Option<DeleteLogsArchiveError> =
527 serde_json::from_str(&local_content).ok();
528 let local_error = datadog::ResponseContent {
529 status: local_status,
530 content: local_content,
531 entity: local_entity,
532 };
533 Err(datadog::Error::ResponseError(local_error))
534 }
535 }
536
537 pub async fn get_logs_archive(
539 &self,
540 archive_id: String,
541 ) -> Result<crate::datadogV2::model::LogsArchive, datadog::Error<GetLogsArchiveError>> {
542 match self.get_logs_archive_with_http_info(archive_id).await {
543 Ok(response_content) => {
544 if let Some(e) = response_content.entity {
545 Ok(e)
546 } else {
547 Err(datadog::Error::Serde(serde::de::Error::custom(
548 "response content was None",
549 )))
550 }
551 }
552 Err(err) => Err(err),
553 }
554 }
555
556 pub async fn get_logs_archive_with_http_info(
558 &self,
559 archive_id: String,
560 ) -> Result<
561 datadog::ResponseContent<crate::datadogV2::model::LogsArchive>,
562 datadog::Error<GetLogsArchiveError>,
563 > {
564 let local_configuration = &self.config;
565 let operation_id = "v2.get_logs_archive";
566
567 let local_client = &self.client;
568
569 let local_uri_str = format!(
570 "{}/api/v2/logs/config/archives/{archive_id}",
571 local_configuration.get_operation_host(operation_id),
572 archive_id = datadog::urlencode(archive_id)
573 );
574 let mut local_req_builder =
575 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
576
577 let mut headers = HeaderMap::new();
579 headers.insert("Accept", HeaderValue::from_static("application/json"));
580
581 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
583 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
584 Err(e) => {
585 log::warn!("Failed to parse user agent header: {e}, falling back to default");
586 headers.insert(
587 reqwest::header::USER_AGENT,
588 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
589 )
590 }
591 };
592
593 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
595 headers.insert(
596 "DD-API-KEY",
597 HeaderValue::from_str(local_key.key.as_str())
598 .expect("failed to parse DD-API-KEY header"),
599 );
600 };
601 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
602 headers.insert(
603 "DD-APPLICATION-KEY",
604 HeaderValue::from_str(local_key.key.as_str())
605 .expect("failed to parse DD-APPLICATION-KEY header"),
606 );
607 };
608
609 local_req_builder = local_req_builder.headers(headers);
610 let local_req = local_req_builder.build()?;
611 log::debug!("request content: {:?}", local_req.body());
612 let local_resp = local_client.execute(local_req).await?;
613
614 let local_status = local_resp.status();
615 let local_content = local_resp.text().await?;
616 log::debug!("response content: {}", local_content);
617
618 if !local_status.is_client_error() && !local_status.is_server_error() {
619 match serde_json::from_str::<crate::datadogV2::model::LogsArchive>(&local_content) {
620 Ok(e) => {
621 return Ok(datadog::ResponseContent {
622 status: local_status,
623 content: local_content,
624 entity: Some(e),
625 })
626 }
627 Err(e) => return Err(datadog::Error::Serde(e)),
628 };
629 } else {
630 let local_entity: Option<GetLogsArchiveError> =
631 serde_json::from_str(&local_content).ok();
632 let local_error = datadog::ResponseContent {
633 status: local_status,
634 content: local_content,
635 entity: local_entity,
636 };
637 Err(datadog::Error::ResponseError(local_error))
638 }
639 }
640
641 pub async fn get_logs_archive_order(
644 &self,
645 ) -> Result<crate::datadogV2::model::LogsArchiveOrder, datadog::Error<GetLogsArchiveOrderError>>
646 {
647 match self.get_logs_archive_order_with_http_info().await {
648 Ok(response_content) => {
649 if let Some(e) = response_content.entity {
650 Ok(e)
651 } else {
652 Err(datadog::Error::Serde(serde::de::Error::custom(
653 "response content was None",
654 )))
655 }
656 }
657 Err(err) => Err(err),
658 }
659 }
660
661 pub async fn get_logs_archive_order_with_http_info(
664 &self,
665 ) -> Result<
666 datadog::ResponseContent<crate::datadogV2::model::LogsArchiveOrder>,
667 datadog::Error<GetLogsArchiveOrderError>,
668 > {
669 let local_configuration = &self.config;
670 let operation_id = "v2.get_logs_archive_order";
671
672 let local_client = &self.client;
673
674 let local_uri_str = format!(
675 "{}/api/v2/logs/config/archive-order",
676 local_configuration.get_operation_host(operation_id)
677 );
678 let mut local_req_builder =
679 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
680
681 let mut headers = HeaderMap::new();
683 headers.insert("Accept", HeaderValue::from_static("application/json"));
684
685 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
687 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
688 Err(e) => {
689 log::warn!("Failed to parse user agent header: {e}, falling back to default");
690 headers.insert(
691 reqwest::header::USER_AGENT,
692 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
693 )
694 }
695 };
696
697 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
699 headers.insert(
700 "DD-API-KEY",
701 HeaderValue::from_str(local_key.key.as_str())
702 .expect("failed to parse DD-API-KEY header"),
703 );
704 };
705 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
706 headers.insert(
707 "DD-APPLICATION-KEY",
708 HeaderValue::from_str(local_key.key.as_str())
709 .expect("failed to parse DD-APPLICATION-KEY header"),
710 );
711 };
712
713 local_req_builder = local_req_builder.headers(headers);
714 let local_req = local_req_builder.build()?;
715 log::debug!("request content: {:?}", local_req.body());
716 let local_resp = local_client.execute(local_req).await?;
717
718 let local_status = local_resp.status();
719 let local_content = local_resp.text().await?;
720 log::debug!("response content: {}", local_content);
721
722 if !local_status.is_client_error() && !local_status.is_server_error() {
723 match serde_json::from_str::<crate::datadogV2::model::LogsArchiveOrder>(&local_content)
724 {
725 Ok(e) => {
726 return Ok(datadog::ResponseContent {
727 status: local_status,
728 content: local_content,
729 entity: Some(e),
730 })
731 }
732 Err(e) => return Err(datadog::Error::Serde(e)),
733 };
734 } else {
735 let local_entity: Option<GetLogsArchiveOrderError> =
736 serde_json::from_str(&local_content).ok();
737 let local_error = datadog::ResponseContent {
738 status: local_status,
739 content: local_content,
740 entity: local_entity,
741 };
742 Err(datadog::Error::ResponseError(local_error))
743 }
744 }
745
746 pub async fn list_archive_read_roles(
748 &self,
749 archive_id: String,
750 ) -> Result<crate::datadogV2::model::RolesResponse, datadog::Error<ListArchiveReadRolesError>>
751 {
752 match self
753 .list_archive_read_roles_with_http_info(archive_id)
754 .await
755 {
756 Ok(response_content) => {
757 if let Some(e) = response_content.entity {
758 Ok(e)
759 } else {
760 Err(datadog::Error::Serde(serde::de::Error::custom(
761 "response content was None",
762 )))
763 }
764 }
765 Err(err) => Err(err),
766 }
767 }
768
769 pub async fn list_archive_read_roles_with_http_info(
771 &self,
772 archive_id: String,
773 ) -> Result<
774 datadog::ResponseContent<crate::datadogV2::model::RolesResponse>,
775 datadog::Error<ListArchiveReadRolesError>,
776 > {
777 let local_configuration = &self.config;
778 let operation_id = "v2.list_archive_read_roles";
779
780 let local_client = &self.client;
781
782 let local_uri_str = format!(
783 "{}/api/v2/logs/config/archives/{archive_id}/readers",
784 local_configuration.get_operation_host(operation_id),
785 archive_id = datadog::urlencode(archive_id)
786 );
787 let mut local_req_builder =
788 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
789
790 let mut headers = HeaderMap::new();
792 headers.insert("Accept", HeaderValue::from_static("application/json"));
793
794 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
796 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
797 Err(e) => {
798 log::warn!("Failed to parse user agent header: {e}, falling back to default");
799 headers.insert(
800 reqwest::header::USER_AGENT,
801 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
802 )
803 }
804 };
805
806 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
808 headers.insert(
809 "DD-API-KEY",
810 HeaderValue::from_str(local_key.key.as_str())
811 .expect("failed to parse DD-API-KEY header"),
812 );
813 };
814 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
815 headers.insert(
816 "DD-APPLICATION-KEY",
817 HeaderValue::from_str(local_key.key.as_str())
818 .expect("failed to parse DD-APPLICATION-KEY header"),
819 );
820 };
821
822 local_req_builder = local_req_builder.headers(headers);
823 let local_req = local_req_builder.build()?;
824 log::debug!("request content: {:?}", local_req.body());
825 let local_resp = local_client.execute(local_req).await?;
826
827 let local_status = local_resp.status();
828 let local_content = local_resp.text().await?;
829 log::debug!("response content: {}", local_content);
830
831 if !local_status.is_client_error() && !local_status.is_server_error() {
832 match serde_json::from_str::<crate::datadogV2::model::RolesResponse>(&local_content) {
833 Ok(e) => {
834 return Ok(datadog::ResponseContent {
835 status: local_status,
836 content: local_content,
837 entity: Some(e),
838 })
839 }
840 Err(e) => return Err(datadog::Error::Serde(e)),
841 };
842 } else {
843 let local_entity: Option<ListArchiveReadRolesError> =
844 serde_json::from_str(&local_content).ok();
845 let local_error = datadog::ResponseContent {
846 status: local_status,
847 content: local_content,
848 entity: local_entity,
849 };
850 Err(datadog::Error::ResponseError(local_error))
851 }
852 }
853
854 pub async fn list_logs_archives(
856 &self,
857 ) -> Result<crate::datadogV2::model::LogsArchives, datadog::Error<ListLogsArchivesError>> {
858 match self.list_logs_archives_with_http_info().await {
859 Ok(response_content) => {
860 if let Some(e) = response_content.entity {
861 Ok(e)
862 } else {
863 Err(datadog::Error::Serde(serde::de::Error::custom(
864 "response content was None",
865 )))
866 }
867 }
868 Err(err) => Err(err),
869 }
870 }
871
872 pub async fn list_logs_archives_with_http_info(
874 &self,
875 ) -> Result<
876 datadog::ResponseContent<crate::datadogV2::model::LogsArchives>,
877 datadog::Error<ListLogsArchivesError>,
878 > {
879 let local_configuration = &self.config;
880 let operation_id = "v2.list_logs_archives";
881
882 let local_client = &self.client;
883
884 let local_uri_str = format!(
885 "{}/api/v2/logs/config/archives",
886 local_configuration.get_operation_host(operation_id)
887 );
888 let mut local_req_builder =
889 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
890
891 let mut headers = HeaderMap::new();
893 headers.insert("Accept", HeaderValue::from_static("application/json"));
894
895 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
897 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
898 Err(e) => {
899 log::warn!("Failed to parse user agent header: {e}, falling back to default");
900 headers.insert(
901 reqwest::header::USER_AGENT,
902 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
903 )
904 }
905 };
906
907 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
909 headers.insert(
910 "DD-API-KEY",
911 HeaderValue::from_str(local_key.key.as_str())
912 .expect("failed to parse DD-API-KEY header"),
913 );
914 };
915 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
916 headers.insert(
917 "DD-APPLICATION-KEY",
918 HeaderValue::from_str(local_key.key.as_str())
919 .expect("failed to parse DD-APPLICATION-KEY header"),
920 );
921 };
922
923 local_req_builder = local_req_builder.headers(headers);
924 let local_req = local_req_builder.build()?;
925 log::debug!("request content: {:?}", local_req.body());
926 let local_resp = local_client.execute(local_req).await?;
927
928 let local_status = local_resp.status();
929 let local_content = local_resp.text().await?;
930 log::debug!("response content: {}", local_content);
931
932 if !local_status.is_client_error() && !local_status.is_server_error() {
933 match serde_json::from_str::<crate::datadogV2::model::LogsArchives>(&local_content) {
934 Ok(e) => {
935 return Ok(datadog::ResponseContent {
936 status: local_status,
937 content: local_content,
938 entity: Some(e),
939 })
940 }
941 Err(e) => return Err(datadog::Error::Serde(e)),
942 };
943 } else {
944 let local_entity: Option<ListLogsArchivesError> =
945 serde_json::from_str(&local_content).ok();
946 let local_error = datadog::ResponseContent {
947 status: local_status,
948 content: local_content,
949 entity: local_entity,
950 };
951 Err(datadog::Error::ResponseError(local_error))
952 }
953 }
954
955 pub async fn remove_role_from_archive(
957 &self,
958 archive_id: String,
959 body: crate::datadogV2::model::RelationshipToRole,
960 ) -> Result<(), datadog::Error<RemoveRoleFromArchiveError>> {
961 match self
962 .remove_role_from_archive_with_http_info(archive_id, body)
963 .await
964 {
965 Ok(_) => Ok(()),
966 Err(err) => Err(err),
967 }
968 }
969
970 pub async fn remove_role_from_archive_with_http_info(
972 &self,
973 archive_id: String,
974 body: crate::datadogV2::model::RelationshipToRole,
975 ) -> Result<datadog::ResponseContent<()>, datadog::Error<RemoveRoleFromArchiveError>> {
976 let local_configuration = &self.config;
977 let operation_id = "v2.remove_role_from_archive";
978
979 let local_client = &self.client;
980
981 let local_uri_str = format!(
982 "{}/api/v2/logs/config/archives/{archive_id}/readers",
983 local_configuration.get_operation_host(operation_id),
984 archive_id = datadog::urlencode(archive_id)
985 );
986 let mut local_req_builder =
987 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
988
989 let mut headers = HeaderMap::new();
991 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
992 headers.insert("Accept", HeaderValue::from_static("*/*"));
993
994 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
996 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
997 Err(e) => {
998 log::warn!("Failed to parse user agent header: {e}, falling back to default");
999 headers.insert(
1000 reqwest::header::USER_AGENT,
1001 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1002 )
1003 }
1004 };
1005
1006 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1008 headers.insert(
1009 "DD-API-KEY",
1010 HeaderValue::from_str(local_key.key.as_str())
1011 .expect("failed to parse DD-API-KEY header"),
1012 );
1013 };
1014 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1015 headers.insert(
1016 "DD-APPLICATION-KEY",
1017 HeaderValue::from_str(local_key.key.as_str())
1018 .expect("failed to parse DD-APPLICATION-KEY header"),
1019 );
1020 };
1021
1022 let output = Vec::new();
1024 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1025 if body.serialize(&mut ser).is_ok() {
1026 if let Some(content_encoding) = headers.get("Content-Encoding") {
1027 match content_encoding.to_str().unwrap_or_default() {
1028 "gzip" => {
1029 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1030 let _ = enc.write_all(ser.into_inner().as_slice());
1031 match enc.finish() {
1032 Ok(buf) => {
1033 local_req_builder = local_req_builder.body(buf);
1034 }
1035 Err(e) => return Err(datadog::Error::Io(e)),
1036 }
1037 }
1038 "deflate" => {
1039 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1040 let _ = enc.write_all(ser.into_inner().as_slice());
1041 match enc.finish() {
1042 Ok(buf) => {
1043 local_req_builder = local_req_builder.body(buf);
1044 }
1045 Err(e) => return Err(datadog::Error::Io(e)),
1046 }
1047 }
1048 "zstd1" => {
1049 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1050 let _ = enc.write_all(ser.into_inner().as_slice());
1051 match enc.finish() {
1052 Ok(buf) => {
1053 local_req_builder = local_req_builder.body(buf);
1054 }
1055 Err(e) => return Err(datadog::Error::Io(e)),
1056 }
1057 }
1058 _ => {
1059 local_req_builder = local_req_builder.body(ser.into_inner());
1060 }
1061 }
1062 } else {
1063 local_req_builder = local_req_builder.body(ser.into_inner());
1064 }
1065 }
1066
1067 local_req_builder = local_req_builder.headers(headers);
1068 let local_req = local_req_builder.build()?;
1069 log::debug!("request content: {:?}", local_req.body());
1070 let local_resp = local_client.execute(local_req).await?;
1071
1072 let local_status = local_resp.status();
1073 let local_content = local_resp.text().await?;
1074 log::debug!("response content: {}", local_content);
1075
1076 if !local_status.is_client_error() && !local_status.is_server_error() {
1077 Ok(datadog::ResponseContent {
1078 status: local_status,
1079 content: local_content,
1080 entity: None,
1081 })
1082 } else {
1083 let local_entity: Option<RemoveRoleFromArchiveError> =
1084 serde_json::from_str(&local_content).ok();
1085 let local_error = datadog::ResponseContent {
1086 status: local_status,
1087 content: local_content,
1088 entity: local_entity,
1089 };
1090 Err(datadog::Error::ResponseError(local_error))
1091 }
1092 }
1093
1094 pub async fn update_logs_archive(
1099 &self,
1100 archive_id: String,
1101 body: crate::datadogV2::model::LogsArchiveCreateRequest,
1102 ) -> Result<crate::datadogV2::model::LogsArchive, datadog::Error<UpdateLogsArchiveError>> {
1103 match self
1104 .update_logs_archive_with_http_info(archive_id, body)
1105 .await
1106 {
1107 Ok(response_content) => {
1108 if let Some(e) = response_content.entity {
1109 Ok(e)
1110 } else {
1111 Err(datadog::Error::Serde(serde::de::Error::custom(
1112 "response content was None",
1113 )))
1114 }
1115 }
1116 Err(err) => Err(err),
1117 }
1118 }
1119
1120 pub async fn update_logs_archive_with_http_info(
1125 &self,
1126 archive_id: String,
1127 body: crate::datadogV2::model::LogsArchiveCreateRequest,
1128 ) -> Result<
1129 datadog::ResponseContent<crate::datadogV2::model::LogsArchive>,
1130 datadog::Error<UpdateLogsArchiveError>,
1131 > {
1132 let local_configuration = &self.config;
1133 let operation_id = "v2.update_logs_archive";
1134
1135 let local_client = &self.client;
1136
1137 let local_uri_str = format!(
1138 "{}/api/v2/logs/config/archives/{archive_id}",
1139 local_configuration.get_operation_host(operation_id),
1140 archive_id = datadog::urlencode(archive_id)
1141 );
1142 let mut local_req_builder =
1143 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1144
1145 let mut headers = HeaderMap::new();
1147 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1148 headers.insert("Accept", HeaderValue::from_static("application/json"));
1149
1150 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1152 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1153 Err(e) => {
1154 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1155 headers.insert(
1156 reqwest::header::USER_AGENT,
1157 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1158 )
1159 }
1160 };
1161
1162 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1164 headers.insert(
1165 "DD-API-KEY",
1166 HeaderValue::from_str(local_key.key.as_str())
1167 .expect("failed to parse DD-API-KEY header"),
1168 );
1169 };
1170 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1171 headers.insert(
1172 "DD-APPLICATION-KEY",
1173 HeaderValue::from_str(local_key.key.as_str())
1174 .expect("failed to parse DD-APPLICATION-KEY header"),
1175 );
1176 };
1177
1178 let output = Vec::new();
1180 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1181 if body.serialize(&mut ser).is_ok() {
1182 if let Some(content_encoding) = headers.get("Content-Encoding") {
1183 match content_encoding.to_str().unwrap_or_default() {
1184 "gzip" => {
1185 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1186 let _ = enc.write_all(ser.into_inner().as_slice());
1187 match enc.finish() {
1188 Ok(buf) => {
1189 local_req_builder = local_req_builder.body(buf);
1190 }
1191 Err(e) => return Err(datadog::Error::Io(e)),
1192 }
1193 }
1194 "deflate" => {
1195 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1196 let _ = enc.write_all(ser.into_inner().as_slice());
1197 match enc.finish() {
1198 Ok(buf) => {
1199 local_req_builder = local_req_builder.body(buf);
1200 }
1201 Err(e) => return Err(datadog::Error::Io(e)),
1202 }
1203 }
1204 "zstd1" => {
1205 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1206 let _ = enc.write_all(ser.into_inner().as_slice());
1207 match enc.finish() {
1208 Ok(buf) => {
1209 local_req_builder = local_req_builder.body(buf);
1210 }
1211 Err(e) => return Err(datadog::Error::Io(e)),
1212 }
1213 }
1214 _ => {
1215 local_req_builder = local_req_builder.body(ser.into_inner());
1216 }
1217 }
1218 } else {
1219 local_req_builder = local_req_builder.body(ser.into_inner());
1220 }
1221 }
1222
1223 local_req_builder = local_req_builder.headers(headers);
1224 let local_req = local_req_builder.build()?;
1225 log::debug!("request content: {:?}", local_req.body());
1226 let local_resp = local_client.execute(local_req).await?;
1227
1228 let local_status = local_resp.status();
1229 let local_content = local_resp.text().await?;
1230 log::debug!("response content: {}", local_content);
1231
1232 if !local_status.is_client_error() && !local_status.is_server_error() {
1233 match serde_json::from_str::<crate::datadogV2::model::LogsArchive>(&local_content) {
1234 Ok(e) => {
1235 return Ok(datadog::ResponseContent {
1236 status: local_status,
1237 content: local_content,
1238 entity: Some(e),
1239 })
1240 }
1241 Err(e) => return Err(datadog::Error::Serde(e)),
1242 };
1243 } else {
1244 let local_entity: Option<UpdateLogsArchiveError> =
1245 serde_json::from_str(&local_content).ok();
1246 let local_error = datadog::ResponseContent {
1247 status: local_status,
1248 content: local_content,
1249 entity: local_entity,
1250 };
1251 Err(datadog::Error::ResponseError(local_error))
1252 }
1253 }
1254
1255 pub async fn update_logs_archive_order(
1261 &self,
1262 body: crate::datadogV2::model::LogsArchiveOrder,
1263 ) -> Result<
1264 crate::datadogV2::model::LogsArchiveOrder,
1265 datadog::Error<UpdateLogsArchiveOrderError>,
1266 > {
1267 match self.update_logs_archive_order_with_http_info(body).await {
1268 Ok(response_content) => {
1269 if let Some(e) = response_content.entity {
1270 Ok(e)
1271 } else {
1272 Err(datadog::Error::Serde(serde::de::Error::custom(
1273 "response content was None",
1274 )))
1275 }
1276 }
1277 Err(err) => Err(err),
1278 }
1279 }
1280
1281 pub async fn update_logs_archive_order_with_http_info(
1287 &self,
1288 body: crate::datadogV2::model::LogsArchiveOrder,
1289 ) -> Result<
1290 datadog::ResponseContent<crate::datadogV2::model::LogsArchiveOrder>,
1291 datadog::Error<UpdateLogsArchiveOrderError>,
1292 > {
1293 let local_configuration = &self.config;
1294 let operation_id = "v2.update_logs_archive_order";
1295
1296 let local_client = &self.client;
1297
1298 let local_uri_str = format!(
1299 "{}/api/v2/logs/config/archive-order",
1300 local_configuration.get_operation_host(operation_id)
1301 );
1302 let mut local_req_builder =
1303 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1304
1305 let mut headers = HeaderMap::new();
1307 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1308 headers.insert("Accept", HeaderValue::from_static("application/json"));
1309
1310 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1312 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1313 Err(e) => {
1314 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1315 headers.insert(
1316 reqwest::header::USER_AGENT,
1317 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1318 )
1319 }
1320 };
1321
1322 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1324 headers.insert(
1325 "DD-API-KEY",
1326 HeaderValue::from_str(local_key.key.as_str())
1327 .expect("failed to parse DD-API-KEY header"),
1328 );
1329 };
1330 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1331 headers.insert(
1332 "DD-APPLICATION-KEY",
1333 HeaderValue::from_str(local_key.key.as_str())
1334 .expect("failed to parse DD-APPLICATION-KEY header"),
1335 );
1336 };
1337
1338 let output = Vec::new();
1340 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1341 if body.serialize(&mut ser).is_ok() {
1342 if let Some(content_encoding) = headers.get("Content-Encoding") {
1343 match content_encoding.to_str().unwrap_or_default() {
1344 "gzip" => {
1345 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1346 let _ = enc.write_all(ser.into_inner().as_slice());
1347 match enc.finish() {
1348 Ok(buf) => {
1349 local_req_builder = local_req_builder.body(buf);
1350 }
1351 Err(e) => return Err(datadog::Error::Io(e)),
1352 }
1353 }
1354 "deflate" => {
1355 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1356 let _ = enc.write_all(ser.into_inner().as_slice());
1357 match enc.finish() {
1358 Ok(buf) => {
1359 local_req_builder = local_req_builder.body(buf);
1360 }
1361 Err(e) => return Err(datadog::Error::Io(e)),
1362 }
1363 }
1364 "zstd1" => {
1365 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1366 let _ = enc.write_all(ser.into_inner().as_slice());
1367 match enc.finish() {
1368 Ok(buf) => {
1369 local_req_builder = local_req_builder.body(buf);
1370 }
1371 Err(e) => return Err(datadog::Error::Io(e)),
1372 }
1373 }
1374 _ => {
1375 local_req_builder = local_req_builder.body(ser.into_inner());
1376 }
1377 }
1378 } else {
1379 local_req_builder = local_req_builder.body(ser.into_inner());
1380 }
1381 }
1382
1383 local_req_builder = local_req_builder.headers(headers);
1384 let local_req = local_req_builder.build()?;
1385 log::debug!("request content: {:?}", local_req.body());
1386 let local_resp = local_client.execute(local_req).await?;
1387
1388 let local_status = local_resp.status();
1389 let local_content = local_resp.text().await?;
1390 log::debug!("response content: {}", local_content);
1391
1392 if !local_status.is_client_error() && !local_status.is_server_error() {
1393 match serde_json::from_str::<crate::datadogV2::model::LogsArchiveOrder>(&local_content)
1394 {
1395 Ok(e) => {
1396 return Ok(datadog::ResponseContent {
1397 status: local_status,
1398 content: local_content,
1399 entity: Some(e),
1400 })
1401 }
1402 Err(e) => return Err(datadog::Error::Serde(e)),
1403 };
1404 } else {
1405 let local_entity: Option<UpdateLogsArchiveOrderError> =
1406 serde_json::from_str(&local_content).ok();
1407 let local_error = datadog::ResponseContent {
1408 status: local_status,
1409 content: local_content,
1410 entity: local_entity,
1411 };
1412 Err(datadog::Error::ResponseError(local_error))
1413 }
1414 }
1415}