use crate::datadog;
use flate2::{
write::{GzEncoder, ZlibEncoder},
Compression,
};
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
use std::io::Write;
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListAWSAccountsOptionalParams {
pub account_id: Option<String>,
pub role_name: Option<String>,
pub access_key_id: Option<String>,
}
impl ListAWSAccountsOptionalParams {
pub fn account_id(mut self, value: String) -> Self {
self.account_id = Some(value);
self
}
pub fn role_name(mut self, value: String) -> Self {
self.role_name = Some(value);
self
}
pub fn access_key_id(mut self, value: String) -> Self {
self.access_key_id = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct UpdateAWSAccountOptionalParams {
pub account_id: Option<String>,
pub role_name: Option<String>,
pub access_key_id: Option<String>,
}
impl UpdateAWSAccountOptionalParams {
pub fn account_id(mut self, value: String) -> Self {
self.account_id = Some(value);
self
}
pub fn role_name(mut self, value: String) -> Self {
self.role_name = Some(value);
self
}
pub fn access_key_id(mut self, value: String) -> Self {
self.access_key_id = Some(value);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAWSAccountError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAWSEventBridgeSourceError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAWSTagFilterError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateNewAWSExternalIDError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAWSAccountError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAWSEventBridgeSourceError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAWSTagFilterError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAWSAccountsError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAWSEventBridgeSourcesError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAWSTagFiltersError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAvailableAWSNamespacesError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateAWSAccountError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone)]
pub struct AWSIntegrationAPI {
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
}
impl Default for AWSIntegrationAPI {
fn default() -> Self {
Self::with_config(datadog::Configuration::default())
}
}
impl AWSIntegrationAPI {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(config: datadog::Configuration) -> Self {
let mut reqwest_client_builder = reqwest::Client::builder();
if let Some(proxy_url) = &config.proxy_url {
let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}
let mut middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
if config.enable_retry {
struct RetryableStatus;
impl reqwest_retry::RetryableStrategy for RetryableStatus {
fn handle(
&self,
res: &Result<reqwest::Response, reqwest_middleware::Error>,
) -> Option<reqwest_retry::Retryable> {
match res {
Ok(success) => reqwest_retry::default_on_request_success(success),
Err(_) => None,
}
}
}
let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
.build_with_max_retries(config.max_retries);
let retry_middleware =
reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
backoff_policy,
RetryableStatus,
);
middleware_client_builder = middleware_client_builder.with(retry_middleware);
}
let client = middleware_client_builder.build();
Self { config, client }
}
pub fn with_client_and_config(
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
) -> Self {
Self { config, client }
}
pub async fn create_aws_account(
&self,
body: crate::datadogV1::model::AWSAccount,
) -> Result<
crate::datadogV1::model::AWSAccountCreateResponse,
datadog::Error<CreateAWSAccountError>,
> {
match self.create_aws_account_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_aws_account_with_http_info(
&self,
body: crate::datadogV1::model::AWSAccount,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSAccountCreateResponse>,
datadog::Error<CreateAWSAccountError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.create_aws_account";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSAccountCreateResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateAWSAccountError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn create_aws_event_bridge_source(
&self,
body: crate::datadogV1::model::AWSEventBridgeCreateRequest,
) -> Result<
crate::datadogV1::model::AWSEventBridgeCreateResponse,
datadog::Error<CreateAWSEventBridgeSourceError>,
> {
match self
.create_aws_event_bridge_source_with_http_info(body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_aws_event_bridge_source_with_http_info(
&self,
body: crate::datadogV1::model::AWSEventBridgeCreateRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSEventBridgeCreateResponse>,
datadog::Error<CreateAWSEventBridgeSourceError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.create_aws_event_bridge_source";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/event_bridge",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSEventBridgeCreateResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateAWSEventBridgeSourceError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn create_aws_tag_filter(
&self,
body: crate::datadogV1::model::AWSTagFilterCreateRequest,
) -> Result<
std::collections::BTreeMap<String, serde_json::Value>,
datadog::Error<CreateAWSTagFilterError>,
> {
match self.create_aws_tag_filter_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_aws_tag_filter_with_http_info(
&self,
body: crate::datadogV1::model::AWSTagFilterCreateRequest,
) -> Result<
datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
datadog::Error<CreateAWSTagFilterError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.create_aws_tag_filter";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/filtering",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateAWSTagFilterError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn create_new_aws_external_id(
&self,
body: crate::datadogV1::model::AWSAccount,
) -> Result<
crate::datadogV1::model::AWSAccountCreateResponse,
datadog::Error<CreateNewAWSExternalIDError>,
> {
match self.create_new_aws_external_id_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_new_aws_external_id_with_http_info(
&self,
body: crate::datadogV1::model::AWSAccount,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSAccountCreateResponse>,
datadog::Error<CreateNewAWSExternalIDError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.create_new_aws_external_id";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/generate_new_external_id",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSAccountCreateResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateNewAWSExternalIDError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn delete_aws_account(
&self,
body: crate::datadogV1::model::AWSAccountDeleteRequest,
) -> Result<
std::collections::BTreeMap<String, serde_json::Value>,
datadog::Error<DeleteAWSAccountError>,
> {
match self.delete_aws_account_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn delete_aws_account_with_http_info(
&self,
body: crate::datadogV1::model::AWSAccountDeleteRequest,
) -> Result<
datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
datadog::Error<DeleteAWSAccountError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.delete_aws_account";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<DeleteAWSAccountError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn delete_aws_event_bridge_source(
&self,
body: crate::datadogV1::model::AWSEventBridgeDeleteRequest,
) -> Result<
crate::datadogV1::model::AWSEventBridgeDeleteResponse,
datadog::Error<DeleteAWSEventBridgeSourceError>,
> {
match self
.delete_aws_event_bridge_source_with_http_info(body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn delete_aws_event_bridge_source_with_http_info(
&self,
body: crate::datadogV1::model::AWSEventBridgeDeleteRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSEventBridgeDeleteResponse>,
datadog::Error<DeleteAWSEventBridgeSourceError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.delete_aws_event_bridge_source";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/event_bridge",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSEventBridgeDeleteResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<DeleteAWSEventBridgeSourceError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn delete_aws_tag_filter(
&self,
body: crate::datadogV1::model::AWSTagFilterDeleteRequest,
) -> Result<
std::collections::BTreeMap<String, serde_json::Value>,
datadog::Error<DeleteAWSTagFilterError>,
> {
match self.delete_aws_tag_filter_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn delete_aws_tag_filter_with_http_info(
&self,
body: crate::datadogV1::model::AWSTagFilterDeleteRequest,
) -> Result<
datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
datadog::Error<DeleteAWSTagFilterError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.delete_aws_tag_filter";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/filtering",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<DeleteAWSTagFilterError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_aws_accounts(
&self,
params: ListAWSAccountsOptionalParams,
) -> Result<crate::datadogV1::model::AWSAccountListResponse, datadog::Error<ListAWSAccountsError>>
{
match self.list_aws_accounts_with_http_info(params).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_aws_accounts_with_http_info(
&self,
params: ListAWSAccountsOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSAccountListResponse>,
datadog::Error<ListAWSAccountsError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.list_aws_accounts";
let account_id = params.account_id;
let role_name = params.role_name;
let access_key_id = params.access_key_id;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = account_id {
local_req_builder =
local_req_builder.query(&[("account_id", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = role_name {
local_req_builder =
local_req_builder.query(&[("role_name", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = access_key_id {
local_req_builder =
local_req_builder.query(&[("access_key_id", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSAccountListResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListAWSAccountsError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_aws_event_bridge_sources(
&self,
) -> Result<
crate::datadogV1::model::AWSEventBridgeListResponse,
datadog::Error<ListAWSEventBridgeSourcesError>,
> {
match self.list_aws_event_bridge_sources_with_http_info().await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_aws_event_bridge_sources_with_http_info(
&self,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSEventBridgeListResponse>,
datadog::Error<ListAWSEventBridgeSourcesError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.list_aws_event_bridge_sources";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/event_bridge",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSEventBridgeListResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListAWSEventBridgeSourcesError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_aws_tag_filters(
&self,
account_id: String,
) -> Result<
crate::datadogV1::model::AWSTagFilterListResponse,
datadog::Error<ListAWSTagFiltersError>,
> {
match self.list_aws_tag_filters_with_http_info(account_id).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_aws_tag_filters_with_http_info(
&self,
account_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::AWSTagFilterListResponse>,
datadog::Error<ListAWSTagFiltersError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.list_aws_tag_filters";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/filtering",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
local_req_builder = local_req_builder.query(&[("account_id", &account_id.to_string())]);
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::AWSTagFilterListResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListAWSTagFiltersError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_available_aws_namespaces(
&self,
) -> Result<Vec<String>, datadog::Error<ListAvailableAWSNamespacesError>> {
match self.list_available_aws_namespaces_with_http_info().await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_available_aws_namespaces_with_http_info(
&self,
) -> Result<
datadog::ResponseContent<Vec<String>>,
datadog::Error<ListAvailableAWSNamespacesError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.list_available_aws_namespaces";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws/available_namespace_rules",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<Vec<String>>(&local_content) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListAvailableAWSNamespacesError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn update_aws_account(
&self,
body: crate::datadogV1::model::AWSAccount,
params: UpdateAWSAccountOptionalParams,
) -> Result<
std::collections::BTreeMap<String, serde_json::Value>,
datadog::Error<UpdateAWSAccountError>,
> {
match self.update_aws_account_with_http_info(body, params).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn update_aws_account_with_http_info(
&self,
body: crate::datadogV1::model::AWSAccount,
params: UpdateAWSAccountOptionalParams,
) -> Result<
datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
datadog::Error<UpdateAWSAccountError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.update_aws_account";
let account_id = params.account_id;
let role_name = params.role_name;
let access_key_id = params.access_key_id;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/integration/aws",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
if let Some(ref local_query_param) = account_id {
local_req_builder =
local_req_builder.query(&[("account_id", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = role_name {
local_req_builder =
local_req_builder.query(&[("role_name", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = access_key_id {
local_req_builder =
local_req_builder.query(&[("access_key_id", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<UpdateAWSAccountError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
}