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