diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 982af41880..726d01d4a5 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -117055,6 +117055,210 @@ components: $ref: "#/components/schemas/UsageDataObject" type: array type: object + UsageQuotaCreateAttributes: + description: Attributes for creating or updating a usage quota by scope. + properties: + enforced: + description: Whether to actively block usage above the limit instead of only tracking or alerting on it. + example: true + type: boolean + org_public_id: + description: The public ID of the caller's organization or one of its descendants that should own the quota. This field is allowed only when `include_descendants` is true and defaults to the caller's organization when omitted. + example: abcdef12345 + type: string + scope: + $ref: "#/components/schemas/UsageQuotaRequestScope" + usage_limit: + description: The quota limit to set in the usage units defined by the quota namespace. The limit cannot be lower than the usage already recorded in the current period. + example: 100000 + format: int64 + type: integer + required: + - usage_limit + - enforced + type: object + UsageQuotaCreateData: + description: A usage quota resource to create or update by scope. + properties: + attributes: + $ref: "#/components/schemas/UsageQuotaCreateAttributes" + type: + $ref: "#/components/schemas/UsageQuotaType" + required: + - type + - attributes + type: object + UsageQuotaCreateDataList: + description: A bulk list of usage quota resources to create or update by scope. + items: + $ref: "#/components/schemas/UsageQuotaCreateData" + minItems: 1 + type: array + UsageQuotaRequestScope: + additionalProperties: + example: jane@example.com + type: string + description: A namespace-specific key and value identifying what the quota applies to within an organization. The object must contain exactly one entry. Use `"*"` as the value for the default quota applied to entities without a specific quota, or omit the scope for an organization-wide quota. When `include_descendants` is false, a specific value must identify an existing user handle in the caller's organization. When `include_descendants` is true, a specific value is validated only as an email address. + example: + user_handle: jane@example.com + maxProperties: 1 + minProperties: 1 + type: object + UsageQuotaResponse: + description: Response containing a usage quota. + properties: + data: + $ref: "#/components/schemas/UsageQuotaResponseData" + required: + - data + type: object + UsageQuotaResponseAttributes: + description: Attributes of a usage quota. + properties: + enforced: + description: Whether usage above the limit is actively blocked instead of only tracked or alerted on. + example: true + type: boolean + org_public_id: + description: The public ID of the organization that owns the quota. + example: abcdef12345 + type: string + scope: + $ref: "#/components/schemas/UsageQuotaResponseScope" + usage_limit: + description: The quota limit in the usage units defined by the quota namespace. + example: 100000 + format: int64 + type: integer + required: + - scope + - org_public_id + - usage_limit + - enforced + type: object + UsageQuotaResponseData: + description: A usage quota resource. + properties: + attributes: + $ref: "#/components/schemas/UsageQuotaResponseAttributes" + id: + description: 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. + example: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: string + type: + $ref: "#/components/schemas/UsageQuotaType" + required: + - id + - type + - attributes + type: object + UsageQuotaResponseDataList: + description: A list of usage quota resources. + items: + $ref: "#/components/schemas/UsageQuotaResponseData" + type: array + UsageQuotaResponseScope: + additionalProperties: + example: jane@example.com + type: string + description: 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 or null for an organization-wide quota. + example: + user_handle: jane@example.com + maxProperties: 1 + minProperties: 1 + nullable: true + type: object + UsageQuotaType: + description: The JSON:API resource type for a usage quota. + enum: + - quota + example: quota + type: string + x-enum-varnames: + - QUOTA + UsageQuotaUpdateAttributes: + description: Attributes to update on a usage quota. Omitting a property leaves its current value unchanged. + properties: + enforced: + description: Whether to actively block usage above the limit. Omit this field to leave the current enforcement setting unchanged. + example: false + nullable: true + type: boolean + org_public_id: + description: The public ID of the organization that already owns the quota. This is a consistency check and cannot move the quota to another organization. + example: abcdef12345 + nullable: true + type: string + usage_limit: + description: The new quota limit in the usage units defined by the quota namespace. The limit cannot be lower than the usage already recorded in the current period. Omit this field to leave the current limit unchanged. + example: 120000 + format: int64 + nullable: true + type: integer + type: object + UsageQuotaUpdateData: + description: A usage quota resource to update. + properties: + attributes: + $ref: "#/components/schemas/UsageQuotaUpdateAttributes" + id: + description: The opaque usage quota identifier, which must match the identifier in the request path. + example: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: string + type: + $ref: "#/components/schemas/UsageQuotaType" + required: + - id + - type + - attributes + type: object + UsageQuotaUpdateRequest: + description: Request containing the usage quota resource to update. + properties: + data: + $ref: "#/components/schemas/UsageQuotaUpdateData" + required: + - data + type: object + UsageQuotasCreateRequest: + description: A JSON:API bulk request containing an array of usage quota resources rather than a single resource. + properties: + data: + $ref: "#/components/schemas/UsageQuotaCreateDataList" + required: + - data + type: object + UsageQuotasListResponse: + description: Response containing a paginated list of usage quotas. + properties: + data: + $ref: "#/components/schemas/UsageQuotaResponseDataList" + meta: + $ref: "#/components/schemas/UsageQuotasResponseMeta" + required: + - data + - meta + type: object + UsageQuotasResponse: + description: Response containing a list of usage quotas. + properties: + data: + $ref: "#/components/schemas/UsageQuotaResponseDataList" + required: + - data + type: object + UsageQuotasResponseMeta: + description: Pagination metadata for a usage quota list response. This field may be omitted when no pagination metadata is available. + nullable: true + properties: + next_cursor: + description: An opaque cursor for retrieving the next page. This field may be omitted or null when there are no more results. + example: eyJvZmZzZXQiOjEwMH0= + nullable: true + type: string + required: + - next_cursor + type: object UsageSummaryAvailableFieldsAttributes: description: |- The lists of field names returned by `GET /api/v1/usage/summary` at each @@ -211442,6 +211646,356 @@ paths: permissions: - usage_read - billing_read + /api/v2/usage/quotas/{quota_namespace}: + get: + description: |- + Lists usage quotas configured for the caller's organization within a quota namespace. Descendant organizations can optionally be included, but only descendants in the same datacenter as the caller are supported. Requires the `user_access_manage`, `billing_edit`, and `org_management` permissions. + operationId: ListQuotas + parameters: + - description: The product-specific namespace whose usage quotas are being managed. + in: path + name: quota_namespace + required: true + schema: + example: ai_credits + type: string + - description: Whether to include quotas configured on descendant organizations in the caller's organization hierarchy. Only descendants in the same datacenter are supported. + in: query + name: include_descendants + required: false + schema: + default: false + type: boolean + - description: An opaque cursor from a previous response's `meta.next_cursor` used to retrieve the next page. + in: query + name: pagination[cursor] + required: false + schema: + type: string + - description: The number of usage quotas to return per page. + in: query + name: pagination[page_size] + required: false + schema: + default: 100 + format: int64 + maximum: 1000 + minimum: 1 + type: integer + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + enforced: true + org_public_id: abcdef12345 + scope: + user_handle: jane@example.com + usage_limit: 100000 + id: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: quota + meta: + next_cursor: eyJvZmZzZXQiOjEwMH0= + schema: + $ref: "#/components/schemas/UsageQuotasListResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - user_access_manage + - billing_edit + - org_management + summary: List usage quotas + tags: + - Usage Metering + x-pagination: + cursorParam: pagination[cursor] + cursorPath: meta.next_cursor + limitParam: pagination[page_size] + resultsPath: data + "x-permission": + operator: AND + permissions: + - user_access_manage + - billing_edit + - org_management + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + post: + description: |- + Creates or updates one or more usage quotas by scope. Existing quotas for a supplied scope are updated and missing quotas are created. Requires the `user_access_manage`, `billing_edit`, and `org_management` permissions. + operationId: CreateOrUpdateQuotas + parameters: + - description: The product-specific namespace whose usage quotas are being managed. + in: path + name: quota_namespace + required: true + schema: + example: ai_credits + type: string + - description: Whether request items may target the caller's organization or one of its descendants through `org_public_id`. When false, every item targets the caller's organization and `org_public_id` must be omitted. + in: query + name: include_descendants + required: false + schema: + default: false + type: boolean + requestBody: + content: + application/json: + examples: + default: + summary: Create or update quotas for the caller's organization. + value: + data: + - attributes: + enforced: true + scope: + user_handle: jane@example.com + usage_limit: 100000 + type: quota + - attributes: + enforced: false + scope: + user_handle: "*" + usage_limit: 250000 + type: quota + descendant: + summary: Create or update a quota for a descendant organization with `include_descendants` set to true. + value: + data: + - attributes: + enforced: true + org_public_id: abcdef12345 + scope: + user_handle: jane@example.com + usage_limit: 100000 + type: quota + schema: + $ref: "#/components/schemas/UsageQuotasCreateRequest" + description: The usage quotas to create or update. + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + enforced: true + org_public_id: abcdef12345 + scope: + user_handle: jane@example.com + usage_limit: 100000 + id: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: quota + schema: + $ref: "#/components/schemas/UsageQuotasResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - user_access_manage + - billing_edit + - org_management + summary: Create or update usage quotas + tags: + - Usage Metering + "x-permission": + operator: AND + permissions: + - user_access_manage + - billing_edit + - org_management + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/usage/quotas/{quota_namespace}/{id}: + delete: + description: |- + 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 `user_access_manage`, `billing_edit`, and `org_management` permissions. + operationId: DeleteQuota + parameters: + - description: The product-specific namespace whose usage quotas are being managed. + in: path + name: quota_namespace + required: true + schema: + example: ai_credits + type: string + - description: The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim. + in: path + name: id + required: true + schema: + example: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: string + responses: + "204": + description: No Content + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - user_access_manage + - billing_edit + - org_management + summary: Delete a usage quota + tags: + - Usage Metering + "x-permission": + operator: AND + permissions: + - user_access_manage + - billing_edit + - org_management + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + patch: + description: |- + 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 `user_access_manage`, `billing_edit`, and `org_management` permissions. + operationId: UpdateQuota + parameters: + - description: The product-specific namespace whose usage quotas are being managed. + in: path + name: quota_namespace + required: true + schema: + example: ai_credits + type: string + - description: The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim. + in: path + name: id + required: true + schema: + example: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: string + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + enforced: false + usage_limit: 120000 + id: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: quota + schema: + $ref: "#/components/schemas/UsageQuotaUpdateRequest" + description: The usage quota fields to update. Omitting an attribute leaves its current value unchanged. + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + enforced: false + org_public_id: abcdef12345 + scope: + user_handle: jane@example.com + usage_limit: 120000 + id: "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f" + type: quota + schema: + $ref: "#/components/schemas/UsageQuotaResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - user_access_manage + - billing_edit + - org_management + summary: Update a usage quota + tags: + - Usage Metering + "x-permission": + operator: AND + permissions: + - user_access_manage + - billing_edit + - org_management + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). /api/v2/usage/summary/available_fields: get: description: |- diff --git a/docs/datadog_api_client.v2.model.rst b/docs/datadog_api_client.v2.model.rst index d1ddaac1fe..6b7fa0144c 100644 --- a/docs/datadog_api_client.v2.model.rst +++ b/docs/datadog_api_client.v2.model.rst @@ -50292,6 +50292,111 @@ datadog\_api\_client.v2.model.usage\_observability\_pipelines\_response module :members: :show-inheritance: +datadog\_api\_client.v2.model.usage\_quota\_create\_attributes module +--------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_create_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_create\_data module +--------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_create_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_request\_scope module +----------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_request_scope + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_response module +----------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_response + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_response\_attributes module +----------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_response_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_response\_data module +----------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_response_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_response\_scope module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.usage_quota_response_scope + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_type module +------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_type + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_update\_attributes module +--------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_update_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_update\_data module +--------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quota_update_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quota\_update\_request module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.usage_quota_update_request + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quotas\_create\_request module +------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.usage_quotas_create_request + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quotas\_list\_response module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.usage_quotas_list_response + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quotas\_response module +------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.usage_quotas_response + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.usage\_quotas\_response\_meta module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.usage_quotas_response_meta + :members: + :show-inheritance: + datadog\_api\_client.v2.model.usage\_summary\_available\_fields\_attributes module ---------------------------------------------------------------------------------- diff --git a/examples/v2/usage-metering/CreateOrUpdateQuotas.py b/examples/v2/usage-metering/CreateOrUpdateQuotas.py new file mode 100644 index 0000000000..51638ca9ac --- /dev/null +++ b/examples/v2/usage-metering/CreateOrUpdateQuotas.py @@ -0,0 +1,35 @@ +""" +Create or update usage quotas returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi +from datadog_api_client.v2.model.usage_quota_create_attributes import UsageQuotaCreateAttributes +from datadog_api_client.v2.model.usage_quota_create_data import UsageQuotaCreateData +from datadog_api_client.v2.model.usage_quota_request_scope import UsageQuotaRequestScope +from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType +from datadog_api_client.v2.model.usage_quotas_create_request import UsageQuotasCreateRequest + +body = UsageQuotasCreateRequest( + data=[ + UsageQuotaCreateData( + attributes=UsageQuotaCreateAttributes( + enforced=True, + org_public_id="abcdef12345", + scope=UsageQuotaRequestScope( + user_handle="jane@example.com", + ), + usage_limit=100000, + ), + type=UsageQuotaType.QUOTA, + ), + ], +) + +configuration = Configuration() +configuration.unstable_operations["create_or_update_quotas"] = True +with ApiClient(configuration) as api_client: + api_instance = UsageMeteringApi(api_client) + response = api_instance.create_or_update_quotas(quota_namespace="ai_credits", body=body) + + print(response) diff --git a/examples/v2/usage-metering/DeleteQuota.py b/examples/v2/usage-metering/DeleteQuota.py new file mode 100644 index 0000000000..6ea64142da --- /dev/null +++ b/examples/v2/usage-metering/DeleteQuota.py @@ -0,0 +1,15 @@ +""" +Delete a usage quota returns "No Content" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi + +configuration = Configuration() +configuration.unstable_operations["delete_quota"] = True +with ApiClient(configuration) as api_client: + api_instance = UsageMeteringApi(api_client) + api_instance.delete_quota( + quota_namespace="ai_credits", + id="MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", + ) diff --git a/examples/v2/usage-metering/ListQuotas.py b/examples/v2/usage-metering/ListQuotas.py new file mode 100644 index 0000000000..5ed00266ea --- /dev/null +++ b/examples/v2/usage-metering/ListQuotas.py @@ -0,0 +1,16 @@ +""" +List usage quotas returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi + +configuration = Configuration() +configuration.unstable_operations["list_quotas"] = True +with ApiClient(configuration) as api_client: + api_instance = UsageMeteringApi(api_client) + response = api_instance.list_quotas( + quota_namespace="ai_credits", + ) + + print(response) diff --git a/examples/v2/usage-metering/ListQuotas_918754421.py b/examples/v2/usage-metering/ListQuotas_918754421.py new file mode 100644 index 0000000000..47f2360ca0 --- /dev/null +++ b/examples/v2/usage-metering/ListQuotas_918754421.py @@ -0,0 +1,16 @@ +""" +List usage quotas returns "OK" response with pagination +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi + +configuration = Configuration() +configuration.unstable_operations["list_quotas"] = True +with ApiClient(configuration) as api_client: + api_instance = UsageMeteringApi(api_client) + items = api_instance.list_quotas_with_pagination( + quota_namespace="ai_credits", + ) + for item in items: + print(item) diff --git a/examples/v2/usage-metering/UpdateQuota.py b/examples/v2/usage-metering/UpdateQuota.py new file mode 100644 index 0000000000..053905c2d2 --- /dev/null +++ b/examples/v2/usage-metering/UpdateQuota.py @@ -0,0 +1,32 @@ +""" +Update a usage quota returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi +from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType +from datadog_api_client.v2.model.usage_quota_update_attributes import UsageQuotaUpdateAttributes +from datadog_api_client.v2.model.usage_quota_update_data import UsageQuotaUpdateData +from datadog_api_client.v2.model.usage_quota_update_request import UsageQuotaUpdateRequest + +body = UsageQuotaUpdateRequest( + data=UsageQuotaUpdateData( + attributes=UsageQuotaUpdateAttributes( + enforced=False, + org_public_id="abcdef12345", + usage_limit=120000, + ), + id="MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", + type=UsageQuotaType.QUOTA, + ), +) + +configuration = Configuration() +configuration.unstable_operations["update_quota"] = True +with ApiClient(configuration) as api_client: + api_instance = UsageMeteringApi(api_client) + response = api_instance.update_quota( + quota_namespace="ai_credits", id="MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", body=body + ) + + print(response) diff --git a/src/datadog_api_client/configuration.py b/src/datadog_api_client/configuration.py index 0c9af4363f..aa824b6ea4 100644 --- a/src/datadog_api_client/configuration.py +++ b/src/datadog_api_client/configuration.py @@ -455,6 +455,10 @@ def __init__( "v2.list_cost_tag_metadata_months": False, "v2.list_cost_tag_metadata_orchestrators": False, "v2.search_cost_recommendations": False, + "v2.create_or_update_quotas": False, + "v2.delete_quota": False, + "v2.list_quotas": False, + "v2.update_quota": False, "v2.create_ownership_feedback": False, "v2.get_ownership_evidence": False, "v2.get_ownership_inference": False, 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 0bea5d7cb1..843ef8719f 100644 --- a/src/datadog_api_client/v2/api/usage_metering_api.py +++ b/src/datadog_api_client/v2/api/usage_metering_api.py @@ -3,6 +3,7 @@ # Copyright 2019-Present Datadog, Inc. from __future__ import annotations +import collections from typing import Any, Dict, Union import warnings @@ -10,6 +11,8 @@ from datadog_api_client.configuration import Configuration from datadog_api_client.model_utils import ( datetime, + set_attribute_from_path, + get_attribute_from_path, UnsetType, unset, ) @@ -26,6 +29,12 @@ from datadog_api_client.v2.model.usage_lambda_traced_invocations_response import UsageLambdaTracedInvocationsResponse from datadog_api_client.v2.model.usage_observability_pipelines_response import UsageObservabilityPipelinesResponse from datadog_api_client.v2.model.projected_cost_response import ProjectedCostResponse +from datadog_api_client.v2.model.usage_quotas_list_response import UsageQuotasListResponse +from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData +from datadog_api_client.v2.model.usage_quotas_response import UsageQuotasResponse +from datadog_api_client.v2.model.usage_quotas_create_request import UsageQuotasCreateRequest +from datadog_api_client.v2.model.usage_quota_response import UsageQuotaResponse +from datadog_api_client.v2.model.usage_quota_update_request import UsageQuotaUpdateRequest from datadog_api_client.v2.model.usage_summary_available_fields_response import UsageSummaryAvailableFieldsResponse from datadog_api_client.v2.model.usage_attribution_types_response import UsageAttributionTypesResponse @@ -49,6 +58,66 @@ def __init__(self, api_client=None): api_client = ApiClient(Configuration()) self.api_client = api_client + self._create_or_update_quotas_endpoint = _Endpoint( + settings={ + "response_type": (UsageQuotasResponse,), + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], + "endpoint_path": "/api/v2/usage/quotas/{quota_namespace}", + "operation_id": "create_or_update_quotas", + "http_method": "POST", + "version": "v2", + }, + params_map={ + "quota_namespace": { + "required": True, + "openapi_types": (str,), + "attribute": "quota_namespace", + "location": "path", + }, + "include_descendants": { + "openapi_types": (bool,), + "attribute": "include_descendants", + "location": "query", + }, + "body": { + "required": True, + "openapi_types": (UsageQuotasCreateRequest,), + "location": "body", + }, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + ) + + self._delete_quota_endpoint = _Endpoint( + settings={ + "response_type": None, + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], + "endpoint_path": "/api/v2/usage/quotas/{quota_namespace}/{id}", + "operation_id": "delete_quota", + "http_method": "DELETE", + "version": "v2", + }, + params_map={ + "quota_namespace": { + "required": True, + "openapi_types": (str,), + "attribute": "quota_namespace", + "location": "path", + }, + "id": { + "required": True, + "openapi_types": (str,), + "attribute": "id", + "location": "path", + }, + }, + headers_map={ + "accept": ["*/*"], + }, + api_client=api_client, + ) + self._get_active_billing_dimensions_endpoint = _Endpoint( settings={ "response_type": (ActiveBillingDimensionsResponse,), @@ -480,6 +549,131 @@ def __init__(self, api_client=None): api_client=api_client, ) + self._list_quotas_endpoint = _Endpoint( + settings={ + "response_type": (UsageQuotasListResponse,), + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], + "endpoint_path": "/api/v2/usage/quotas/{quota_namespace}", + "operation_id": "list_quotas", + "http_method": "GET", + "version": "v2", + }, + params_map={ + "quota_namespace": { + "required": True, + "openapi_types": (str,), + "attribute": "quota_namespace", + "location": "path", + }, + "include_descendants": { + "openapi_types": (bool,), + "attribute": "include_descendants", + "location": "query", + }, + "pagination_cursor": { + "openapi_types": (str,), + "attribute": "pagination[cursor]", + "location": "query", + }, + "pagination_page_size": { + "validation": { + "inclusive_maximum": 1000, + "inclusive_minimum": 1, + }, + "openapi_types": (int,), + "attribute": "pagination[page_size]", + "location": "query", + }, + }, + headers_map={ + "accept": ["application/json"], + }, + api_client=api_client, + ) + + self._update_quota_endpoint = _Endpoint( + settings={ + "response_type": (UsageQuotaResponse,), + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], + "endpoint_path": "/api/v2/usage/quotas/{quota_namespace}/{id}", + "operation_id": "update_quota", + "http_method": "PATCH", + "version": "v2", + }, + params_map={ + "quota_namespace": { + "required": True, + "openapi_types": (str,), + "attribute": "quota_namespace", + "location": "path", + }, + "id": { + "required": True, + "openapi_types": (str,), + "attribute": "id", + "location": "path", + }, + "body": { + "required": True, + "openapi_types": (UsageQuotaUpdateRequest,), + "location": "body", + }, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + ) + + def create_or_update_quotas( + self, + quota_namespace: str, + body: UsageQuotasCreateRequest, + *, + include_descendants: Union[bool, UnsetType] = unset, + ) -> UsageQuotasResponse: + """Create or update usage quotas. + + Creates or updates one or more usage quotas by scope. Existing quotas for a supplied scope are updated and missing quotas are created. Requires the ``user_access_manage`` , ``billing_edit`` , and ``org_management`` permissions. + + :param quota_namespace: The product-specific namespace whose usage quotas are being managed. + :type quota_namespace: str + :param body: The usage quotas to create or update. + :type body: UsageQuotasCreateRequest + :param include_descendants: Whether request items may target the caller's organization or one of its descendants through ``org_public_id``. When false, every item targets the caller's organization and ``org_public_id`` must be omitted. + :type include_descendants: bool, optional + :rtype: UsageQuotasResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["quota_namespace"] = quota_namespace + + if include_descendants is not unset: + kwargs["include_descendants"] = include_descendants + + kwargs["body"] = body + + return self._create_or_update_quotas_endpoint.call_with_http_info(**kwargs) + + def delete_quota( + self, + quota_namespace: str, + id: str, + ) -> None: + """Delete a usage quota. + + 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 ``user_access_manage`` , ``billing_edit`` , and ``org_management`` permissions. + + :param quota_namespace: The product-specific namespace whose usage quotas are being managed. + :type quota_namespace: str + :param id: The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim. + :type id: str + :rtype: None + """ + kwargs: Dict[str, Any] = {} + kwargs["quota_namespace"] = quota_namespace + + kwargs["id"] = id + + return self._delete_quota_endpoint.call_with_http_info(**kwargs) + def get_active_billing_dimensions( self, ) -> ActiveBillingDimensionsResponse: @@ -976,3 +1170,115 @@ def get_usage_summary_available_fields( """ kwargs: Dict[str, Any] = {} return self._get_usage_summary_available_fields_endpoint.call_with_http_info(**kwargs) + + def list_quotas( + self, + quota_namespace: str, + *, + include_descendants: Union[bool, UnsetType] = unset, + pagination_cursor: Union[str, UnsetType] = unset, + pagination_page_size: Union[int, UnsetType] = unset, + ) -> UsageQuotasListResponse: + """List usage quotas. + + Lists usage quotas configured for the caller's organization within a quota namespace. Descendant organizations can optionally be included, but only descendants in the same datacenter as the caller are supported. Requires the ``user_access_manage`` , ``billing_edit`` , and ``org_management`` permissions. + + :param quota_namespace: The product-specific namespace whose usage quotas are being managed. + :type quota_namespace: str + :param include_descendants: Whether to include quotas configured on descendant organizations in the caller's organization hierarchy. Only descendants in the same datacenter are supported. + :type include_descendants: bool, optional + :param pagination_cursor: An opaque cursor from a previous response's ``meta.next_cursor`` used to retrieve the next page. + :type pagination_cursor: str, optional + :param pagination_page_size: The number of usage quotas to return per page. + :type pagination_page_size: int, optional + :rtype: UsageQuotasListResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["quota_namespace"] = quota_namespace + + if include_descendants is not unset: + kwargs["include_descendants"] = include_descendants + + if pagination_cursor is not unset: + kwargs["pagination_cursor"] = pagination_cursor + + if pagination_page_size is not unset: + kwargs["pagination_page_size"] = pagination_page_size + + return self._list_quotas_endpoint.call_with_http_info(**kwargs) + + def list_quotas_with_pagination( + self, + quota_namespace: str, + *, + include_descendants: Union[bool, UnsetType] = unset, + pagination_cursor: Union[str, UnsetType] = unset, + pagination_page_size: Union[int, UnsetType] = unset, + ) -> collections.abc.Iterable[UsageQuotaResponseData]: + """List usage quotas. + + Provide a paginated version of :meth:`list_quotas`, returning all items. + + :param quota_namespace: The product-specific namespace whose usage quotas are being managed. + :type quota_namespace: str + :param include_descendants: Whether to include quotas configured on descendant organizations in the caller's organization hierarchy. Only descendants in the same datacenter are supported. + :type include_descendants: bool, optional + :param pagination_cursor: An opaque cursor from a previous response's ``meta.next_cursor`` used to retrieve the next page. + :type pagination_cursor: str, optional + :param pagination_page_size: The number of usage quotas to return per page. + :type pagination_page_size: int, optional + + :return: A generator of paginated results. + :rtype: collections.abc.Iterable[UsageQuotaResponseData] + """ + kwargs: Dict[str, Any] = {} + kwargs["quota_namespace"] = quota_namespace + + if include_descendants is not unset: + kwargs["include_descendants"] = include_descendants + + if pagination_cursor is not unset: + kwargs["pagination_cursor"] = pagination_cursor + + if pagination_page_size is not unset: + kwargs["pagination_page_size"] = pagination_page_size + + local_page_size = get_attribute_from_path(kwargs, "pagination_page_size", 100) + endpoint = self._list_quotas_endpoint + set_attribute_from_path(kwargs, "pagination_page_size", local_page_size, endpoint.params_map) + pagination = { + "limit_value": local_page_size, + "results_path": "data", + "cursor_param": "pagination_cursor", + "cursor_path": "meta.next_cursor", + "endpoint": endpoint, + "kwargs": kwargs, + } + return endpoint.call_with_http_info_paginated(pagination) + + def update_quota( + self, + quota_namespace: str, + id: str, + body: UsageQuotaUpdateRequest, + ) -> UsageQuotaResponse: + """Update a usage quota. + + 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 ``user_access_manage`` , ``billing_edit`` , and ``org_management`` permissions. + + :param quota_namespace: The product-specific namespace whose usage quotas are being managed. + :type quota_namespace: str + :param id: The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim. + :type id: str + :param body: The usage quota fields to update. Omitting an attribute leaves its current value unchanged. + :type body: UsageQuotaUpdateRequest + :rtype: UsageQuotaResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["quota_namespace"] = quota_namespace + + kwargs["id"] = id + + kwargs["body"] = body + + return self._update_quota_endpoint.call_with_http_info(**kwargs) diff --git a/src/datadog_api_client/v2/model/usage_quota_create_attributes.py b/src/datadog_api_client/v2/model/usage_quota_create_attributes.py new file mode 100644 index 0000000000..b0e6a83006 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_create_attributes.py @@ -0,0 +1,69 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Union, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + unset, + UnsetType, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_request_scope import UsageQuotaRequestScope + + +class UsageQuotaCreateAttributes(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_request_scope import UsageQuotaRequestScope + + return { + "enforced": (bool,), + "org_public_id": (str,), + "scope": (UsageQuotaRequestScope,), + "usage_limit": (int,), + } + + attribute_map = { + "enforced": "enforced", + "org_public_id": "org_public_id", + "scope": "scope", + "usage_limit": "usage_limit", + } + + def __init__( + self_, + enforced: bool, + usage_limit: int, + org_public_id: Union[str, UnsetType] = unset, + scope: Union[UsageQuotaRequestScope, UnsetType] = unset, + **kwargs, + ): + """ + Attributes for creating or updating a usage quota by scope. + + :param enforced: Whether to actively block usage above the limit instead of only tracking or alerting on it. + :type enforced: bool + + :param org_public_id: The public ID of the caller's organization or one of its descendants that should own the quota. This field is allowed only when ``include_descendants`` is true and defaults to the caller's organization when omitted. + :type org_public_id: str, optional + + :param scope: A namespace-specific key and value identifying what the quota applies to within an organization. The object must contain exactly one entry. Use ``"*"`` as the value for the default quota applied to entities without a specific quota, or omit the scope for an organization-wide quota. When ``include_descendants`` is false, a specific value must identify an existing user handle in the caller's organization. When ``include_descendants`` is true, a specific value is validated only as an email address. + :type scope: UsageQuotaRequestScope, optional + + :param usage_limit: The quota limit to set in the usage units defined by the quota namespace. The limit cannot be lower than the usage already recorded in the current period. + :type usage_limit: int + """ + if org_public_id is not unset: + kwargs["org_public_id"] = org_public_id + if scope is not unset: + kwargs["scope"] = scope + super().__init__(kwargs) + + self_.enforced = enforced + self_.usage_limit = usage_limit diff --git a/src/datadog_api_client/v2/model/usage_quota_create_data.py b/src/datadog_api_client/v2/model/usage_quota_create_data.py new file mode 100644 index 0000000000..702e30e437 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_create_data.py @@ -0,0 +1,48 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_create_attributes import UsageQuotaCreateAttributes + from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType + + +class UsageQuotaCreateData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_create_attributes import UsageQuotaCreateAttributes + from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType + + return { + "attributes": (UsageQuotaCreateAttributes,), + "type": (UsageQuotaType,), + } + + attribute_map = { + "attributes": "attributes", + "type": "type", + } + + def __init__(self_, attributes: UsageQuotaCreateAttributes, type: UsageQuotaType, **kwargs): + """ + A usage quota resource to create or update by scope. + + :param attributes: Attributes for creating or updating a usage quota by scope. + :type attributes: UsageQuotaCreateAttributes + + :param type: The JSON:API resource type for a usage quota. + :type type: UsageQuotaType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.type = type diff --git a/src/datadog_api_client/v2/model/usage_quota_request_scope.py b/src/datadog_api_client/v2/model/usage_quota_request_scope.py new file mode 100644 index 0000000000..c409683a26 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_request_scope.py @@ -0,0 +1,22 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +class UsageQuotaRequestScope(ModelNormal): + @cached_property + def additional_properties_type(_): + return (str,) + + def __init__(self_, **kwargs): + """ + A namespace-specific key and value identifying what the quota applies to within an organization. The object must contain exactly one entry. Use ``"*"`` as the value for the default quota applied to entities without a specific quota, or omit the scope for an organization-wide quota. When ``include_descendants`` is false, a specific value must identify an existing user handle in the caller's organization. When ``include_descendants`` is true, a specific value is validated only as an email address. + """ + super().__init__(kwargs) diff --git a/src/datadog_api_client/v2/model/usage_quota_response.py b/src/datadog_api_client/v2/model/usage_quota_response.py new file mode 100644 index 0000000000..e8e3990dc8 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_response.py @@ -0,0 +1,40 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData + + +class UsageQuotaResponse(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData + + return { + "data": (UsageQuotaResponseData,), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: UsageQuotaResponseData, **kwargs): + """ + Response containing a usage quota. + + :param data: A usage quota resource. + :type data: UsageQuotaResponseData + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/usage_quota_response_attributes.py b/src/datadog_api_client/v2/model/usage_quota_response_attributes.py new file mode 100644 index 0000000000..f7437ae1b8 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_response_attributes.py @@ -0,0 +1,66 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Union, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + none_type, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_response_scope import UsageQuotaResponseScope + + +class UsageQuotaResponseAttributes(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_response_scope import UsageQuotaResponseScope + + return { + "enforced": (bool,), + "org_public_id": (str,), + "scope": (UsageQuotaResponseScope,), + "usage_limit": (int,), + } + + attribute_map = { + "enforced": "enforced", + "org_public_id": "org_public_id", + "scope": "scope", + "usage_limit": "usage_limit", + } + + def __init__( + self_, + enforced: bool, + org_public_id: str, + scope: Union[UsageQuotaResponseScope, none_type], + usage_limit: int, + **kwargs, + ): + """ + Attributes of a usage quota. + + :param enforced: Whether usage above the limit is actively blocked instead of only tracked or alerted on. + :type enforced: bool + + :param org_public_id: The public ID of the organization that owns the quota. + :type org_public_id: str + + :param scope: 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 or null for an organization-wide quota. + :type scope: UsageQuotaResponseScope, none_type + + :param usage_limit: The quota limit in the usage units defined by the quota namespace. + :type usage_limit: int + """ + super().__init__(kwargs) + + self_.enforced = enforced + self_.org_public_id = org_public_id + self_.scope = scope + self_.usage_limit = usage_limit diff --git a/src/datadog_api_client/v2/model/usage_quota_response_data.py b/src/datadog_api_client/v2/model/usage_quota_response_data.py new file mode 100644 index 0000000000..38c493f10c --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_response_data.py @@ -0,0 +1,54 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_response_attributes import UsageQuotaResponseAttributes + from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType + + +class UsageQuotaResponseData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_response_attributes import UsageQuotaResponseAttributes + from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType + + return { + "attributes": (UsageQuotaResponseAttributes,), + "id": (str,), + "type": (UsageQuotaType,), + } + + attribute_map = { + "attributes": "attributes", + "id": "id", + "type": "type", + } + + def __init__(self_, attributes: UsageQuotaResponseAttributes, id: str, type: UsageQuotaType, **kwargs): + """ + A usage quota resource. + + :param attributes: Attributes of a usage quota. + :type attributes: UsageQuotaResponseAttributes + + :param id: 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. + :type id: str + + :param type: The JSON:API resource type for a usage quota. + :type type: UsageQuotaType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.id = id + self_.type = type diff --git a/src/datadog_api_client/v2/model/usage_quota_response_scope.py b/src/datadog_api_client/v2/model/usage_quota_response_scope.py new file mode 100644 index 0000000000..423a901934 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_response_scope.py @@ -0,0 +1,24 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +class UsageQuotaResponseScope(ModelNormal): + @cached_property + def additional_properties_type(_): + return (str,) + + _nullable = True + + def __init__(self_, **kwargs): + """ + 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 or null for an organization-wide quota. + """ + super().__init__(kwargs) diff --git a/src/datadog_api_client/v2/model/usage_quota_type.py b/src/datadog_api_client/v2/model/usage_quota_type.py new file mode 100644 index 0000000000..2de50e2358 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_type.py @@ -0,0 +1,35 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + + +from datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class UsageQuotaType(ModelSimple): + """ + The JSON:API resource type for a usage quota. + + :param value: If omitted defaults to "quota". Must be one of ["quota"]. + :type value: str + """ + + allowed_values = { + "quota", + } + QUOTA: ClassVar["UsageQuotaType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +UsageQuotaType.QUOTA = UsageQuotaType("quota") diff --git a/src/datadog_api_client/v2/model/usage_quota_update_attributes.py b/src/datadog_api_client/v2/model/usage_quota_update_attributes.py new file mode 100644 index 0000000000..d93fea6676 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_update_attributes.py @@ -0,0 +1,57 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Union + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + none_type, + unset, + UnsetType, +) + + +class UsageQuotaUpdateAttributes(ModelNormal): + @cached_property + def openapi_types(_): + return { + "enforced": (bool, none_type), + "org_public_id": (str, none_type), + "usage_limit": (int, none_type), + } + + attribute_map = { + "enforced": "enforced", + "org_public_id": "org_public_id", + "usage_limit": "usage_limit", + } + + def __init__( + self_, + enforced: Union[bool, none_type, UnsetType] = unset, + org_public_id: Union[str, none_type, UnsetType] = unset, + usage_limit: Union[int, none_type, UnsetType] = unset, + **kwargs, + ): + """ + Attributes to update on a usage quota. Omitting a property leaves its current value unchanged. + + :param enforced: Whether to actively block usage above the limit. Omit this field to leave the current enforcement setting unchanged. + :type enforced: bool, none_type, optional + + :param org_public_id: The public ID of the organization that already owns the quota. This is a consistency check and cannot move the quota to another organization. + :type org_public_id: str, none_type, optional + + :param usage_limit: The new quota limit in the usage units defined by the quota namespace. The limit cannot be lower than the usage already recorded in the current period. Omit this field to leave the current limit unchanged. + :type usage_limit: int, none_type, optional + """ + if enforced is not unset: + kwargs["enforced"] = enforced + if org_public_id is not unset: + kwargs["org_public_id"] = org_public_id + if usage_limit is not unset: + kwargs["usage_limit"] = usage_limit + super().__init__(kwargs) diff --git a/src/datadog_api_client/v2/model/usage_quota_update_data.py b/src/datadog_api_client/v2/model/usage_quota_update_data.py new file mode 100644 index 0000000000..d3e397cd34 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_update_data.py @@ -0,0 +1,54 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_update_attributes import UsageQuotaUpdateAttributes + from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType + + +class UsageQuotaUpdateData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_update_attributes import UsageQuotaUpdateAttributes + from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType + + return { + "attributes": (UsageQuotaUpdateAttributes,), + "id": (str,), + "type": (UsageQuotaType,), + } + + attribute_map = { + "attributes": "attributes", + "id": "id", + "type": "type", + } + + def __init__(self_, attributes: UsageQuotaUpdateAttributes, id: str, type: UsageQuotaType, **kwargs): + """ + A usage quota resource to update. + + :param attributes: Attributes to update on a usage quota. Omitting a property leaves its current value unchanged. + :type attributes: UsageQuotaUpdateAttributes + + :param id: The opaque usage quota identifier, which must match the identifier in the request path. + :type id: str + + :param type: The JSON:API resource type for a usage quota. + :type type: UsageQuotaType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.id = id + self_.type = type diff --git a/src/datadog_api_client/v2/model/usage_quota_update_request.py b/src/datadog_api_client/v2/model/usage_quota_update_request.py new file mode 100644 index 0000000000..44f0085739 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quota_update_request.py @@ -0,0 +1,40 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_update_data import UsageQuotaUpdateData + + +class UsageQuotaUpdateRequest(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_update_data import UsageQuotaUpdateData + + return { + "data": (UsageQuotaUpdateData,), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: UsageQuotaUpdateData, **kwargs): + """ + Request containing the usage quota resource to update. + + :param data: A usage quota resource to update. + :type data: UsageQuotaUpdateData + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/usage_quotas_create_request.py b/src/datadog_api_client/v2/model/usage_quotas_create_request.py new file mode 100644 index 0000000000..4727469283 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quotas_create_request.py @@ -0,0 +1,46 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import List, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_create_data import UsageQuotaCreateData + + +class UsageQuotasCreateRequest(ModelNormal): + validations = { + "data": { + "min_items": 1, + }, + } + + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_create_data import UsageQuotaCreateData + + return { + "data": ([UsageQuotaCreateData],), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: List[UsageQuotaCreateData], **kwargs): + """ + A JSON:API bulk request containing an array of usage quota resources rather than a single resource. + + :param data: A bulk list of usage quota resources to create or update by scope. + :type data: [UsageQuotaCreateData] + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/usage_quotas_list_response.py b/src/datadog_api_client/v2/model/usage_quotas_list_response.py new file mode 100644 index 0000000000..742cf83210 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quotas_list_response.py @@ -0,0 +1,49 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import List, Union, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + none_type, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData + from datadog_api_client.v2.model.usage_quotas_response_meta import UsageQuotasResponseMeta + + +class UsageQuotasListResponse(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData + from datadog_api_client.v2.model.usage_quotas_response_meta import UsageQuotasResponseMeta + + return { + "data": ([UsageQuotaResponseData],), + "meta": (UsageQuotasResponseMeta,), + } + + attribute_map = { + "data": "data", + "meta": "meta", + } + + def __init__(self_, data: List[UsageQuotaResponseData], meta: Union[UsageQuotasResponseMeta, none_type], **kwargs): + """ + Response containing a paginated list of usage quotas. + + :param data: A list of usage quota resources. + :type data: [UsageQuotaResponseData] + + :param meta: Pagination metadata for a usage quota list response. This field may be omitted when no pagination metadata is available. + :type meta: UsageQuotasResponseMeta, none_type + """ + super().__init__(kwargs) + + self_.data = data + self_.meta = meta diff --git a/src/datadog_api_client/v2/model/usage_quotas_response.py b/src/datadog_api_client/v2/model/usage_quotas_response.py new file mode 100644 index 0000000000..d13f9d6885 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quotas_response.py @@ -0,0 +1,40 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import List, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData + + +class UsageQuotasResponse(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData + + return { + "data": ([UsageQuotaResponseData],), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: List[UsageQuotaResponseData], **kwargs): + """ + Response containing a list of usage quotas. + + :param data: A list of usage quota resources. + :type data: [UsageQuotaResponseData] + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/usage_quotas_response_meta.py b/src/datadog_api_client/v2/model/usage_quotas_response_meta.py new file mode 100644 index 0000000000..86565761c7 --- /dev/null +++ b/src/datadog_api_client/v2/model/usage_quotas_response_meta.py @@ -0,0 +1,37 @@ +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019-Present Datadog, Inc. +from __future__ import annotations + +from typing import Union + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + none_type, +) + + +class UsageQuotasResponseMeta(ModelNormal): + _nullable = True + + @cached_property + def openapi_types(_): + return { + "next_cursor": (str, none_type), + } + + attribute_map = { + "next_cursor": "next_cursor", + } + + def __init__(self_, next_cursor: Union[str, none_type], **kwargs): + """ + Pagination metadata for a usage quota list response. This field may be omitted when no pagination metadata is available. + + :param next_cursor: An opaque cursor for retrieving the next page. This field may be omitted or null when there are no more results. + :type next_cursor: str, none_type + """ + super().__init__(kwargs) + + self_.next_cursor = next_cursor diff --git a/src/datadog_api_client/v2/models/__init__.py b/src/datadog_api_client/v2/models/__init__.py index d5bf0573c2..9ec3d8ca83 100644 --- a/src/datadog_api_client/v2/models/__init__.py +++ b/src/datadog_api_client/v2/models/__init__.py @@ -10352,6 +10352,21 @@ from datadog_api_client.v2.model.usage_data_object import UsageDataObject from datadog_api_client.v2.model.usage_lambda_traced_invocations_response import UsageLambdaTracedInvocationsResponse from datadog_api_client.v2.model.usage_observability_pipelines_response import UsageObservabilityPipelinesResponse +from datadog_api_client.v2.model.usage_quota_create_attributes import UsageQuotaCreateAttributes +from datadog_api_client.v2.model.usage_quota_create_data import UsageQuotaCreateData +from datadog_api_client.v2.model.usage_quota_request_scope import UsageQuotaRequestScope +from datadog_api_client.v2.model.usage_quota_response import UsageQuotaResponse +from datadog_api_client.v2.model.usage_quota_response_attributes import UsageQuotaResponseAttributes +from datadog_api_client.v2.model.usage_quota_response_data import UsageQuotaResponseData +from datadog_api_client.v2.model.usage_quota_response_scope import UsageQuotaResponseScope +from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType +from datadog_api_client.v2.model.usage_quota_update_attributes import UsageQuotaUpdateAttributes +from datadog_api_client.v2.model.usage_quota_update_data import UsageQuotaUpdateData +from datadog_api_client.v2.model.usage_quota_update_request import UsageQuotaUpdateRequest +from datadog_api_client.v2.model.usage_quotas_create_request import UsageQuotasCreateRequest +from datadog_api_client.v2.model.usage_quotas_list_response import UsageQuotasListResponse +from datadog_api_client.v2.model.usage_quotas_response import UsageQuotasResponse +from datadog_api_client.v2.model.usage_quotas_response_meta import UsageQuotasResponseMeta from datadog_api_client.v2.model.usage_summary_available_fields_attributes import UsageSummaryAvailableFieldsAttributes from datadog_api_client.v2.model.usage_summary_available_fields_body import UsageSummaryAvailableFieldsBody from datadog_api_client.v2.model.usage_summary_available_fields_response import UsageSummaryAvailableFieldsResponse @@ -17811,6 +17826,21 @@ "UsageDataObject", "UsageLambdaTracedInvocationsResponse", "UsageObservabilityPipelinesResponse", + "UsageQuotaCreateAttributes", + "UsageQuotaCreateData", + "UsageQuotaRequestScope", + "UsageQuotaResponse", + "UsageQuotaResponseAttributes", + "UsageQuotaResponseData", + "UsageQuotaResponseScope", + "UsageQuotaType", + "UsageQuotaUpdateAttributes", + "UsageQuotaUpdateData", + "UsageQuotaUpdateRequest", + "UsageQuotasCreateRequest", + "UsageQuotasListResponse", + "UsageQuotasResponse", + "UsageQuotasResponseMeta", "UsageSummaryAvailableFieldsAttributes", "UsageSummaryAvailableFieldsBody", "UsageSummaryAvailableFieldsResponse", diff --git a/tests/v2/features/undo.json b/tests/v2/features/undo.json index 870f4e34a5..f78a571d68 100644 --- a/tests/v2/features/undo.json +++ b/tests/v2/features/undo.json @@ -9883,6 +9883,30 @@ "type": "safe" } }, + "ListQuotas": { + "tag": "Usage Metering", + "undo": { + "type": "safe" + } + }, + "CreateOrUpdateQuotas": { + "tag": "Usage Metering", + "undo": { + "type": "idempotent" + } + }, + "DeleteQuota": { + "tag": "Usage Metering", + "undo": { + "type": "idempotent" + } + }, + "UpdateQuota": { + "tag": "Usage Metering", + "undo": { + "type": "idempotent" + } + }, "GetUsageSummaryAvailableFields": { "tag": "Usage Metering", "undo": { diff --git a/tests/v2/features/usage_metering.feature b/tests/v2/features/usage_metering.feature index ca4cfbd670..cfca4bbac9 100644 --- a/tests/v2/features/usage_metering.feature +++ b/tests/v2/features/usage_metering.feature @@ -14,6 +14,42 @@ Feature: Usage Metering And a valid "appKeyAuth" key in the system And an instance of "UsageMetering" API + @generated @skip @team:DataDog/billing-hub + Scenario: Create or update usage quotas returns "Bad Request" response + Given operation "CreateOrUpdateQuotas" enabled + And new "CreateOrUpdateQuotas" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And body with value {"data": [{"attributes": {"enforced": true, "org_public_id": "abcdef12345", "scope": {"user_handle": "jane@example.com"}, "usage_limit": 100000}, "type": "quota"}]} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/billing-hub + Scenario: Create or update usage quotas returns "OK" response + Given operation "CreateOrUpdateQuotas" enabled + And new "CreateOrUpdateQuotas" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And body with value {"data": [{"attributes": {"enforced": true, "org_public_id": "abcdef12345", "scope": {"user_handle": "jane@example.com"}, "usage_limit": 100000}, "type": "quota"}]} + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/billing-hub + Scenario: Delete a usage quota returns "No Content" response + Given operation "DeleteQuota" enabled + And new "DeleteQuota" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 204 No Content + + @generated @skip @team:DataDog/billing-hub + Scenario: Delete a usage quota returns "Not Found" response + Given operation "DeleteQuota" enabled + And new "DeleteQuota" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And request contains "id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + @replay-only @team:DataDog/billing-hub Scenario: Get Monthly Cost Attribution returns "Bad Request" response Given new "GetMonthlyCostAttribution" request @@ -242,3 +278,57 @@ Feature: Usage Metering And request contains "start_month" parameter with value "{{ timeISO('now') }}" When the request is sent Then the response status is 200 OK + + @generated @skip @team:DataDog/billing-hub + Scenario: List usage quotas returns "Bad Request" response + Given operation "ListQuotas" enabled + And new "ListQuotas" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/billing-hub + Scenario: List usage quotas returns "OK" response + Given operation "ListQuotas" enabled + And new "ListQuotas" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/billing-hub @with-pagination + Scenario: List usage quotas returns "OK" response with pagination + Given operation "ListQuotas" enabled + And new "ListQuotas" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + When the request with pagination is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/billing-hub + Scenario: Update a usage quota returns "Bad Request" response + Given operation "UpdateQuota" enabled + And new "UpdateQuota" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"enforced": false, "org_public_id": "abcdef12345", "usage_limit": 120000}, "id": "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", "type": "quota"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/billing-hub + Scenario: Update a usage quota returns "Not Found" response + Given operation "UpdateQuota" enabled + And new "UpdateQuota" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"enforced": false, "org_public_id": "abcdef12345", "usage_limit": 120000}, "id": "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", "type": "quota"}} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/billing-hub + Scenario: Update a usage quota returns "OK" response + Given operation "UpdateQuota" enabled + And new "UpdateQuota" request + And request contains "quota_namespace" parameter from "REPLACE.ME" + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"enforced": false, "org_public_id": "abcdef12345", "usage_limit": 120000}, "id": "MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", "type": "quota"}} + When the request is sent + Then the response status is 200 OK