use crate::datadog;
use log::warn;
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetCostByOrgOptionalParams {
pub end_month: Option<chrono::DateTime<chrono::Utc>>,
}
impl GetCostByOrgOptionalParams {
pub fn end_month(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_month = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetEstimatedCostByOrgOptionalParams {
pub view: Option<String>,
pub start_month: Option<chrono::DateTime<chrono::Utc>>,
pub end_month: Option<chrono::DateTime<chrono::Utc>>,
pub start_date: Option<chrono::DateTime<chrono::Utc>>,
pub end_date: Option<chrono::DateTime<chrono::Utc>>,
pub include_connected_accounts: Option<bool>,
}
impl GetEstimatedCostByOrgOptionalParams {
pub fn view(mut self, value: String) -> Self {
self.view = Some(value);
self
}
pub fn start_month(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.start_month = Some(value);
self
}
pub fn end_month(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_month = Some(value);
self
}
pub fn start_date(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.start_date = Some(value);
self
}
pub fn end_date(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_date = Some(value);
self
}
pub fn include_connected_accounts(mut self, value: bool) -> Self {
self.include_connected_accounts = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetHistoricalCostByOrgOptionalParams {
pub view: Option<String>,
pub end_month: Option<chrono::DateTime<chrono::Utc>>,
pub include_connected_accounts: Option<bool>,
}
impl GetHistoricalCostByOrgOptionalParams {
pub fn view(mut self, value: String) -> Self {
self.view = Some(value);
self
}
pub fn end_month(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_month = Some(value);
self
}
pub fn include_connected_accounts(mut self, value: bool) -> Self {
self.include_connected_accounts = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetHourlyUsageOptionalParams {
pub filter_timestamp_end: Option<chrono::DateTime<chrono::Utc>>,
pub filter_include_descendants: Option<bool>,
pub filter_include_connected_accounts: Option<bool>,
pub filter_include_breakdown: Option<bool>,
pub filter_versions: Option<String>,
pub page_limit: Option<i32>,
pub page_next_record_id: Option<String>,
}
impl GetHourlyUsageOptionalParams {
pub fn filter_timestamp_end(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.filter_timestamp_end = Some(value);
self
}
pub fn filter_include_descendants(mut self, value: bool) -> Self {
self.filter_include_descendants = Some(value);
self
}
pub fn filter_include_connected_accounts(mut self, value: bool) -> Self {
self.filter_include_connected_accounts = Some(value);
self
}
pub fn filter_include_breakdown(mut self, value: bool) -> Self {
self.filter_include_breakdown = Some(value);
self
}
pub fn filter_versions(mut self, value: String) -> Self {
self.filter_versions = Some(value);
self
}
pub fn page_limit(mut self, value: i32) -> Self {
self.page_limit = Some(value);
self
}
pub fn page_next_record_id(mut self, value: String) -> Self {
self.page_next_record_id = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetMonthlyCostAttributionOptionalParams {
pub sort_direction: Option<crate::datadogV2::model::SortDirection>,
pub sort_name: Option<String>,
pub tag_breakdown_keys: Option<String>,
pub next_record_id: Option<String>,
pub include_descendants: Option<bool>,
}
impl GetMonthlyCostAttributionOptionalParams {
pub fn sort_direction(mut self, value: crate::datadogV2::model::SortDirection) -> Self {
self.sort_direction = Some(value);
self
}
pub fn sort_name(mut self, value: String) -> Self {
self.sort_name = Some(value);
self
}
pub fn tag_breakdown_keys(mut self, value: String) -> Self {
self.tag_breakdown_keys = Some(value);
self
}
pub fn next_record_id(mut self, value: String) -> Self {
self.next_record_id = Some(value);
self
}
pub fn include_descendants(mut self, value: bool) -> Self {
self.include_descendants = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetProjectedCostOptionalParams {
pub view: Option<String>,
pub include_connected_accounts: Option<bool>,
}
impl GetProjectedCostOptionalParams {
pub fn view(mut self, value: String) -> Self {
self.view = Some(value);
self
}
pub fn include_connected_accounts(mut self, value: bool) -> Self {
self.include_connected_accounts = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetUsageApplicationSecurityMonitoringOptionalParams {
pub end_hr: Option<chrono::DateTime<chrono::Utc>>,
}
impl GetUsageApplicationSecurityMonitoringOptionalParams {
pub fn end_hr(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_hr = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetUsageLambdaTracedInvocationsOptionalParams {
pub end_hr: Option<chrono::DateTime<chrono::Utc>>,
}
impl GetUsageLambdaTracedInvocationsOptionalParams {
pub fn end_hr(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_hr = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetUsageObservabilityPipelinesOptionalParams {
pub end_hr: Option<chrono::DateTime<chrono::Utc>>,
}
impl GetUsageObservabilityPipelinesOptionalParams {
pub fn end_hr(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_hr = Some(value);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetActiveBillingDimensionsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCostByOrgError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetEstimatedCostByOrgError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetHistoricalCostByOrgError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetHourlyUsageError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMonthlyCostAttributionError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetProjectedCostError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUsageApplicationSecurityMonitoringError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUsageLambdaTracedInvocationsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUsageObservabilityPipelinesError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone)]
pub struct UsageMeteringAPI {
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
}
impl Default for UsageMeteringAPI {
fn default() -> Self {
Self::with_config(datadog::Configuration::default())
}
}
impl UsageMeteringAPI {
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 get_active_billing_dimensions(
&self,
) -> Result<
crate::datadogV2::model::ActiveBillingDimensionsResponse,
datadog::Error<GetActiveBillingDimensionsError>,
> {
match self.get_active_billing_dimensions_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 get_active_billing_dimensions_with_http_info(
&self,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::ActiveBillingDimensionsResponse>,
datadog::Error<GetActiveBillingDimensionsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_active_billing_dimensions";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.get_active_billing_dimensions' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/cost_by_tag/active_billing_dimensions",
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;datetime-format=rfc3339"),
);
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::datadogV2::model::ActiveBillingDimensionsResponse>(
&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<GetActiveBillingDimensionsError> =
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 get_cost_by_org(
&self,
start_month: chrono::DateTime<chrono::Utc>,
params: GetCostByOrgOptionalParams,
) -> Result<crate::datadogV2::model::CostByOrgResponse, datadog::Error<GetCostByOrgError>> {
match self
.get_cost_by_org_with_http_info(start_month, 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 get_cost_by_org_with_http_info(
&self,
start_month: chrono::DateTime<chrono::Utc>,
params: GetCostByOrgOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::CostByOrgResponse>,
datadog::Error<GetCostByOrgError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_cost_by_org";
let end_month = params.end_month;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/cost_by_org",
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(&[(
"start_month",
&start_month.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
if let Some(ref local_query_param) = end_month {
local_req_builder = local_req_builder.query(&[(
"end_month",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::CostByOrgResponse>(&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<GetCostByOrgError> = 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 get_estimated_cost_by_org(
&self,
params: GetEstimatedCostByOrgOptionalParams,
) -> Result<
crate::datadogV2::model::CostByOrgResponse,
datadog::Error<GetEstimatedCostByOrgError>,
> {
match self.get_estimated_cost_by_org_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 get_estimated_cost_by_org_with_http_info(
&self,
params: GetEstimatedCostByOrgOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::CostByOrgResponse>,
datadog::Error<GetEstimatedCostByOrgError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_estimated_cost_by_org";
let view = params.view;
let start_month = params.start_month;
let end_month = params.end_month;
let start_date = params.start_date;
let end_date = params.end_date;
let include_connected_accounts = params.include_connected_accounts;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/estimated_cost",
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) = view {
local_req_builder =
local_req_builder.query(&[("view", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = start_month {
local_req_builder = local_req_builder.query(&[(
"start_month",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = end_month {
local_req_builder = local_req_builder.query(&[(
"end_month",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = start_date {
local_req_builder = local_req_builder.query(&[(
"start_date",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = end_date {
local_req_builder = local_req_builder.query(&[(
"end_date",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = include_connected_accounts {
local_req_builder = local_req_builder
.query(&[("include_connected_accounts", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::CostByOrgResponse>(&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<GetEstimatedCostByOrgError> =
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 get_historical_cost_by_org(
&self,
start_month: chrono::DateTime<chrono::Utc>,
params: GetHistoricalCostByOrgOptionalParams,
) -> Result<
crate::datadogV2::model::CostByOrgResponse,
datadog::Error<GetHistoricalCostByOrgError>,
> {
match self
.get_historical_cost_by_org_with_http_info(start_month, 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 get_historical_cost_by_org_with_http_info(
&self,
start_month: chrono::DateTime<chrono::Utc>,
params: GetHistoricalCostByOrgOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::CostByOrgResponse>,
datadog::Error<GetHistoricalCostByOrgError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_historical_cost_by_org";
let view = params.view;
let end_month = params.end_month;
let include_connected_accounts = params.include_connected_accounts;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/historical_cost",
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(&[(
"start_month",
&start_month.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
if let Some(ref local_query_param) = view {
local_req_builder =
local_req_builder.query(&[("view", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = end_month {
local_req_builder = local_req_builder.query(&[(
"end_month",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = include_connected_accounts {
local_req_builder = local_req_builder
.query(&[("include_connected_accounts", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::CostByOrgResponse>(&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<GetHistoricalCostByOrgError> =
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 get_hourly_usage(
&self,
filter_timestamp_start: chrono::DateTime<chrono::Utc>,
filter_product_families: String,
params: GetHourlyUsageOptionalParams,
) -> Result<crate::datadogV2::model::HourlyUsageResponse, datadog::Error<GetHourlyUsageError>>
{
match self
.get_hourly_usage_with_http_info(
filter_timestamp_start,
filter_product_families,
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 get_hourly_usage_with_http_info(
&self,
filter_timestamp_start: chrono::DateTime<chrono::Utc>,
filter_product_families: String,
params: GetHourlyUsageOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::HourlyUsageResponse>,
datadog::Error<GetHourlyUsageError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_hourly_usage";
let filter_timestamp_end = params.filter_timestamp_end;
let filter_include_descendants = params.filter_include_descendants;
let filter_include_connected_accounts = params.filter_include_connected_accounts;
let filter_include_breakdown = params.filter_include_breakdown;
let filter_versions = params.filter_versions;
let page_limit = params.page_limit;
let page_next_record_id = params.page_next_record_id;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/hourly_usage",
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(&[(
"filter[timestamp][start]",
&filter_timestamp_start.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
local_req_builder = local_req_builder.query(&[(
"filter[product_families]",
&filter_product_families.to_string(),
)]);
if let Some(ref local_query_param) = filter_timestamp_end {
local_req_builder = local_req_builder.query(&[(
"filter[timestamp][end]",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = filter_include_descendants {
local_req_builder = local_req_builder.query(&[(
"filter[include_descendants]",
&local_query_param.to_string(),
)]);
};
if let Some(ref local_query_param) = filter_include_connected_accounts {
local_req_builder = local_req_builder.query(&[(
"filter[include_connected_accounts]",
&local_query_param.to_string(),
)]);
};
if let Some(ref local_query_param) = filter_include_breakdown {
local_req_builder = local_req_builder
.query(&[("filter[include_breakdown]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_versions {
local_req_builder =
local_req_builder.query(&[("filter[versions]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page_limit {
local_req_builder =
local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page_next_record_id {
local_req_builder = local_req_builder
.query(&[("page[next_record_id]", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::HourlyUsageResponse>(
&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<GetHourlyUsageError> =
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 get_monthly_cost_attribution(
&self,
start_month: chrono::DateTime<chrono::Utc>,
end_month: chrono::DateTime<chrono::Utc>,
fields: String,
params: GetMonthlyCostAttributionOptionalParams,
) -> Result<
crate::datadogV2::model::MonthlyCostAttributionResponse,
datadog::Error<GetMonthlyCostAttributionError>,
> {
match self
.get_monthly_cost_attribution_with_http_info(start_month, end_month, fields, 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 get_monthly_cost_attribution_with_http_info(
&self,
start_month: chrono::DateTime<chrono::Utc>,
end_month: chrono::DateTime<chrono::Utc>,
fields: String,
params: GetMonthlyCostAttributionOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::MonthlyCostAttributionResponse>,
datadog::Error<GetMonthlyCostAttributionError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_monthly_cost_attribution";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.get_monthly_cost_attribution' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}
let sort_direction = params.sort_direction;
let sort_name = params.sort_name;
let tag_breakdown_keys = params.tag_breakdown_keys;
let next_record_id = params.next_record_id;
let include_descendants = params.include_descendants;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/cost_by_tag/monthly_cost_attribution",
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(&[(
"start_month",
&start_month.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
local_req_builder = local_req_builder.query(&[(
"end_month",
&end_month.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
local_req_builder = local_req_builder.query(&[("fields", &fields.to_string())]);
if let Some(ref local_query_param) = sort_direction {
local_req_builder =
local_req_builder.query(&[("sort_direction", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = sort_name {
local_req_builder =
local_req_builder.query(&[("sort_name", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = tag_breakdown_keys {
local_req_builder =
local_req_builder.query(&[("tag_breakdown_keys", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = next_record_id {
local_req_builder =
local_req_builder.query(&[("next_record_id", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = include_descendants {
local_req_builder =
local_req_builder.query(&[("include_descendants", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::MonthlyCostAttributionResponse>(
&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<GetMonthlyCostAttributionError> =
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 get_projected_cost(
&self,
params: GetProjectedCostOptionalParams,
) -> Result<crate::datadogV2::model::ProjectedCostResponse, datadog::Error<GetProjectedCostError>>
{
match self.get_projected_cost_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 get_projected_cost_with_http_info(
&self,
params: GetProjectedCostOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::ProjectedCostResponse>,
datadog::Error<GetProjectedCostError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_projected_cost";
let view = params.view;
let include_connected_accounts = params.include_connected_accounts;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/projected_cost",
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) = view {
local_req_builder =
local_req_builder.query(&[("view", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = include_connected_accounts {
local_req_builder = local_req_builder
.query(&[("include_connected_accounts", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::ProjectedCostResponse>(
&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<GetProjectedCostError> =
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 get_usage_application_security_monitoring(
&self,
start_hr: chrono::DateTime<chrono::Utc>,
params: GetUsageApplicationSecurityMonitoringOptionalParams,
) -> Result<
crate::datadogV2::model::UsageApplicationSecurityMonitoringResponse,
datadog::Error<GetUsageApplicationSecurityMonitoringError>,
> {
match self
.get_usage_application_security_monitoring_with_http_info(start_hr, 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 get_usage_application_security_monitoring_with_http_info(
&self,
start_hr: chrono::DateTime<chrono::Utc>,
params: GetUsageApplicationSecurityMonitoringOptionalParams,
) -> Result<
datadog::ResponseContent<
crate::datadogV2::model::UsageApplicationSecurityMonitoringResponse,
>,
datadog::Error<GetUsageApplicationSecurityMonitoringError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_usage_application_security_monitoring";
let end_hr = params.end_hr;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/application_security",
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(&[(
"start_hr",
&start_hr.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
if let Some(ref local_query_param) = end_hr {
local_req_builder = local_req_builder.query(&[(
"end_hr",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::UsageApplicationSecurityMonitoringResponse,
>(&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<GetUsageApplicationSecurityMonitoringError> =
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 get_usage_lambda_traced_invocations(
&self,
start_hr: chrono::DateTime<chrono::Utc>,
params: GetUsageLambdaTracedInvocationsOptionalParams,
) -> Result<
crate::datadogV2::model::UsageLambdaTracedInvocationsResponse,
datadog::Error<GetUsageLambdaTracedInvocationsError>,
> {
match self
.get_usage_lambda_traced_invocations_with_http_info(start_hr, 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 get_usage_lambda_traced_invocations_with_http_info(
&self,
start_hr: chrono::DateTime<chrono::Utc>,
params: GetUsageLambdaTracedInvocationsOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::UsageLambdaTracedInvocationsResponse>,
datadog::Error<GetUsageLambdaTracedInvocationsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_usage_lambda_traced_invocations";
let end_hr = params.end_hr;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/lambda_traced_invocations",
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(&[(
"start_hr",
&start_hr.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
if let Some(ref local_query_param) = end_hr {
local_req_builder = local_req_builder.query(&[(
"end_hr",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::UsageLambdaTracedInvocationsResponse,
>(&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<GetUsageLambdaTracedInvocationsError> =
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 get_usage_observability_pipelines(
&self,
start_hr: chrono::DateTime<chrono::Utc>,
params: GetUsageObservabilityPipelinesOptionalParams,
) -> Result<
crate::datadogV2::model::UsageObservabilityPipelinesResponse,
datadog::Error<GetUsageObservabilityPipelinesError>,
> {
match self
.get_usage_observability_pipelines_with_http_info(start_hr, 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 get_usage_observability_pipelines_with_http_info(
&self,
start_hr: chrono::DateTime<chrono::Utc>,
params: GetUsageObservabilityPipelinesOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::UsageObservabilityPipelinesResponse>,
datadog::Error<GetUsageObservabilityPipelinesError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_usage_observability_pipelines";
let end_hr = params.end_hr;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/usage/observability_pipelines",
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(&[(
"start_hr",
&start_hr.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
if let Some(ref local_query_param) = end_hr {
local_req_builder = local_req_builder.query(&[(
"end_hr",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
let mut headers = HeaderMap::new();
headers.insert(
"Accept",
HeaderValue::from_static("application/json;datetime-format=rfc3339"),
);
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::datadogV2::model::UsageObservabilityPipelinesResponse>(
&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<GetUsageObservabilityPipelinesError> =
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))
}
}
}