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#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct ListAWSAccountsOptionalParams {
17 pub aws_account_id: Option<String>,
19}
20
21impl ListAWSAccountsOptionalParams {
22 pub fn aws_account_id(mut self, value: String) -> Self {
24 self.aws_account_id = Some(value);
25 self
26 }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum CreateAWSAccountError {
33 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum CreateNewAWSExternalIDError {
41 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum DeleteAWSAccountError {
49 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetAWSAccountError {
57 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetAWSIntegrationIAMPermissionsError {
65 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ListAWSAccountsError {
73 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum ListAWSNamespacesError {
81 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum UpdateAWSAccountError {
89 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone)]
96pub struct AWSIntegrationAPI {
97 config: datadog::Configuration,
98 client: reqwest_middleware::ClientWithMiddleware,
99}
100
101impl Default for AWSIntegrationAPI {
102 fn default() -> Self {
103 Self::with_config(datadog::Configuration::default())
104 }
105}
106
107impl AWSIntegrationAPI {
108 pub fn new() -> Self {
109 Self::default()
110 }
111 pub fn with_config(config: datadog::Configuration) -> Self {
112 let mut reqwest_client_builder = reqwest::Client::builder();
113
114 if let Some(proxy_url) = &config.proxy_url {
115 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
116 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
117 }
118
119 let mut middleware_client_builder =
120 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
121
122 if config.enable_retry {
123 struct RetryableStatus;
124 impl reqwest_retry::RetryableStrategy for RetryableStatus {
125 fn handle(
126 &self,
127 res: &Result<reqwest::Response, reqwest_middleware::Error>,
128 ) -> Option<reqwest_retry::Retryable> {
129 match res {
130 Ok(success) => reqwest_retry::default_on_request_success(success),
131 Err(_) => None,
132 }
133 }
134 }
135 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
136 .build_with_max_retries(config.max_retries);
137
138 let retry_middleware =
139 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
140 backoff_policy,
141 RetryableStatus,
142 );
143
144 middleware_client_builder = middleware_client_builder.with(retry_middleware);
145 }
146
147 let client = middleware_client_builder.build();
148
149 Self { config, client }
150 }
151
152 pub fn with_client_and_config(
153 config: datadog::Configuration,
154 client: reqwest_middleware::ClientWithMiddleware,
155 ) -> Self {
156 Self { config, client }
157 }
158
159 pub async fn create_aws_account(
161 &self,
162 body: crate::datadogV2::model::AWSAccountCreateRequest,
163 ) -> Result<crate::datadogV2::model::AWSAccountResponse, datadog::Error<CreateAWSAccountError>>
164 {
165 match self.create_aws_account_with_http_info(body).await {
166 Ok(response_content) => {
167 if let Some(e) = response_content.entity {
168 Ok(e)
169 } else {
170 Err(datadog::Error::Serde(serde::de::Error::custom(
171 "response content was None",
172 )))
173 }
174 }
175 Err(err) => Err(err),
176 }
177 }
178
179 pub async fn create_aws_account_with_http_info(
181 &self,
182 body: crate::datadogV2::model::AWSAccountCreateRequest,
183 ) -> Result<
184 datadog::ResponseContent<crate::datadogV2::model::AWSAccountResponse>,
185 datadog::Error<CreateAWSAccountError>,
186 > {
187 let local_configuration = &self.config;
188 let operation_id = "v2.create_aws_account";
189
190 let local_client = &self.client;
191
192 let local_uri_str = format!(
193 "{}/api/v2/integration/aws/accounts",
194 local_configuration.get_operation_host(operation_id)
195 );
196 let mut local_req_builder =
197 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
198
199 let mut headers = HeaderMap::new();
201 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
202 headers.insert("Accept", HeaderValue::from_static("application/json"));
203
204 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
206 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
207 Err(e) => {
208 log::warn!("Failed to parse user agent header: {e}, falling back to default");
209 headers.insert(
210 reqwest::header::USER_AGENT,
211 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
212 )
213 }
214 };
215
216 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
218 headers.insert(
219 "DD-API-KEY",
220 HeaderValue::from_str(local_key.key.as_str())
221 .expect("failed to parse DD-API-KEY header"),
222 );
223 };
224 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
225 headers.insert(
226 "DD-APPLICATION-KEY",
227 HeaderValue::from_str(local_key.key.as_str())
228 .expect("failed to parse DD-APPLICATION-KEY header"),
229 );
230 };
231
232 let output = Vec::new();
234 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
235 if body.serialize(&mut ser).is_ok() {
236 if let Some(content_encoding) = headers.get("Content-Encoding") {
237 match content_encoding.to_str().unwrap_or_default() {
238 "gzip" => {
239 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
240 let _ = enc.write_all(ser.into_inner().as_slice());
241 match enc.finish() {
242 Ok(buf) => {
243 local_req_builder = local_req_builder.body(buf);
244 }
245 Err(e) => return Err(datadog::Error::Io(e)),
246 }
247 }
248 "deflate" => {
249 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
250 let _ = enc.write_all(ser.into_inner().as_slice());
251 match enc.finish() {
252 Ok(buf) => {
253 local_req_builder = local_req_builder.body(buf);
254 }
255 Err(e) => return Err(datadog::Error::Io(e)),
256 }
257 }
258 "zstd1" => {
259 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
260 let _ = enc.write_all(ser.into_inner().as_slice());
261 match enc.finish() {
262 Ok(buf) => {
263 local_req_builder = local_req_builder.body(buf);
264 }
265 Err(e) => return Err(datadog::Error::Io(e)),
266 }
267 }
268 _ => {
269 local_req_builder = local_req_builder.body(ser.into_inner());
270 }
271 }
272 } else {
273 local_req_builder = local_req_builder.body(ser.into_inner());
274 }
275 }
276
277 local_req_builder = local_req_builder.headers(headers);
278 let local_req = local_req_builder.build()?;
279 log::debug!("request content: {:?}", local_req.body());
280 let local_resp = local_client.execute(local_req).await?;
281
282 let local_status = local_resp.status();
283 let local_content = local_resp.text().await?;
284 log::debug!("response content: {}", local_content);
285
286 if !local_status.is_client_error() && !local_status.is_server_error() {
287 match serde_json::from_str::<crate::datadogV2::model::AWSAccountResponse>(
288 &local_content,
289 ) {
290 Ok(e) => {
291 return Ok(datadog::ResponseContent {
292 status: local_status,
293 content: local_content,
294 entity: Some(e),
295 })
296 }
297 Err(e) => return Err(datadog::Error::Serde(e)),
298 };
299 } else {
300 let local_entity: Option<CreateAWSAccountError> =
301 serde_json::from_str(&local_content).ok();
302 let local_error = datadog::ResponseContent {
303 status: local_status,
304 content: local_content,
305 entity: local_entity,
306 };
307 Err(datadog::Error::ResponseError(local_error))
308 }
309 }
310
311 pub async fn create_new_aws_external_id(
313 &self,
314 ) -> Result<
315 crate::datadogV2::model::AWSNewExternalIDResponse,
316 datadog::Error<CreateNewAWSExternalIDError>,
317 > {
318 match self.create_new_aws_external_id_with_http_info().await {
319 Ok(response_content) => {
320 if let Some(e) = response_content.entity {
321 Ok(e)
322 } else {
323 Err(datadog::Error::Serde(serde::de::Error::custom(
324 "response content was None",
325 )))
326 }
327 }
328 Err(err) => Err(err),
329 }
330 }
331
332 pub async fn create_new_aws_external_id_with_http_info(
334 &self,
335 ) -> Result<
336 datadog::ResponseContent<crate::datadogV2::model::AWSNewExternalIDResponse>,
337 datadog::Error<CreateNewAWSExternalIDError>,
338 > {
339 let local_configuration = &self.config;
340 let operation_id = "v2.create_new_aws_external_id";
341
342 let local_client = &self.client;
343
344 let local_uri_str = format!(
345 "{}/api/v2/integration/aws/generate_new_external_id",
346 local_configuration.get_operation_host(operation_id)
347 );
348 let mut local_req_builder =
349 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
350
351 let mut headers = HeaderMap::new();
353 headers.insert("Accept", HeaderValue::from_static("application/json"));
354
355 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
357 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
358 Err(e) => {
359 log::warn!("Failed to parse user agent header: {e}, falling back to default");
360 headers.insert(
361 reqwest::header::USER_AGENT,
362 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
363 )
364 }
365 };
366
367 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
369 headers.insert(
370 "DD-API-KEY",
371 HeaderValue::from_str(local_key.key.as_str())
372 .expect("failed to parse DD-API-KEY header"),
373 );
374 };
375 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
376 headers.insert(
377 "DD-APPLICATION-KEY",
378 HeaderValue::from_str(local_key.key.as_str())
379 .expect("failed to parse DD-APPLICATION-KEY header"),
380 );
381 };
382
383 local_req_builder = local_req_builder.headers(headers);
384 let local_req = local_req_builder.build()?;
385 log::debug!("request content: {:?}", local_req.body());
386 let local_resp = local_client.execute(local_req).await?;
387
388 let local_status = local_resp.status();
389 let local_content = local_resp.text().await?;
390 log::debug!("response content: {}", local_content);
391
392 if !local_status.is_client_error() && !local_status.is_server_error() {
393 match serde_json::from_str::<crate::datadogV2::model::AWSNewExternalIDResponse>(
394 &local_content,
395 ) {
396 Ok(e) => {
397 return Ok(datadog::ResponseContent {
398 status: local_status,
399 content: local_content,
400 entity: Some(e),
401 })
402 }
403 Err(e) => return Err(datadog::Error::Serde(e)),
404 };
405 } else {
406 let local_entity: Option<CreateNewAWSExternalIDError> =
407 serde_json::from_str(&local_content).ok();
408 let local_error = datadog::ResponseContent {
409 status: local_status,
410 content: local_content,
411 entity: local_entity,
412 };
413 Err(datadog::Error::ResponseError(local_error))
414 }
415 }
416
417 pub async fn delete_aws_account(
419 &self,
420 aws_account_config_id: String,
421 ) -> Result<(), datadog::Error<DeleteAWSAccountError>> {
422 match self
423 .delete_aws_account_with_http_info(aws_account_config_id)
424 .await
425 {
426 Ok(_) => Ok(()),
427 Err(err) => Err(err),
428 }
429 }
430
431 pub async fn delete_aws_account_with_http_info(
433 &self,
434 aws_account_config_id: String,
435 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteAWSAccountError>> {
436 let local_configuration = &self.config;
437 let operation_id = "v2.delete_aws_account";
438
439 let local_client = &self.client;
440
441 let local_uri_str = format!(
442 "{}/api/v2/integration/aws/accounts/{aws_account_config_id}",
443 local_configuration.get_operation_host(operation_id),
444 aws_account_config_id = datadog::urlencode(aws_account_config_id)
445 );
446 let mut local_req_builder =
447 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
448
449 let mut headers = HeaderMap::new();
451 headers.insert("Accept", HeaderValue::from_static("*/*"));
452
453 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
455 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
456 Err(e) => {
457 log::warn!("Failed to parse user agent header: {e}, falling back to default");
458 headers.insert(
459 reqwest::header::USER_AGENT,
460 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
461 )
462 }
463 };
464
465 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
467 headers.insert(
468 "DD-API-KEY",
469 HeaderValue::from_str(local_key.key.as_str())
470 .expect("failed to parse DD-API-KEY header"),
471 );
472 };
473 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
474 headers.insert(
475 "DD-APPLICATION-KEY",
476 HeaderValue::from_str(local_key.key.as_str())
477 .expect("failed to parse DD-APPLICATION-KEY header"),
478 );
479 };
480
481 local_req_builder = local_req_builder.headers(headers);
482 let local_req = local_req_builder.build()?;
483 log::debug!("request content: {:?}", local_req.body());
484 let local_resp = local_client.execute(local_req).await?;
485
486 let local_status = local_resp.status();
487 let local_content = local_resp.text().await?;
488 log::debug!("response content: {}", local_content);
489
490 if !local_status.is_client_error() && !local_status.is_server_error() {
491 Ok(datadog::ResponseContent {
492 status: local_status,
493 content: local_content,
494 entity: None,
495 })
496 } else {
497 let local_entity: Option<DeleteAWSAccountError> =
498 serde_json::from_str(&local_content).ok();
499 let local_error = datadog::ResponseContent {
500 status: local_status,
501 content: local_content,
502 entity: local_entity,
503 };
504 Err(datadog::Error::ResponseError(local_error))
505 }
506 }
507
508 pub async fn get_aws_account(
510 &self,
511 aws_account_config_id: String,
512 ) -> Result<crate::datadogV2::model::AWSAccountResponse, datadog::Error<GetAWSAccountError>>
513 {
514 match self
515 .get_aws_account_with_http_info(aws_account_config_id)
516 .await
517 {
518 Ok(response_content) => {
519 if let Some(e) = response_content.entity {
520 Ok(e)
521 } else {
522 Err(datadog::Error::Serde(serde::de::Error::custom(
523 "response content was None",
524 )))
525 }
526 }
527 Err(err) => Err(err),
528 }
529 }
530
531 pub async fn get_aws_account_with_http_info(
533 &self,
534 aws_account_config_id: String,
535 ) -> Result<
536 datadog::ResponseContent<crate::datadogV2::model::AWSAccountResponse>,
537 datadog::Error<GetAWSAccountError>,
538 > {
539 let local_configuration = &self.config;
540 let operation_id = "v2.get_aws_account";
541
542 let local_client = &self.client;
543
544 let local_uri_str = format!(
545 "{}/api/v2/integration/aws/accounts/{aws_account_config_id}",
546 local_configuration.get_operation_host(operation_id),
547 aws_account_config_id = datadog::urlencode(aws_account_config_id)
548 );
549 let mut local_req_builder =
550 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
551
552 let mut headers = HeaderMap::new();
554 headers.insert("Accept", HeaderValue::from_static("application/json"));
555
556 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
558 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
559 Err(e) => {
560 log::warn!("Failed to parse user agent header: {e}, falling back to default");
561 headers.insert(
562 reqwest::header::USER_AGENT,
563 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
564 )
565 }
566 };
567
568 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
570 headers.insert(
571 "DD-API-KEY",
572 HeaderValue::from_str(local_key.key.as_str())
573 .expect("failed to parse DD-API-KEY header"),
574 );
575 };
576 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
577 headers.insert(
578 "DD-APPLICATION-KEY",
579 HeaderValue::from_str(local_key.key.as_str())
580 .expect("failed to parse DD-APPLICATION-KEY header"),
581 );
582 };
583
584 local_req_builder = local_req_builder.headers(headers);
585 let local_req = local_req_builder.build()?;
586 log::debug!("request content: {:?}", local_req.body());
587 let local_resp = local_client.execute(local_req).await?;
588
589 let local_status = local_resp.status();
590 let local_content = local_resp.text().await?;
591 log::debug!("response content: {}", local_content);
592
593 if !local_status.is_client_error() && !local_status.is_server_error() {
594 match serde_json::from_str::<crate::datadogV2::model::AWSAccountResponse>(
595 &local_content,
596 ) {
597 Ok(e) => {
598 return Ok(datadog::ResponseContent {
599 status: local_status,
600 content: local_content,
601 entity: Some(e),
602 })
603 }
604 Err(e) => return Err(datadog::Error::Serde(e)),
605 };
606 } else {
607 let local_entity: Option<GetAWSAccountError> =
608 serde_json::from_str(&local_content).ok();
609 let local_error = datadog::ResponseContent {
610 status: local_status,
611 content: local_content,
612 entity: local_entity,
613 };
614 Err(datadog::Error::ResponseError(local_error))
615 }
616 }
617
618 pub async fn get_aws_integration_iam_permissions(
620 &self,
621 ) -> Result<
622 crate::datadogV2::model::AWSIntegrationIamPermissionsResponse,
623 datadog::Error<GetAWSIntegrationIAMPermissionsError>,
624 > {
625 match self
626 .get_aws_integration_iam_permissions_with_http_info()
627 .await
628 {
629 Ok(response_content) => {
630 if let Some(e) = response_content.entity {
631 Ok(e)
632 } else {
633 Err(datadog::Error::Serde(serde::de::Error::custom(
634 "response content was None",
635 )))
636 }
637 }
638 Err(err) => Err(err),
639 }
640 }
641
642 pub async fn get_aws_integration_iam_permissions_with_http_info(
644 &self,
645 ) -> Result<
646 datadog::ResponseContent<crate::datadogV2::model::AWSIntegrationIamPermissionsResponse>,
647 datadog::Error<GetAWSIntegrationIAMPermissionsError>,
648 > {
649 let local_configuration = &self.config;
650 let operation_id = "v2.get_aws_integration_iam_permissions";
651
652 let local_client = &self.client;
653
654 let local_uri_str = format!(
655 "{}/api/v2/integration/aws/iam_permissions",
656 local_configuration.get_operation_host(operation_id)
657 );
658 let mut local_req_builder =
659 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
660
661 let mut headers = HeaderMap::new();
663 headers.insert("Accept", HeaderValue::from_static("application/json"));
664
665 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
667 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
668 Err(e) => {
669 log::warn!("Failed to parse user agent header: {e}, falling back to default");
670 headers.insert(
671 reqwest::header::USER_AGENT,
672 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
673 )
674 }
675 };
676
677 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
679 headers.insert(
680 "DD-API-KEY",
681 HeaderValue::from_str(local_key.key.as_str())
682 .expect("failed to parse DD-API-KEY header"),
683 );
684 };
685 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
686 headers.insert(
687 "DD-APPLICATION-KEY",
688 HeaderValue::from_str(local_key.key.as_str())
689 .expect("failed to parse DD-APPLICATION-KEY header"),
690 );
691 };
692
693 local_req_builder = local_req_builder.headers(headers);
694 let local_req = local_req_builder.build()?;
695 log::debug!("request content: {:?}", local_req.body());
696 let local_resp = local_client.execute(local_req).await?;
697
698 let local_status = local_resp.status();
699 let local_content = local_resp.text().await?;
700 log::debug!("response content: {}", local_content);
701
702 if !local_status.is_client_error() && !local_status.is_server_error() {
703 match serde_json::from_str::<
704 crate::datadogV2::model::AWSIntegrationIamPermissionsResponse,
705 >(&local_content)
706 {
707 Ok(e) => {
708 return Ok(datadog::ResponseContent {
709 status: local_status,
710 content: local_content,
711 entity: Some(e),
712 })
713 }
714 Err(e) => return Err(datadog::Error::Serde(e)),
715 };
716 } else {
717 let local_entity: Option<GetAWSIntegrationIAMPermissionsError> =
718 serde_json::from_str(&local_content).ok();
719 let local_error = datadog::ResponseContent {
720 status: local_status,
721 content: local_content,
722 entity: local_entity,
723 };
724 Err(datadog::Error::ResponseError(local_error))
725 }
726 }
727
728 pub async fn list_aws_accounts(
730 &self,
731 params: ListAWSAccountsOptionalParams,
732 ) -> Result<crate::datadogV2::model::AWSAccountsResponse, datadog::Error<ListAWSAccountsError>>
733 {
734 match self.list_aws_accounts_with_http_info(params).await {
735 Ok(response_content) => {
736 if let Some(e) = response_content.entity {
737 Ok(e)
738 } else {
739 Err(datadog::Error::Serde(serde::de::Error::custom(
740 "response content was None",
741 )))
742 }
743 }
744 Err(err) => Err(err),
745 }
746 }
747
748 pub async fn list_aws_accounts_with_http_info(
750 &self,
751 params: ListAWSAccountsOptionalParams,
752 ) -> Result<
753 datadog::ResponseContent<crate::datadogV2::model::AWSAccountsResponse>,
754 datadog::Error<ListAWSAccountsError>,
755 > {
756 let local_configuration = &self.config;
757 let operation_id = "v2.list_aws_accounts";
758
759 let aws_account_id = params.aws_account_id;
761
762 let local_client = &self.client;
763
764 let local_uri_str = format!(
765 "{}/api/v2/integration/aws/accounts",
766 local_configuration.get_operation_host(operation_id)
767 );
768 let mut local_req_builder =
769 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
770
771 if let Some(ref local_query_param) = aws_account_id {
772 local_req_builder =
773 local_req_builder.query(&[("aws_account_id", &local_query_param.to_string())]);
774 };
775
776 let mut headers = HeaderMap::new();
778 headers.insert("Accept", HeaderValue::from_static("application/json"));
779
780 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
782 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
783 Err(e) => {
784 log::warn!("Failed to parse user agent header: {e}, falling back to default");
785 headers.insert(
786 reqwest::header::USER_AGENT,
787 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
788 )
789 }
790 };
791
792 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
794 headers.insert(
795 "DD-API-KEY",
796 HeaderValue::from_str(local_key.key.as_str())
797 .expect("failed to parse DD-API-KEY header"),
798 );
799 };
800 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
801 headers.insert(
802 "DD-APPLICATION-KEY",
803 HeaderValue::from_str(local_key.key.as_str())
804 .expect("failed to parse DD-APPLICATION-KEY header"),
805 );
806 };
807
808 local_req_builder = local_req_builder.headers(headers);
809 let local_req = local_req_builder.build()?;
810 log::debug!("request content: {:?}", local_req.body());
811 let local_resp = local_client.execute(local_req).await?;
812
813 let local_status = local_resp.status();
814 let local_content = local_resp.text().await?;
815 log::debug!("response content: {}", local_content);
816
817 if !local_status.is_client_error() && !local_status.is_server_error() {
818 match serde_json::from_str::<crate::datadogV2::model::AWSAccountsResponse>(
819 &local_content,
820 ) {
821 Ok(e) => {
822 return Ok(datadog::ResponseContent {
823 status: local_status,
824 content: local_content,
825 entity: Some(e),
826 })
827 }
828 Err(e) => return Err(datadog::Error::Serde(e)),
829 };
830 } else {
831 let local_entity: Option<ListAWSAccountsError> =
832 serde_json::from_str(&local_content).ok();
833 let local_error = datadog::ResponseContent {
834 status: local_status,
835 content: local_content,
836 entity: local_entity,
837 };
838 Err(datadog::Error::ResponseError(local_error))
839 }
840 }
841
842 pub async fn list_aws_namespaces(
844 &self,
845 ) -> Result<
846 crate::datadogV2::model::AWSNamespacesResponse,
847 datadog::Error<ListAWSNamespacesError>,
848 > {
849 match self.list_aws_namespaces_with_http_info().await {
850 Ok(response_content) => {
851 if let Some(e) = response_content.entity {
852 Ok(e)
853 } else {
854 Err(datadog::Error::Serde(serde::de::Error::custom(
855 "response content was None",
856 )))
857 }
858 }
859 Err(err) => Err(err),
860 }
861 }
862
863 pub async fn list_aws_namespaces_with_http_info(
865 &self,
866 ) -> Result<
867 datadog::ResponseContent<crate::datadogV2::model::AWSNamespacesResponse>,
868 datadog::Error<ListAWSNamespacesError>,
869 > {
870 let local_configuration = &self.config;
871 let operation_id = "v2.list_aws_namespaces";
872
873 let local_client = &self.client;
874
875 let local_uri_str = format!(
876 "{}/api/v2/integration/aws/available_namespaces",
877 local_configuration.get_operation_host(operation_id)
878 );
879 let mut local_req_builder =
880 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
881
882 let mut headers = HeaderMap::new();
884 headers.insert("Accept", HeaderValue::from_static("application/json"));
885
886 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
888 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
889 Err(e) => {
890 log::warn!("Failed to parse user agent header: {e}, falling back to default");
891 headers.insert(
892 reqwest::header::USER_AGENT,
893 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
894 )
895 }
896 };
897
898 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
900 headers.insert(
901 "DD-API-KEY",
902 HeaderValue::from_str(local_key.key.as_str())
903 .expect("failed to parse DD-API-KEY header"),
904 );
905 };
906 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
907 headers.insert(
908 "DD-APPLICATION-KEY",
909 HeaderValue::from_str(local_key.key.as_str())
910 .expect("failed to parse DD-APPLICATION-KEY header"),
911 );
912 };
913
914 local_req_builder = local_req_builder.headers(headers);
915 let local_req = local_req_builder.build()?;
916 log::debug!("request content: {:?}", local_req.body());
917 let local_resp = local_client.execute(local_req).await?;
918
919 let local_status = local_resp.status();
920 let local_content = local_resp.text().await?;
921 log::debug!("response content: {}", local_content);
922
923 if !local_status.is_client_error() && !local_status.is_server_error() {
924 match serde_json::from_str::<crate::datadogV2::model::AWSNamespacesResponse>(
925 &local_content,
926 ) {
927 Ok(e) => {
928 return Ok(datadog::ResponseContent {
929 status: local_status,
930 content: local_content,
931 entity: Some(e),
932 })
933 }
934 Err(e) => return Err(datadog::Error::Serde(e)),
935 };
936 } else {
937 let local_entity: Option<ListAWSNamespacesError> =
938 serde_json::from_str(&local_content).ok();
939 let local_error = datadog::ResponseContent {
940 status: local_status,
941 content: local_content,
942 entity: local_entity,
943 };
944 Err(datadog::Error::ResponseError(local_error))
945 }
946 }
947
948 pub async fn update_aws_account(
950 &self,
951 aws_account_config_id: String,
952 body: crate::datadogV2::model::AWSAccountUpdateRequest,
953 ) -> Result<crate::datadogV2::model::AWSAccountResponse, datadog::Error<UpdateAWSAccountError>>
954 {
955 match self
956 .update_aws_account_with_http_info(aws_account_config_id, body)
957 .await
958 {
959 Ok(response_content) => {
960 if let Some(e) = response_content.entity {
961 Ok(e)
962 } else {
963 Err(datadog::Error::Serde(serde::de::Error::custom(
964 "response content was None",
965 )))
966 }
967 }
968 Err(err) => Err(err),
969 }
970 }
971
972 pub async fn update_aws_account_with_http_info(
974 &self,
975 aws_account_config_id: String,
976 body: crate::datadogV2::model::AWSAccountUpdateRequest,
977 ) -> Result<
978 datadog::ResponseContent<crate::datadogV2::model::AWSAccountResponse>,
979 datadog::Error<UpdateAWSAccountError>,
980 > {
981 let local_configuration = &self.config;
982 let operation_id = "v2.update_aws_account";
983
984 let local_client = &self.client;
985
986 let local_uri_str = format!(
987 "{}/api/v2/integration/aws/accounts/{aws_account_config_id}",
988 local_configuration.get_operation_host(operation_id),
989 aws_account_config_id = datadog::urlencode(aws_account_config_id)
990 );
991 let mut local_req_builder =
992 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
993
994 let mut headers = HeaderMap::new();
996 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
997 headers.insert("Accept", HeaderValue::from_static("application/json"));
998
999 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1001 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1002 Err(e) => {
1003 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1004 headers.insert(
1005 reqwest::header::USER_AGENT,
1006 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1007 )
1008 }
1009 };
1010
1011 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1013 headers.insert(
1014 "DD-API-KEY",
1015 HeaderValue::from_str(local_key.key.as_str())
1016 .expect("failed to parse DD-API-KEY header"),
1017 );
1018 };
1019 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1020 headers.insert(
1021 "DD-APPLICATION-KEY",
1022 HeaderValue::from_str(local_key.key.as_str())
1023 .expect("failed to parse DD-APPLICATION-KEY header"),
1024 );
1025 };
1026
1027 let output = Vec::new();
1029 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1030 if body.serialize(&mut ser).is_ok() {
1031 if let Some(content_encoding) = headers.get("Content-Encoding") {
1032 match content_encoding.to_str().unwrap_or_default() {
1033 "gzip" => {
1034 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1035 let _ = enc.write_all(ser.into_inner().as_slice());
1036 match enc.finish() {
1037 Ok(buf) => {
1038 local_req_builder = local_req_builder.body(buf);
1039 }
1040 Err(e) => return Err(datadog::Error::Io(e)),
1041 }
1042 }
1043 "deflate" => {
1044 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1045 let _ = enc.write_all(ser.into_inner().as_slice());
1046 match enc.finish() {
1047 Ok(buf) => {
1048 local_req_builder = local_req_builder.body(buf);
1049 }
1050 Err(e) => return Err(datadog::Error::Io(e)),
1051 }
1052 }
1053 "zstd1" => {
1054 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1055 let _ = enc.write_all(ser.into_inner().as_slice());
1056 match enc.finish() {
1057 Ok(buf) => {
1058 local_req_builder = local_req_builder.body(buf);
1059 }
1060 Err(e) => return Err(datadog::Error::Io(e)),
1061 }
1062 }
1063 _ => {
1064 local_req_builder = local_req_builder.body(ser.into_inner());
1065 }
1066 }
1067 } else {
1068 local_req_builder = local_req_builder.body(ser.into_inner());
1069 }
1070 }
1071
1072 local_req_builder = local_req_builder.headers(headers);
1073 let local_req = local_req_builder.build()?;
1074 log::debug!("request content: {:?}", local_req.body());
1075 let local_resp = local_client.execute(local_req).await?;
1076
1077 let local_status = local_resp.status();
1078 let local_content = local_resp.text().await?;
1079 log::debug!("response content: {}", local_content);
1080
1081 if !local_status.is_client_error() && !local_status.is_server_error() {
1082 match serde_json::from_str::<crate::datadogV2::model::AWSAccountResponse>(
1083 &local_content,
1084 ) {
1085 Ok(e) => {
1086 return Ok(datadog::ResponseContent {
1087 status: local_status,
1088 content: local_content,
1089 entity: Some(e),
1090 })
1091 }
1092 Err(e) => return Err(datadog::Error::Serde(e)),
1093 };
1094 } else {
1095 let local_entity: Option<UpdateAWSAccountError> =
1096 serde_json::from_str(&local_content).ok();
1097 let local_error = datadog::ResponseContent {
1098 status: local_status,
1099 content: local_content,
1100 entity: local_entity,
1101 };
1102 Err(datadog::Error::ResponseError(local_error))
1103 }
1104 }
1105}