diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index aaae703e3a..7991818c67 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -267100,6 +267100,10 @@ paths: description: |- 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. + Set `create_only=true` to atomically create exactly one quota in the caller's organization and reject an + existing quota with `409` instead of updating it. This mode does not support pending limits or descendant writes. + Repeated create-only requests do not replay the original response. If a response is lost, a retry can return `409` + even if the first request succeeded; reconcile the outcome before retrying or importing the quota. 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. @@ -267147,6 +267151,13 @@ paths: schema: default: false type: boolean + - description: Create one quota without updating an existing quota. Requires exactly one item that specifies `usage_limit` and `enforced`, omits `pending_usage_limit`, and sets `include_descendants=false`. The quota belongs to the caller's organization. An existing quota returns `409` without being modified. + in: query + name: create_only + required: false + schema: + default: false + type: boolean requestBody: content: application/json: @@ -267208,13 +267219,29 @@ paths: application/json: schema: $ref: "#/components/schemas/JSONAPIErrorResponse" - description: Bad Request. Returned if the request is malformed, including when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a quota that does not exist is reported in that item's `error`; when only the caller's organization is targeted, this failure returns `400`. + description: Bad Request. Returned when `create_only=true` is combined with multiple items, `pending_usage_limit`, or `include_descendants=true`, or when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a nonexistent quota reports an error in the item's `error` field. If only the caller's organization is targeted, this failure returns `400`. "403": content: application/json: schema: $ref: "#/components/schemas/JSONAPIErrorResponse" description: Forbidden + "409": + content: + application/json: + examples: + already_exists: + value: + errors: + - detail: A quota already exists for this namespace and scope. Import it before managing it with Terraform. + meta: + error_code: already_exists + quota_id: "MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOmphbmVAZXhhbXBsZS5jb20" + status: "409" + title: Conflict + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Conflict. With `create_only=true`, a quota already exists for this namespace and scope in the caller's organization. The existing quota is unchanged. The error's `meta` contains `error_code` set to `already_exists` and `quota_id` set to the existing quota's opaque ID. Import the existing quota before managing it with Terraform. "429": $ref: "#/components/responses/TooManyRequestsResponse" "500": diff --git a/src/datadog_api_client/v2/api/usage_metering_api.py b/src/datadog_api_client/v2/api/usage_metering_api.py index ebabfad6d1..0c4d5ffb36 100644 --- a/src/datadog_api_client/v2/api/usage_metering_api.py +++ b/src/datadog_api_client/v2/api/usage_metering_api.py @@ -86,6 +86,11 @@ def __init__(self, api_client=None): "attribute": "include_descendants", "location": "query", }, + "create_only": { + "openapi_types": (bool,), + "attribute": "create_only", + "location": "query", + }, "body": { "required": True, "openapi_types": (UsageQuotasCreateRequest,), @@ -929,11 +934,16 @@ def create_quotas( body: UsageQuotasCreateRequest, *, include_descendants: Union[bool, UnsetType] = unset, + create_only: Union[bool, UnsetType] = unset, ) -> UsageQuotasBulkResponse: """Create or update usage quotas. 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. + Set ``create_only=true`` to atomically create exactly one quota in the caller's organization and reject an + existing quota with ``409`` instead of updating it. This mode does not support pending limits or descendant writes. + Repeated create-only requests do not replay the original response. If a response is lost, a retry can return ``409`` + even if the first request succeeded; reconcile the outcome before retrying or importing the quota. 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. @@ -972,6 +982,8 @@ def create_quotas( :type body: UsageQuotasCreateRequest :param include_descendants: Whether to write every item in the request to the caller's organization and all of its descendant organizations, instead of only the caller's organization. Only descendants in the same data center are supported. For a user-handle scope, the quota is applied only to the caller's organization and to descendant organizations where that user handle exists; the item fails only if the handle exists in none of them. :type include_descendants: bool, optional + :param create_only: Create one quota without updating an existing quota. Requires exactly one item that specifies ``usage_limit`` and ``enforced`` , omits ``pending_usage_limit`` , and sets ``include_descendants=false``. The quota belongs to the caller's organization. An existing quota returns ``409`` without being modified. + :type create_only: bool, optional :rtype: UsageQuotasBulkResponse """ kwargs: Dict[str, Any] = {} @@ -980,6 +992,9 @@ def create_quotas( if include_descendants is not unset: kwargs["include_descendants"] = include_descendants + if create_only is not unset: + kwargs["create_only"] = create_only + kwargs["body"] = body return self._create_quotas_endpoint.call_with_http_info(**kwargs) diff --git a/tests/v2/features/usage_metering.feature b/tests/v2/features/usage_metering.feature index eea23ce587..67ba7beace 100644 --- a/tests/v2/features/usage_metering.feature +++ b/tests/v2/features/usage_metering.feature @@ -106,13 +106,22 @@ Feature: Usage Metering Then the response status is 404 Not Found @generated @skip @team:ddoghq/billing-hub - Scenario: Create or update usage quotas returns "Bad Request. Returned if the request is malformed, including when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a quota that does not exist is reported in that item's `error`; when only the caller's organization is targeted, this failure returns `400`." response + Scenario: Create or update usage quotas returns "Bad Request. Returned when `create_only=true` is combined with multiple items, `pending_usage_limit`, or `include_descendants=true`, or when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a nonexistent quota reports an error in the item's `error` field. If only the caller's organization is targeted, this failure returns `400`." response Given operation "CreateQuotas" enabled And new "CreateQuotas" request And request contains "quota_namespace" parameter from "REPLACE.ME" And body with value {"data": [{"attributes": {"enforced": true, "pending_usage_limit": 100000, "usage_limit": 600000}, "type": "quotas"}]} When the request is sent - Then the response status is 400 Bad Request. Returned if the request is malformed, including when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a quota that does not exist is reported in that item's `error`; when only the caller's organization is targeted, this failure returns `400`. + Then the response status is 400 Bad Request. Returned when `create_only=true` is combined with multiple items, `pending_usage_limit`, or `include_descendants=true`, or when an item sets `pending_usage_limit` on a scoped quota, provides `enforced` without `usage_limit`, or provides neither limit. A pending-only item for a nonexistent quota reports an error in the item's `error` field. If only the caller's organization is targeted, this failure returns `400`. + + @generated @skip @team:ddoghq/billing-hub + Scenario: Create or update usage quotas returns "Conflict. With `create_only=true`, a quota already exists for this namespace and scope in the caller's organization. The existing quota is unchanged. The error's `meta` contains `error_code` set to `already_exists` and `quota_id` set to the existing quota's opaque ID. Import the existing quota before managing it with Terraform." response + Given operation "CreateQuotas" enabled + And new "CreateQuotas" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And body with value {"data": [{"attributes": {"enforced": true, "pending_usage_limit": 100000, "usage_limit": 600000}, "type": "quotas"}]} + When the request is sent + Then the response status is 409 Conflict. With `create_only=true`, a quota already exists for this namespace and scope in the caller's organization. The existing quota is unchanged. The error's `meta` contains `error_code` set to `already_exists` and `quota_id` set to the existing quota's opaque ID. Import the existing quota before managing it with Terraform. @generated @skip @team:ddoghq/billing-hub Scenario: Create or update usage quotas returns "OK. The response includes each item's result; see each item's `error` attribute for any that failed to write." response