Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 138 additions & 24 deletions .generator/schemas/v2/openapi.yaml

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions examples/v2_usage-metering_CreateQuotas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use datadog_api_client::datadogV2::model::UsageQuotaCreateAttributes;
use datadog_api_client::datadogV2::model::UsageQuotaCreateData;
use datadog_api_client::datadogV2::model::UsageQuotaType;
use datadog_api_client::datadogV2::model::UsageQuotasCreateRequest;
use std::collections::BTreeMap;

#[tokio::main]
async fn main() {
let body = UsageQuotasCreateRequest::new(vec![UsageQuotaCreateData::new(
UsageQuotaCreateAttributes::new(true, 100000).scope(BTreeMap::from([(
"user_handle".to_string(),
"jane@example.com".to_string(),
)])),
UsageQuotaCreateAttributes::new()
.enforced(true)
.pending_usage_limit(100000)
.usage_limit(600000),
UsageQuotaType::QUOTAS,
)]);
let mut configuration = datadog::Configuration::new();
Expand Down
21 changes: 21 additions & 0 deletions examples/v2_usage-metering_DeletePendingQuota.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Cancel a scheduled usage quota limit returns "No Content" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI;

#[tokio::main]
async fn main() {
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.delete_pending_quota", true);
let api = UsageMeteringAPI::with_config(configuration);
let resp = api
.delete_pending_quota(
"ai_credits".to_string(),
"MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18".to_string(),
)
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
2 changes: 1 addition & 1 deletion examples/v2_usage-metering_DeleteQuota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() {
let resp = api
.delete_quota(
"ai_credits".to_string(),
"MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f".to_string(),
"MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18".to_string(),
)
.await;
if let Ok(value) = resp {
Expand Down
5 changes: 3 additions & 2 deletions examples/v2_usage-metering_UpdateQuota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ async fn main() {
let body = UsageQuotaUpdateRequest::new(UsageQuotaUpdateData::new(
UsageQuotaUpdateAttributes::new()
.enforced(Some(false))
.pending_usage_limit(Some(50000))
.usage_limit(Some(120000)),
"MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f".to_string(),
"MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18".to_string(),
UsageQuotaType::QUOTAS,
));
let mut configuration = datadog::Configuration::new();
Expand All @@ -21,7 +22,7 @@ async fn main() {
let resp = api
.update_quota(
"ai_credits".to_string(),
"MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f".to_string(),
"MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18".to_string(),
body,
)
.await;
Expand Down
1 change: 1 addition & 0 deletions src/datadog/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ impl Default for Configuration {
("v2.search_cost_recommendations".to_owned(), false),
("v2.update_unit_cost".to_owned(), false),
("v2.create_quotas".to_owned(), false),
("v2.delete_pending_quota".to_owned(), false),
("v2.delete_quota".to_owned(), false),
("v2.list_quotas".to_owned(), false),
("v2.update_quota".to_owned(), false),
Expand Down
127 changes: 123 additions & 4 deletions src/datadogV2/api/api_usage_metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ pub enum CreateQuotasError {
UnknownValue(serde_json::Value),
}

/// DeletePendingQuotaError is a struct for typed errors of method [`UsageMeteringAPI::delete_pending_quota`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePendingQuotaError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// DeleteQuotaError is a struct for typed errors of method [`UsageMeteringAPI::delete_quota`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -601,7 +610,11 @@ impl UsageMeteringAPI {
Self { config, client }
}

/// Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated; otherwise, a new quota is created. Requires the `billing_edit` permission.
/// Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated.
/// Otherwise, a quota is created only when `usage_limit` and `enforced` are provided.
/// For the organization-wide quota, `pending_usage_limit` schedules a limit for the next usage period and can
/// accompany an immediate limit or update an existing quota by itself.
/// Scheduled changes follow `include_descendants` like the other fields. Requires the `billing_edit` permission.
pub async fn create_quotas(
&self,
quota_namespace: String,
Expand All @@ -626,7 +639,11 @@ impl UsageMeteringAPI {
}
}

/// Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated; otherwise, a new quota is created. Requires the `billing_edit` permission.
/// Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated.
/// Otherwise, a quota is created only when `usage_limit` and `enforced` are provided.
/// For the organization-wide quota, `pending_usage_limit` schedules a limit for the next usage period and can
/// accompany an immediate limit or update an existing quota by itself.
/// Scheduled changes follow `include_descendants` like the other fields. Requires the `billing_edit` permission.
pub async fn create_quotas_with_http_info(
&self,
quota_namespace: String,
Expand Down Expand Up @@ -777,6 +794,108 @@ impl UsageMeteringAPI {
}
}

/// Cancels the limit change scheduled to take effect at the start of the next usage period, leaving the usage quota and its current limit unchanged. Returns `404` when the quota does not exist, has no scheduled change, or its scheduled change has already taken effect; in every case the quota is left unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
pub async fn delete_pending_quota(
&self,
quota_namespace: String,
id: String,
) -> Result<(), datadog::Error<DeletePendingQuotaError>> {
match self
.delete_pending_quota_with_http_info(quota_namespace, id)
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}

/// Cancels the limit change scheduled to take effect at the start of the next usage period, leaving the usage quota and its current limit unchanged. Returns `404` when the quota does not exist, has no scheduled change, or its scheduled change has already taken effect; in every case the quota is left unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
pub async fn delete_pending_quota_with_http_info(
&self,
quota_namespace: String,
id: String,
) -> Result<datadog::ResponseContent<()>, datadog::Error<DeletePendingQuotaError>> {
let local_configuration = &self.config;
let local_operation_id = "v2.delete_pending_quota";
if local_configuration.is_unstable_operation_enabled(local_operation_id) {
warn!("Using unstable operation {local_operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.delete_pending_quota' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/usage/quotas/{quota_namespace}/{id}/pending",
local_configuration.get_operation_host(local_operation_id),
quota_namespace = datadog::urlencode(quota_namespace),
id = datadog::urlencode(id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());

// build headers
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("*/*"));

// build user agent
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()),
)
}
};

// build auth
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() {
Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: None,
})
} else {
let local_entity: Option<DeletePendingQuotaError> =
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))
}
}

/// Deletes a usage quota by its opaque identifier. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
pub async fn delete_quota(
&self,
Expand Down Expand Up @@ -2926,7 +3045,7 @@ impl UsageMeteringAPI {
}
}

/// Updates the supplied fields on a usage quota and leaves omitted fields unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
/// Updates the supplied fields on a usage quota and leaves omitted fields unchanged. For an organization-wide quota, `pending_usage_limit` schedules a limit for the next usage period. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
pub async fn update_quota(
&self,
quota_namespace: String,
Expand All @@ -2950,7 +3069,7 @@ impl UsageMeteringAPI {
}
}

/// Updates the supplied fields on a usage quota and leaves omitted fields unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
/// Updates the supplied fields on a usage quota and leaves omitted fields unchanged. For an organization-wide quota, `pending_usage_limit` schedules a limit for the next usage period. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the `billing_edit` permission.
pub async fn update_quota_with_http_info(
&self,
quota_namespace: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// Attributes of a usage quota bulk write result. On success, all fields except `error` are present. On failure, only `error` is present and the other fields are omitted.
/// Attributes of a usage quota bulk write result. On success, quota fields are present as applicable, and pending fields are present only when a change is scheduled. On failure, only `error` is present and the other fields are omitted.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
Expand All @@ -20,6 +20,12 @@ pub struct UsageQuotaBulkResultAttributes {
/// The public ID of the organization that owns the quota. Omitted if this item failed to write.
#[serde(rename = "org_public_id")]
pub org_public_id: Option<String>,
/// The future UTC month when the scheduled limit takes effect, formatted as `YYYY-MM`, starting at 00:00 UTC on its first day. Present only together with `pending_usage_limit` and omitted when no change is scheduled or this item failed to write.
#[serde(rename = "pending_effective_from")]
pub pending_effective_from: Option<String>,
/// The usage limit scheduled for the organization-wide quota in the usage units defined by the quota namespace. A value of `0` is valid. At the start of the effective month, this value becomes `usage_limit` and both pending fields are omitted. Omitted when no change is scheduled or this item failed to write.
#[serde(rename = "pending_usage_limit")]
pub pending_usage_limit: Option<f64>,
/// A namespace-specific key and value identifying what the quota applies to within an organization. The object contains exactly one entry. A value of `"*"` identifies the default quota applied to entities without a specific quota. This field is omitted for an organization-wide quota.
#[serde(rename = "scope")]
pub scope: Option<std::collections::BTreeMap<String, String>>,
Expand All @@ -39,6 +45,8 @@ impl UsageQuotaBulkResultAttributes {
enforced: None,
error: None,
org_public_id: None,
pending_effective_from: None,
pending_usage_limit: None,
scope: None,
usage_limit: None,
additional_properties: std::collections::BTreeMap::new(),
Expand All @@ -61,6 +69,16 @@ impl UsageQuotaBulkResultAttributes {
self
}

pub fn pending_effective_from(mut self, value: String) -> Self {
self.pending_effective_from = Some(value);
self
}

pub fn pending_usage_limit(mut self, value: f64) -> Self {
self.pending_usage_limit = Some(value);
self
}

pub fn scope(mut self, value: std::collections::BTreeMap<String, String>) -> Self {
self.scope = Some(value);
self
Expand Down Expand Up @@ -106,6 +124,8 @@ impl<'de> Deserialize<'de> for UsageQuotaBulkResultAttributes {
let mut enforced: Option<bool> = None;
let mut error: Option<String> = None;
let mut org_public_id: Option<String> = None;
let mut pending_effective_from: Option<String> = None;
let mut pending_usage_limit: Option<f64> = None;
let mut scope: Option<std::collections::BTreeMap<String, String>> = None;
let mut usage_limit: Option<f64> = None;
let mut additional_properties: std::collections::BTreeMap<
Expand Down Expand Up @@ -135,6 +155,20 @@ impl<'de> Deserialize<'de> for UsageQuotaBulkResultAttributes {
org_public_id =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"pending_effective_from" => {
if v.is_null() {
continue;
}
pending_effective_from =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"pending_usage_limit" => {
if v.is_null() || v.as_str() == Some("") {
continue;
}
pending_usage_limit =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"scope" => {
if v.is_null() {
continue;
Expand All @@ -160,6 +194,8 @@ impl<'de> Deserialize<'de> for UsageQuotaBulkResultAttributes {
enforced,
error,
org_public_id,
pending_effective_from,
pending_usage_limit,
scope,
usage_limit,
additional_properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt::{self, Formatter};
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct UsageQuotaBulkResultData {
/// Attributes of a usage quota bulk write result. On success, all fields except `error` are present. On failure, only `error` is present and the other fields are omitted.
/// Attributes of a usage quota bulk write result. On success, quota fields are present as applicable, and pending fields are present only when a change is scheduled. On failure, only `error` is present and the other fields are omitted.
#[serde(rename = "attributes")]
pub attributes: crate::datadogV2::model::UsageQuotaBulkResultAttributes,
/// An opaque usage quota identifier. Clients must pass this value back verbatim in update and delete requests and must not infer any structure from it.
Expand Down
Loading
Loading