diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 1e1724d2f..48ab737de 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -98062,6 +98062,414 @@ components: format: int64 type: integer type: object + TagPoliciesListResponse: + description: A page of tag policies. + properties: + data: + $ref: "#/components/schemas/TagPolicyDataArray" + included: + $ref: "#/components/schemas/TagPolicyIncludedResources" + required: + - data + type: object + TagPolicyAttributes: + description: The attributes of a tag policy resource. + properties: + created_at: + description: The RFC 3339 timestamp at which the policy was created. + example: "2026-05-21T22:11:06.108696Z" + format: date-time + type: string + created_by: + description: The identifier of the user who created the policy. + example: "test-user" + type: string + deleted_at: + description: The RFC 3339 timestamp at which the policy was soft-deleted. `null` if the policy has not been deleted. Only present when `include_deleted=true` is requested. + format: date-time + nullable: true + type: string + deleted_by: + description: The identifier of the user who soft-deleted the policy. `null` if the policy has not been deleted. + nullable: true + type: string + enabled: + description: Whether the policy is currently enforced. + example: true + type: boolean + modified_at: + description: The RFC 3339 timestamp at which the policy was last modified. + example: "2026-05-21T22:11:06.108696Z" + format: date-time + type: string + modified_by: + description: The identifier of the user who last modified the policy. + example: "test-user" + type: string + negated: + description: When `true`, the policy matches tag values that do NOT match any of the supplied patterns. + example: false + type: boolean + policy_name: + description: Human-readable name for the tag policy. + example: "Service tag must be one of api or web" + type: string + policy_type: + $ref: "#/components/schemas/TagPolicyType" + required: + description: When `true`, telemetry without this tag is treated as a violation. + example: true + type: boolean + scope: + description: The scope the policy applies within. + example: "env" + type: string + source: + $ref: "#/components/schemas/TagPolicySource" + tag_key: + description: The tag key that the policy governs. + example: "service" + type: string + tag_value_patterns: + description: The patterns that valid values for the tag key must match. + example: + - "api" + - "web" + items: + description: A pattern that valid tag values must match. + type: string + type: array + version: + description: A monotonically increasing version counter that is incremented on each update. + example: 1 + format: int64 + type: integer + required: + - policy_name + - source + - scope + - tag_key + - tag_value_patterns + - negated + - required + - enabled + - policy_type + - version + - created_at + - created_by + - modified_at + - modified_by + type: object + TagPolicyCreateAttributes: + description: Attributes that can be supplied when creating a tag policy. + properties: + enabled: + description: Whether the policy is currently enforced. Defaults to `true` for newly created policies. + example: true + type: boolean + negated: + description: When `true`, the policy matches tag values that do NOT match any of the supplied patterns. Defaults to `false`. + example: false + type: boolean + policy_name: + description: Human-readable name for the tag policy. + example: "Service tag must be one of api or web" + type: string + policy_type: + $ref: "#/components/schemas/TagPolicyCreateType" + required: + description: When `true`, telemetry without this tag is treated as a violation. Defaults to `false`. + example: true + type: boolean + scope: + description: |- + The scope the policy applies within. Typically an environment, team, or + organization-level identifier used to limit where the policy is enforced. + example: "env" + type: string + source: + $ref: "#/components/schemas/TagPolicySource" + tag_key: + description: The tag key that the policy governs (for example, `service`). + example: "service" + type: string + tag_value_patterns: + description: |- + One or more patterns that valid values for the tag key must match. At least one + pattern is required. + example: + - "api" + - "web" + items: + description: A pattern that valid tag values must match. + type: string + minItems: 1 + type: array + required: + - policy_name + - source + - scope + - tag_key + - tag_value_patterns + - policy_type + type: object + TagPolicyCreateData: + description: Data object for creating a tag policy. + properties: + attributes: + $ref: "#/components/schemas/TagPolicyCreateAttributes" + type: + $ref: "#/components/schemas/TagPolicyResourceType" + required: + - type + - attributes + type: object + TagPolicyCreateRequest: + description: Payload for creating a new tag policy. + properties: + data: + $ref: "#/components/schemas/TagPolicyCreateData" + required: + - data + type: object + TagPolicyCreateType: + description: |- + The policy type allowed when creating a tag policy. Only `surfacing` is accepted at + creation time. + enum: + - surfacing + example: "surfacing" + type: string + x-enum-varnames: + - SURFACING + TagPolicyData: + description: A tag policy resource. + properties: + attributes: + $ref: "#/components/schemas/TagPolicyAttributes" + id: + description: The unique identifier of the tag policy. + example: "123" + type: string + relationships: + $ref: "#/components/schemas/TagPolicyRelationships" + type: + $ref: "#/components/schemas/TagPolicyResourceType" + required: + - type + - id + - attributes + type: object + TagPolicyDataArray: + description: An array of tag policy data objects. + items: + $ref: "#/components/schemas/TagPolicyData" + type: array + TagPolicyInclude: + description: A related resource to include alongside a tag policy in the response. Currently the only supported value is `score`. + enum: + - score + example: "score" + type: string + x-enum-varnames: + - SCORE + TagPolicyIncludedResources: + description: Related resources fetched alongside the primary tag policies. Populated when an `include` query parameter is supplied. + items: + $ref: "#/components/schemas/TagPolicyScoreData" + type: array + TagPolicyRelationships: + description: Related resources for a tag policy. Only present when the corresponding `include` query parameter is supplied. + properties: + score: + $ref: "#/components/schemas/TagPolicyScoreRelationship" + type: object + TagPolicyResourceType: + description: JSON:API resource type for a tag policy. + enum: + - tag_policy + example: "tag_policy" + type: string + x-enum-varnames: + - TAG_POLICY + TagPolicyResponse: + description: A single tag policy. + properties: + data: + $ref: "#/components/schemas/TagPolicyData" + included: + $ref: "#/components/schemas/TagPolicyIncludedResources" + required: + - data + type: object + TagPolicyScoreAttributes: + description: Attributes of a tag policy compliance score. + properties: + score: + description: |- + The compliance score for the policy over the requested time window, as a percentage + between 0 and 100. `null` indicates that no relevant telemetry was found. + example: 80 + format: double + nullable: true + type: number + ts_end: + description: End of the time window the score was computed over, as a Unix timestamp in milliseconds. + example: 1779401466097 + format: int64 + type: integer + ts_start: + description: Start of the time window the score was computed over, as a Unix timestamp in milliseconds. + example: 1779315066097 + format: int64 + type: integer + version: + description: The version of the tag policy that the score was computed against. + example: 1 + format: int64 + type: integer + required: + - score + - ts_start + - ts_end + - version + type: object + TagPolicyScoreData: + description: A compliance score resource for a tag policy. + properties: + attributes: + $ref: "#/components/schemas/TagPolicyScoreAttributes" + id: + description: The unique identifier of the compliance score resource. + example: "123-v1-1779315066097-1779401466097" + type: string + type: + $ref: "#/components/schemas/TagPolicyScoreResourceType" + required: + - type + - id + - attributes + type: object + TagPolicyScoreRelationship: + description: A relationship to the compliance score resource for this policy. + properties: + data: + $ref: "#/components/schemas/TagPolicyScoreRelationshipData" + required: + - data + type: object + TagPolicyScoreRelationshipData: + description: Identifier of the related compliance score resource. + properties: + id: + description: The unique identifier of the related compliance score resource. + example: "123-v1-1779315066097-1779401466097" + type: string + type: + $ref: "#/components/schemas/TagPolicyScoreResourceType" + required: + - type + - id + type: object + TagPolicyScoreResourceType: + description: JSON:API resource type for a tag policy compliance score. + enum: + - tag_policy_score + example: "tag_policy_score" + type: string + x-enum-varnames: + - TAG_POLICY_SCORE + TagPolicyScoreResponse: + description: A tag policy compliance score. + properties: + data: + $ref: "#/components/schemas/TagPolicyScoreData" + required: + - data + type: object + TagPolicySource: + description: The telemetry source that a tag policy applies to. + enum: + - logs + - spans + - metrics + - rum + - feed + example: "logs" + type: string + x-enum-varnames: + - LOGS + - SPANS + - METRICS + - RUM + - FEED + TagPolicyType: + description: |- + How the policy is enforced. `blocking` rejects telemetry that violates the policy. + `surfacing` only highlights non-compliant telemetry without blocking it. + enum: + - blocking + - surfacing + example: "surfacing" + type: string + x-enum-varnames: + - BLOCKING + - SURFACING + TagPolicyUpdateAttributes: + description: |- + Mutable attributes of a tag policy. Each field is optional; omitting a field leaves its + current value unchanged. The `source` of a policy cannot be changed. + properties: + enabled: + description: Whether the policy is currently enforced. + type: boolean + negated: + description: When `true`, the policy matches tag values that do NOT match any of the supplied patterns. + type: boolean + policy_name: + description: Human-readable name for the tag policy. + type: string + policy_type: + $ref: "#/components/schemas/TagPolicyType" + required: + description: When `true`, telemetry without this tag is treated as a violation. + type: boolean + scope: + description: The scope the policy applies within. + type: string + tag_key: + description: The tag key that the policy governs. + type: string + tag_value_patterns: + description: One or more patterns that valid values for the tag key must match. + items: + description: A pattern that valid tag values must match. + type: string + type: array + type: object + TagPolicyUpdateData: + description: Data object for updating a tag policy. + properties: + attributes: + $ref: "#/components/schemas/TagPolicyUpdateAttributes" + id: + description: The unique identifier of the tag policy being updated. + example: "123" + type: string + type: + $ref: "#/components/schemas/TagPolicyResourceType" + required: + - type + - id + type: object + TagPolicyUpdateRequest: + description: Payload for updating an existing tag policy. Only the supplied fields are modified. + properties: + data: + $ref: "#/components/schemas/TagPolicyUpdateData" + required: + - data + type: object TagsEventAttribute: description: Array of tags associated with your event. example: ["team:A"] @@ -182595,6 +183003,559 @@ paths: operator: OR permissions: - synthetics_global_variable_write + /api/v2/tag-policies: + get: + description: |- + Retrieve all tag policies for the organization. Optionally include disabled or deleted + policies, filter by telemetry source, and include each policy's current compliance score + via the `include=score` query parameter. + operationId: ListTagPolicies + parameters: + - description: Whether to include policies that are currently disabled. Defaults to `false`. + example: false + in: query + name: include_disabled + required: false + schema: + type: boolean + - description: Whether to include policies that have been soft-deleted. Defaults to `false`. + example: false + in: query + name: include_deleted + required: false + schema: + type: boolean + - description: Comma-separated list of related resources to include alongside each policy in the response. Currently the only supported value is `score`. + example: "score" + in: query + name: include + required: false + schema: + $ref: "#/components/schemas/TagPolicyInclude" + - description: Restrict the result set to policies whose source matches the given value. + in: query + name: filter[source] + required: false + schema: + $ref: "#/components/schemas/TagPolicySource" + - description: Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Defaults to a recent window appropriate for the source. + example: 1779315066097 + in: query + name: ts_start + required: false + schema: + format: int64 + type: integer + - description: End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + example: 1779401466097 + in: query + name: ts_end + required: false + schema: + format: int64 + type: integer + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + created_at: "2026-05-21T22:11:06.108696Z" + created_by: "test-user" + enabled: true + modified_at: "2026-05-21T22:11:06.108696Z" + modified_by: "test-user" + negated: false + policy_name: "Service tag must be one of api or web" + policy_type: "surfacing" + required: true + scope: "env" + source: "logs" + tag_key: "service" + tag_value_patterns: + - "api" + - "web" + version: 1 + id: "123" + relationships: + score: + data: + id: "123-v1-1779315066097-1779401466097" + type: "tag_policy_score" + type: "tag_policy" + included: + - attributes: + score: 80 + ts_end: 1779401466097 + ts_start: 1779315066097 + version: 1 + id: "123-v1-1779315066097-1779401466097" + type: "tag_policy_score" + schema: + $ref: "#/components/schemas/TagPoliciesListResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: List tag policies + tags: + - Tag Policies + 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: |- + Create a new tag policy for the organization. The caller's organization is derived from + the authenticated user; cross-organization creation is not supported. Fields such as + `policy_id`, `version`, and the timestamp/audit fields are assigned by the server. + operationId: CreateTagPolicy + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + enabled: true + negated: false + policy_name: "Service tag must be one of api or web" + policy_type: "surfacing" + required: true + scope: "env" + source: "logs" + tag_key: "service" + tag_value_patterns: + - "api" + - "web" + type: "tag_policy" + schema: + $ref: "#/components/schemas/TagPolicyCreateRequest" + required: true + responses: + "201": + content: + application/json: + examples: + default: + value: + data: + attributes: + created_at: "2026-05-21T22:11:06.108696Z" + created_by: "test-user" + enabled: true + modified_at: "2026-05-21T22:11:06.108696Z" + modified_by: "test-user" + negated: false + policy_name: "Service tag must be one of api or web" + policy_type: "surfacing" + required: true + scope: "env" + source: "logs" + tag_key: "service" + tag_value_patterns: + - "api" + - "web" + version: 1 + id: "123" + type: "tag_policy" + schema: + $ref: "#/components/schemas/TagPolicyResponse" + description: Created + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "409": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Conflict + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Create a tag policy + tags: + - Tag Policies + 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/tag-policies/{policy_id}: + delete: + description: |- + Delete a tag policy. By default the policy is soft-deleted so it can be recovered later + and so that historical score data remains queryable. Pass `hard_delete=true` to remove + the policy permanently. + operationId: DeleteTagPolicy + parameters: + - description: The unique identifier of the tag policy to delete. + example: "123" + in: path + name: policy_id + required: true + schema: + type: string + - description: Whether to permanently delete the policy instead of performing a soft delete. Defaults to `false`. + example: false + in: query + name: hard_delete + required: false + schema: + type: boolean + responses: + "204": + description: No Content + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "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" + summary: Delete a tag policy + tags: + - Tag Policies + 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/). + get: + description: |- + Retrieve a single tag policy by ID. Optionally include the policy's current compliance + score via the `include=score` query parameter. Policies belonging to other organizations + cannot be retrieved. + operationId: GetTagPolicy + parameters: + - description: The unique identifier of the tag policy. + example: "123" + in: path + name: policy_id + required: true + schema: + type: string + - description: Comma-separated list of related resources to include alongside the policy. Currently the only supported value is `score`. + example: "score" + in: query + name: include + required: false + schema: + $ref: "#/components/schemas/TagPolicyInclude" + - description: Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. + example: 1779315066097 + in: query + name: ts_start + required: false + schema: + format: int64 + type: integer + - description: End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + example: 1779401466097 + in: query + name: ts_end + required: false + schema: + format: int64 + type: integer + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + created_at: "2026-05-21T22:11:06.108696Z" + created_by: "test-user" + enabled: true + modified_at: "2026-05-21T22:11:06.108696Z" + modified_by: "test-user" + negated: false + policy_name: "Service tag must be one of api or web" + policy_type: "surfacing" + required: true + scope: "env" + source: "logs" + tag_key: "service" + tag_value_patterns: + - "api" + - "web" + version: 1 + id: "123" + relationships: + score: + data: + id: "123-v1-1779315066097-1779401466097" + type: "tag_policy_score" + type: "tag_policy" + included: + - attributes: + score: 80 + ts_end: 1779401466097 + ts_start: 1779315066097 + version: 1 + id: "123-v1-1779315066097-1779401466097" + type: "tag_policy_score" + schema: + $ref: "#/components/schemas/TagPolicyResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "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" + summary: Get a tag policy + tags: + - Tag Policies + 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: |- + Update one or more attributes of an existing tag policy. Only the fields supplied in the + request body are modified; omitted fields retain their current values. The policy's + `source` cannot be changed after creation. + operationId: UpdateTagPolicy + parameters: + - description: The unique identifier of the tag policy to update. + example: "123" + in: path + name: policy_id + required: true + schema: + type: string + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + enabled: true + policy_name: "Service tag must be one of api, web, or worker" + id: "123" + type: "tag_policy" + schema: + $ref: "#/components/schemas/TagPolicyUpdateRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + created_at: "2026-05-21T22:11:06.108696Z" + created_by: "test-user" + enabled: true + modified_at: "2026-05-21T22:25:01.000000Z" + modified_by: "test-user" + negated: false + policy_name: "Service tag must be one of api, web, or worker" + policy_type: "surfacing" + required: true + scope: "env" + source: "logs" + tag_key: "service" + tag_value_patterns: + - "api" + - "web" + version: 2 + id: "123" + type: "tag_policy" + schema: + $ref: "#/components/schemas/TagPolicyResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "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" + summary: Update a tag policy + tags: + - Tag Policies + 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/tag-policies/{policy_id}/score: + get: + description: |- + Retrieve the compliance score for a single tag policy. The score is computed over the + requested time window (or a source-appropriate default) and represents the percentage of + telemetry within that window that conforms to the policy. A `null` score indicates that + no relevant telemetry was found. + operationId: GetTagPolicyScore + parameters: + - description: The unique identifier of the tag policy. + example: "123" + in: path + name: policy_id + required: true + schema: + type: string + - description: Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. + example: 1779315066097 + in: query + name: ts_start + required: false + schema: + format: int64 + type: integer + - description: End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + example: 1779401466097 + in: query + name: ts_end + required: false + schema: + format: int64 + type: integer + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + score: 80 + ts_end: 1779401466097 + ts_start: 1779315066097 + version: 1 + id: "123-v1-1779315066097-1779401466097" + type: "tag_policy_score" + schema: + $ref: "#/components/schemas/TagPolicyScoreResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "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" + summary: Get a tag policy compliance score + tags: + - Tag Policies + 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/tags/enrichment: get: description: List all tag pipeline rulesets - Retrieve a list of all tag pipeline rulesets for the organization @@ -188558,6 +189519,13 @@ tags: You can use the Datadog API to create, manage, and organize tests and test suites programmatically. For more information, see the [Synthetic Monitoring documentation](https://docs.datadoghq.com/synthetics/). name: Synthetics + - description: |- + Tag Policies define rules that govern which tag values are accepted for a given tag key, + scoped to a particular telemetry source (such as logs, spans, or metrics). Policies can be + `blocking` (data not matching the policy is rejected) or `surfacing` (matching data is + highlighted but not blocked). Each policy reports a compliance `score` derived from how + much recent telemetry adheres to the policy. + name: Tag Policies - description: View and manage teams within Datadog. See the [Teams page](https://docs.datadoghq.com/account_management/teams/) for more information. name: Teams - description: |- diff --git a/examples/v2_tag-policies_CreateTagPolicy.rs b/examples/v2_tag-policies_CreateTagPolicy.rs new file mode 100644 index 000000000..74779fdb6 --- /dev/null +++ b/examples/v2_tag-policies_CreateTagPolicy.rs @@ -0,0 +1,36 @@ +// Create a tag policy returns "Created" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_tag_policies::TagPoliciesAPI; +use datadog_api_client::datadogV2::model::TagPolicyCreateAttributes; +use datadog_api_client::datadogV2::model::TagPolicyCreateData; +use datadog_api_client::datadogV2::model::TagPolicyCreateRequest; +use datadog_api_client::datadogV2::model::TagPolicyCreateType; +use datadog_api_client::datadogV2::model::TagPolicyResourceType; +use datadog_api_client::datadogV2::model::TagPolicySource; + +#[tokio::main] +async fn main() { + let body = TagPolicyCreateRequest::new(TagPolicyCreateData::new( + TagPolicyCreateAttributes::new( + "Service tag must be one of api or web".to_string(), + TagPolicyCreateType::SURFACING, + "env".to_string(), + TagPolicySource::LOGS, + "service".to_string(), + vec!["api".to_string(), "web".to_string()], + ) + .enabled(true) + .negated(false) + .required(true), + TagPolicyResourceType::TAG_POLICY, + )); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.CreateTagPolicy", true); + let api = TagPoliciesAPI::with_config(configuration); + let resp = api.create_tag_policy(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_tag-policies_DeleteTagPolicy.rs b/examples/v2_tag-policies_DeleteTagPolicy.rs new file mode 100644 index 000000000..61aa79513 --- /dev/null +++ b/examples/v2_tag-policies_DeleteTagPolicy.rs @@ -0,0 +1,22 @@ +// Delete a tag policy returns "No Content" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_tag_policies::DeleteTagPolicyOptionalParams; +use datadog_api_client::datadogV2::api_tag_policies::TagPoliciesAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.DeleteTagPolicy", true); + let api = TagPoliciesAPI::with_config(configuration); + let resp = api + .delete_tag_policy( + "policy_id".to_string(), + DeleteTagPolicyOptionalParams::default(), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_tag-policies_GetTagPolicy.rs b/examples/v2_tag-policies_GetTagPolicy.rs new file mode 100644 index 000000000..239948dd9 --- /dev/null +++ b/examples/v2_tag-policies_GetTagPolicy.rs @@ -0,0 +1,22 @@ +// Get a tag policy returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_tag_policies::GetTagPolicyOptionalParams; +use datadog_api_client::datadogV2::api_tag_policies::TagPoliciesAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetTagPolicy", true); + let api = TagPoliciesAPI::with_config(configuration); + let resp = api + .get_tag_policy( + "policy_id".to_string(), + GetTagPolicyOptionalParams::default(), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_tag-policies_GetTagPolicyScore.rs b/examples/v2_tag-policies_GetTagPolicyScore.rs new file mode 100644 index 000000000..e41046366 --- /dev/null +++ b/examples/v2_tag-policies_GetTagPolicyScore.rs @@ -0,0 +1,22 @@ +// Get a tag policy compliance score returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_tag_policies::GetTagPolicyScoreOptionalParams; +use datadog_api_client::datadogV2::api_tag_policies::TagPoliciesAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetTagPolicyScore", true); + let api = TagPoliciesAPI::with_config(configuration); + let resp = api + .get_tag_policy_score( + "policy_id".to_string(), + GetTagPolicyScoreOptionalParams::default(), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_tag-policies_ListTagPolicies.rs b/examples/v2_tag-policies_ListTagPolicies.rs new file mode 100644 index 000000000..8c86a1342 --- /dev/null +++ b/examples/v2_tag-policies_ListTagPolicies.rs @@ -0,0 +1,19 @@ +// List tag policies returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_tag_policies::ListTagPoliciesOptionalParams; +use datadog_api_client::datadogV2::api_tag_policies::TagPoliciesAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListTagPolicies", true); + let api = TagPoliciesAPI::with_config(configuration); + let resp = api + .list_tag_policies(ListTagPoliciesOptionalParams::default()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_tag-policies_UpdateTagPolicy.rs b/examples/v2_tag-policies_UpdateTagPolicy.rs new file mode 100644 index 000000000..10f7335d4 --- /dev/null +++ b/examples/v2_tag-policies_UpdateTagPolicy.rs @@ -0,0 +1,28 @@ +// Update a tag policy returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_tag_policies::TagPoliciesAPI; +use datadog_api_client::datadogV2::model::TagPolicyResourceType; +use datadog_api_client::datadogV2::model::TagPolicyType; +use datadog_api_client::datadogV2::model::TagPolicyUpdateAttributes; +use datadog_api_client::datadogV2::model::TagPolicyUpdateData; +use datadog_api_client::datadogV2::model::TagPolicyUpdateRequest; + +#[tokio::main] +async fn main() { + let body = TagPolicyUpdateRequest::new( + TagPolicyUpdateData::new("123".to_string(), TagPolicyResourceType::TAG_POLICY).attributes( + TagPolicyUpdateAttributes::new() + .policy_type(TagPolicyType::SURFACING) + .tag_value_patterns(vec![]), + ), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.UpdateTagPolicy", true); + let api = TagPoliciesAPI::with_config(configuration); + let resp = api.update_tag_policy("policy_id".to_string(), body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index ea2c8fd0a..9f7c50a77 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -700,6 +700,12 @@ impl Default for Configuration { ("v2.revert_custom_rule_revision".to_owned(), false), ("v2.update_ai_custom_ruleset".to_owned(), false), ("v2.update_custom_ruleset".to_owned(), false), + ("v2.create_tag_policy".to_owned(), false), + ("v2.delete_tag_policy".to_owned(), false), + ("v2.get_tag_policy".to_owned(), false), + ("v2.get_tag_policy_score".to_owned(), false), + ("v2.list_tag_policies".to_owned(), false), + ("v2.update_tag_policy".to_owned(), false), ("v2.add_member_team".to_owned(), false), ("v2.list_member_teams".to_owned(), false), ("v2.remove_member_team".to_owned(), false), diff --git a/src/datadogV2/api/api_tag_policies.rs b/src/datadogV2/api/api_tag_policies.rs new file mode 100644 index 000000000..413745f91 --- /dev/null +++ b/src/datadogV2/api/api_tag_policies.rs @@ -0,0 +1,1139 @@ +// 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. +use crate::datadog; +use flate2::{ + write::{GzEncoder, ZlibEncoder}, + Compression, +}; +use log::warn; +use reqwest::header::{HeaderMap, HeaderValue}; +use serde::{Deserialize, Serialize}; +use std::io::Write; + +/// DeleteTagPolicyOptionalParams is a struct for passing parameters to the method [`TagPoliciesAPI::delete_tag_policy`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct DeleteTagPolicyOptionalParams { + /// Whether to permanently delete the policy instead of performing a soft delete. Defaults to `false`. + pub hard_delete: Option, +} + +impl DeleteTagPolicyOptionalParams { + /// Whether to permanently delete the policy instead of performing a soft delete. Defaults to `false`. + pub fn hard_delete(mut self, value: bool) -> Self { + self.hard_delete = Some(value); + self + } +} + +/// GetTagPolicyOptionalParams is a struct for passing parameters to the method [`TagPoliciesAPI::get_tag_policy`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct GetTagPolicyOptionalParams { + /// Comma-separated list of related resources to include alongside the policy. Currently the only supported value is `score`. + pub include: Option, + /// Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. + pub ts_start: Option, + /// End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + pub ts_end: Option, +} + +impl GetTagPolicyOptionalParams { + /// Comma-separated list of related resources to include alongside the policy. Currently the only supported value is `score`. + pub fn include(mut self, value: crate::datadogV2::model::TagPolicyInclude) -> Self { + self.include = Some(value); + self + } + /// Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. + pub fn ts_start(mut self, value: i64) -> Self { + self.ts_start = Some(value); + self + } + /// End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + pub fn ts_end(mut self, value: i64) -> Self { + self.ts_end = Some(value); + self + } +} + +/// GetTagPolicyScoreOptionalParams is a struct for passing parameters to the method [`TagPoliciesAPI::get_tag_policy_score`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct GetTagPolicyScoreOptionalParams { + /// Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. + pub ts_start: Option, + /// End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + pub ts_end: Option, +} + +impl GetTagPolicyScoreOptionalParams { + /// Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. + pub fn ts_start(mut self, value: i64) -> Self { + self.ts_start = Some(value); + self + } + /// End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + pub fn ts_end(mut self, value: i64) -> Self { + self.ts_end = Some(value); + self + } +} + +/// ListTagPoliciesOptionalParams is a struct for passing parameters to the method [`TagPoliciesAPI::list_tag_policies`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct ListTagPoliciesOptionalParams { + /// Whether to include policies that are currently disabled. Defaults to `false`. + pub include_disabled: Option, + /// Whether to include policies that have been soft-deleted. Defaults to `false`. + pub include_deleted: Option, + /// Comma-separated list of related resources to include alongside each policy in the response. Currently the only supported value is `score`. + pub include: Option, + /// Restrict the result set to policies whose source matches the given value. + pub filter_source: Option, + /// Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Defaults to a recent window appropriate for the source. + pub ts_start: Option, + /// End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + pub ts_end: Option, +} + +impl ListTagPoliciesOptionalParams { + /// Whether to include policies that are currently disabled. Defaults to `false`. + pub fn include_disabled(mut self, value: bool) -> Self { + self.include_disabled = Some(value); + self + } + /// Whether to include policies that have been soft-deleted. Defaults to `false`. + pub fn include_deleted(mut self, value: bool) -> Self { + self.include_deleted = Some(value); + self + } + /// Comma-separated list of related resources to include alongside each policy in the response. Currently the only supported value is `score`. + pub fn include(mut self, value: crate::datadogV2::model::TagPolicyInclude) -> Self { + self.include = Some(value); + self + } + /// Restrict the result set to policies whose source matches the given value. + pub fn filter_source(mut self, value: crate::datadogV2::model::TagPolicySource) -> Self { + self.filter_source = Some(value); + self + } + /// Start of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Defaults to a recent window appropriate for the source. + pub fn ts_start(mut self, value: i64) -> Self { + self.ts_start = Some(value); + self + } + /// End of the time window used for compliance score computation, as a Unix timestamp in milliseconds. Must be in the past and greater than `ts_start`. + pub fn ts_end(mut self, value: i64) -> Self { + self.ts_end = Some(value); + self + } +} + +/// CreateTagPolicyError is a struct for typed errors of method [`TagPoliciesAPI::create_tag_policy`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateTagPolicyError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// DeleteTagPolicyError is a struct for typed errors of method [`TagPoliciesAPI::delete_tag_policy`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteTagPolicyError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetTagPolicyError is a struct for typed errors of method [`TagPoliciesAPI::get_tag_policy`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetTagPolicyError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetTagPolicyScoreError is a struct for typed errors of method [`TagPoliciesAPI::get_tag_policy_score`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetTagPolicyScoreError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListTagPoliciesError is a struct for typed errors of method [`TagPoliciesAPI::list_tag_policies`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListTagPoliciesError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// UpdateTagPolicyError is a struct for typed errors of method [`TagPoliciesAPI::update_tag_policy`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateTagPolicyError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// Tag Policies define rules that govern which tag values are accepted for a given tag key, +/// scoped to a particular telemetry source (such as logs, spans, or metrics). Policies can be +/// `blocking` (data not matching the policy is rejected) or `surfacing` (matching data is +/// highlighted but not blocked). Each policy reports a compliance `score` derived from how +/// much recent telemetry adheres to the policy. +#[derive(Debug, Clone)] +pub struct TagPoliciesAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for TagPoliciesAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl TagPoliciesAPI { + pub fn new() -> Self { + Self::default() + } + pub fn with_config(config: datadog::Configuration) -> Self { + let reqwest_client_builder = { + let builder = reqwest::Client::builder(); + #[cfg(not(target_arch = "wasm32"))] + let builder = if let Some(proxy_url) = &config.proxy_url { + builder.proxy(reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL")) + } else { + builder + }; + builder + }; + + let middleware_client_builder = { + let builder = + reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap()); + #[cfg(feature = "retry")] + let builder = if config.enable_retry { + struct RetryableStatus; + impl reqwest_retry::RetryableStrategy for RetryableStatus { + fn handle( + &self, + res: &Result, + ) -> Option { + match res { + Ok(success) => reqwest_retry::default_on_request_success(success), + Err(_) => None, + } + } + } + let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder() + .build_with_max_retries(config.max_retries); + + let retry_middleware = + reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy( + backoff_policy, + RetryableStatus, + ); + + builder.with(retry_middleware) + } else { + builder + }; + builder + }; + + let client = middleware_client_builder.build(); + + Self { config, client } + } + + pub fn with_client_and_config( + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, + ) -> Self { + Self { config, client } + } + + /// Create a new tag policy for the organization. The caller's organization is derived from + /// the authenticated user; cross-organization creation is not supported. Fields such as + /// `policy_id`, `version`, and the timestamp/audit fields are assigned by the server. + pub async fn create_tag_policy( + &self, + body: crate::datadogV2::model::TagPolicyCreateRequest, + ) -> Result> + { + match self.create_tag_policy_with_http_info(body).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Create a new tag policy for the organization. The caller's organization is derived from + /// the authenticated user; cross-organization creation is not supported. Fields such as + /// `policy_id`, `version`, and the timestamp/audit fields are assigned by the server. + pub async fn create_tag_policy_with_http_info( + &self, + body: crate::datadogV2::model::TagPolicyCreateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_tag_policy"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.create_tag_policy' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/tag-policies", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // 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"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + #[cfg(feature = "zstd")] + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::(&local_content) + { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + 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)) + } + } + + /// Delete a tag policy. By default the policy is soft-deleted so it can be recovered later + /// and so that historical score data remains queryable. Pass `hard_delete=true` to remove + /// the policy permanently. + pub async fn delete_tag_policy( + &self, + policy_id: String, + params: DeleteTagPolicyOptionalParams, + ) -> Result<(), datadog::Error> { + match self + .delete_tag_policy_with_http_info(policy_id, params) + .await + { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + + /// Delete a tag policy. By default the policy is soft-deleted so it can be recovered later + /// and so that historical score data remains queryable. Pass `hard_delete=true` to remove + /// the policy permanently. + pub async fn delete_tag_policy_with_http_info( + &self, + policy_id: String, + params: DeleteTagPolicyOptionalParams, + ) -> Result, datadog::Error> { + let local_configuration = &self.config; + let operation_id = "v2.delete_tag_policy"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.delete_tag_policy' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let hard_delete = params.hard_delete; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/tag-policies/{policy_id}", + local_configuration.get_operation_host(operation_id), + policy_id = datadog::urlencode(policy_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::DELETE, local_uri_str.as_str()); + + if let Some(ref local_query_param) = hard_delete { + local_req_builder = + local_req_builder.query(&[("hard_delete", &local_query_param.to_string())]); + }; + + // 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 = + 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)) + } + } + + /// Retrieve a single tag policy by ID. Optionally include the policy's current compliance + /// score via the `include=score` query parameter. Policies belonging to other organizations + /// cannot be retrieved. + pub async fn get_tag_policy( + &self, + policy_id: String, + params: GetTagPolicyOptionalParams, + ) -> Result> { + match self.get_tag_policy_with_http_info(policy_id, params).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Retrieve a single tag policy by ID. Optionally include the policy's current compliance + /// score via the `include=score` query parameter. Policies belonging to other organizations + /// cannot be retrieved. + pub async fn get_tag_policy_with_http_info( + &self, + policy_id: String, + params: GetTagPolicyOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_tag_policy"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.get_tag_policy' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let include = params.include; + let ts_start = params.ts_start; + let ts_end = params.ts_end; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/tag-policies/{policy_id}", + local_configuration.get_operation_host(operation_id), + policy_id = datadog::urlencode(policy_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = include { + local_req_builder = + local_req_builder.query(&[("include", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = ts_start { + local_req_builder = + local_req_builder.query(&[("ts_start", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = ts_end { + local_req_builder = + local_req_builder.query(&[("ts_end", &local_query_param.to_string())]); + }; + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // 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() { + match serde_json::from_str::(&local_content) + { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = 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)) + } + } + + /// Retrieve the compliance score for a single tag policy. The score is computed over the + /// requested time window (or a source-appropriate default) and represents the percentage of + /// telemetry within that window that conforms to the policy. A `null` score indicates that + /// no relevant telemetry was found. + pub async fn get_tag_policy_score( + &self, + policy_id: String, + params: GetTagPolicyScoreOptionalParams, + ) -> Result< + crate::datadogV2::model::TagPolicyScoreResponse, + datadog::Error, + > { + match self + .get_tag_policy_score_with_http_info(policy_id, params) + .await + { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Retrieve the compliance score for a single tag policy. The score is computed over the + /// requested time window (or a source-appropriate default) and represents the percentage of + /// telemetry within that window that conforms to the policy. A `null` score indicates that + /// no relevant telemetry was found. + pub async fn get_tag_policy_score_with_http_info( + &self, + policy_id: String, + params: GetTagPolicyScoreOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_tag_policy_score"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.get_tag_policy_score' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let ts_start = params.ts_start; + let ts_end = params.ts_end; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/tag-policies/{policy_id}/score", + local_configuration.get_operation_host(operation_id), + policy_id = datadog::urlencode(policy_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = ts_start { + local_req_builder = + local_req_builder.query(&[("ts_start", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = ts_end { + local_req_builder = + local_req_builder.query(&[("ts_end", &local_query_param.to_string())]); + }; + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // 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() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + 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)) + } + } + + /// Retrieve all tag policies for the organization. Optionally include disabled or deleted + /// policies, filter by telemetry source, and include each policy's current compliance score + /// via the `include=score` query parameter. + pub async fn list_tag_policies( + &self, + params: ListTagPoliciesOptionalParams, + ) -> Result< + crate::datadogV2::model::TagPoliciesListResponse, + datadog::Error, + > { + match self.list_tag_policies_with_http_info(params).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Retrieve all tag policies for the organization. Optionally include disabled or deleted + /// policies, filter by telemetry source, and include each policy's current compliance score + /// via the `include=score` query parameter. + pub async fn list_tag_policies_with_http_info( + &self, + params: ListTagPoliciesOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_tag_policies"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.list_tag_policies' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let include_disabled = params.include_disabled; + let include_deleted = params.include_deleted; + let include = params.include; + let filter_source = params.filter_source; + let ts_start = params.ts_start; + let ts_end = params.ts_end; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/tag-policies", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = include_disabled { + local_req_builder = + local_req_builder.query(&[("include_disabled", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = include_deleted { + local_req_builder = + local_req_builder.query(&[("include_deleted", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = include { + local_req_builder = + local_req_builder.query(&[("include", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = filter_source { + local_req_builder = + local_req_builder.query(&[("filter[source]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = ts_start { + local_req_builder = + local_req_builder.query(&[("ts_start", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = ts_end { + local_req_builder = + local_req_builder.query(&[("ts_end", &local_query_param.to_string())]); + }; + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // 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() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + 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)) + } + } + + /// Update one or more attributes of an existing tag policy. Only the fields supplied in the + /// request body are modified; omitted fields retain their current values. The policy's + /// `source` cannot be changed after creation. + pub async fn update_tag_policy( + &self, + policy_id: String, + body: crate::datadogV2::model::TagPolicyUpdateRequest, + ) -> Result> + { + match self.update_tag_policy_with_http_info(policy_id, body).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Update one or more attributes of an existing tag policy. Only the fields supplied in the + /// request body are modified; omitted fields retain their current values. The policy's + /// `source` cannot be changed after creation. + pub async fn update_tag_policy_with_http_info( + &self, + policy_id: String, + body: crate::datadogV2::model::TagPolicyUpdateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_tag_policy"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.update_tag_policy' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/tag-policies/{policy_id}", + local_configuration.get_operation_host(operation_id), + policy_id = datadog::urlencode(policy_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PATCH, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // 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"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + #[cfg(feature = "zstd")] + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::(&local_content) + { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + 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)) + } + } +} diff --git a/src/datadogV2/api/mod.rs b/src/datadogV2/api/mod.rs index b61730073..8b5a79922 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -124,6 +124,7 @@ pub mod api_statuspage_integration; pub mod api_stegadography; pub mod api_storage_management; pub mod api_synthetics; +pub mod api_tag_policies; pub mod api_teams; pub mod api_test_optimization; pub mod api_usage_metering; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index b37e573b9..c180c2588 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -125,6 +125,7 @@ pub use self::api::api_statuspage_integration; pub use self::api::api_stegadography; pub use self::api::api_storage_management; pub use self::api::api_synthetics; +pub use self::api::api_tag_policies; pub use self::api::api_teams; pub use self::api::api_test_optimization; pub use self::api::api_usage_metering; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index f4d63def6..1047471e0 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -12258,6 +12258,50 @@ pub mod model_synthetics_global_variable_totp_parameters; pub use self::model_synthetics_global_variable_totp_parameters::SyntheticsGlobalVariableTOTPParameters; pub mod model_global_variable_type; pub use self::model_global_variable_type::GlobalVariableType; +pub mod model_tag_policy_include; +pub use self::model_tag_policy_include::TagPolicyInclude; +pub mod model_tag_policy_source; +pub use self::model_tag_policy_source::TagPolicySource; +pub mod model_tag_policies_list_response; +pub use self::model_tag_policies_list_response::TagPoliciesListResponse; +pub mod model_tag_policy_data; +pub use self::model_tag_policy_data::TagPolicyData; +pub mod model_tag_policy_attributes; +pub use self::model_tag_policy_attributes::TagPolicyAttributes; +pub mod model_tag_policy_type; +pub use self::model_tag_policy_type::TagPolicyType; +pub mod model_tag_policy_relationships; +pub use self::model_tag_policy_relationships::TagPolicyRelationships; +pub mod model_tag_policy_score_relationship; +pub use self::model_tag_policy_score_relationship::TagPolicyScoreRelationship; +pub mod model_tag_policy_score_relationship_data; +pub use self::model_tag_policy_score_relationship_data::TagPolicyScoreRelationshipData; +pub mod model_tag_policy_score_resource_type; +pub use self::model_tag_policy_score_resource_type::TagPolicyScoreResourceType; +pub mod model_tag_policy_resource_type; +pub use self::model_tag_policy_resource_type::TagPolicyResourceType; +pub mod model_tag_policy_score_data; +pub use self::model_tag_policy_score_data::TagPolicyScoreData; +pub mod model_tag_policy_score_attributes; +pub use self::model_tag_policy_score_attributes::TagPolicyScoreAttributes; +pub mod model_tag_policy_create_request; +pub use self::model_tag_policy_create_request::TagPolicyCreateRequest; +pub mod model_tag_policy_create_data; +pub use self::model_tag_policy_create_data::TagPolicyCreateData; +pub mod model_tag_policy_create_attributes; +pub use self::model_tag_policy_create_attributes::TagPolicyCreateAttributes; +pub mod model_tag_policy_create_type; +pub use self::model_tag_policy_create_type::TagPolicyCreateType; +pub mod model_tag_policy_response; +pub use self::model_tag_policy_response::TagPolicyResponse; +pub mod model_tag_policy_update_request; +pub use self::model_tag_policy_update_request::TagPolicyUpdateRequest; +pub mod model_tag_policy_update_data; +pub use self::model_tag_policy_update_data::TagPolicyUpdateData; +pub mod model_tag_policy_update_attributes; +pub use self::model_tag_policy_update_attributes::TagPolicyUpdateAttributes; +pub mod model_tag_policy_score_response; +pub use self::model_tag_policy_score_response::TagPolicyScoreResponse; pub mod model_ruleset_resp_array; pub use self::model_ruleset_resp_array::RulesetRespArray; pub mod model_ruleset_resp_data; diff --git a/src/datadogV2/model/model_tag_policies_list_response.rs b/src/datadogV2/model/model_tag_policies_list_response.rs new file mode 100644 index 000000000..6c854cbae --- /dev/null +++ b/src/datadogV2/model/model_tag_policies_list_response.rs @@ -0,0 +1,109 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A page of tag policies. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPoliciesListResponse { + /// An array of tag policy data objects. + #[serde(rename = "data")] + pub data: Vec, + /// Related resources fetched alongside the primary tag policies. Populated when an `include` query parameter is supplied. + #[serde(rename = "included")] + pub included: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPoliciesListResponse { + pub fn new(data: Vec) -> TagPoliciesListResponse { + TagPoliciesListResponse { + data, + included: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn included(mut self, value: Vec) -> Self { + self.included = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPoliciesListResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPoliciesListResponseVisitor; + impl<'a> Visitor<'a> for TagPoliciesListResponseVisitor { + type Value = TagPoliciesListResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option> = None; + let mut included: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "included" => { + if v.is_null() { + continue; + } + included = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = TagPoliciesListResponse { + data, + included, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPoliciesListResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_attributes.rs b/src/datadogV2/model/model_tag_policy_attributes.rs new file mode 100644 index 000000000..ee53a5e1b --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_attributes.rs @@ -0,0 +1,304 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a tag policy resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyAttributes { + /// The RFC 3339 timestamp at which the policy was created. + #[serde(rename = "created_at")] + pub created_at: chrono::DateTime, + /// The identifier of the user who created the policy. + #[serde(rename = "created_by")] + pub created_by: String, + /// The RFC 3339 timestamp at which the policy was soft-deleted. `null` if the policy has not been deleted. Only present when `include_deleted=true` is requested. + #[serde( + rename = "deleted_at", + default, + with = "::serde_with::rust::double_option" + )] + pub deleted_at: Option>>, + /// The identifier of the user who soft-deleted the policy. `null` if the policy has not been deleted. + #[serde( + rename = "deleted_by", + default, + with = "::serde_with::rust::double_option" + )] + pub deleted_by: Option>, + /// Whether the policy is currently enforced. + #[serde(rename = "enabled")] + pub enabled: bool, + /// The RFC 3339 timestamp at which the policy was last modified. + #[serde(rename = "modified_at")] + pub modified_at: chrono::DateTime, + /// The identifier of the user who last modified the policy. + #[serde(rename = "modified_by")] + pub modified_by: String, + /// When `true`, the policy matches tag values that do NOT match any of the supplied patterns. + #[serde(rename = "negated")] + pub negated: bool, + /// Human-readable name for the tag policy. + #[serde(rename = "policy_name")] + pub policy_name: String, + /// How the policy is enforced. `blocking` rejects telemetry that violates the policy. + /// `surfacing` only highlights non-compliant telemetry without blocking it. + #[serde(rename = "policy_type")] + pub policy_type: crate::datadogV2::model::TagPolicyType, + /// When `true`, telemetry without this tag is treated as a violation. + #[serde(rename = "required")] + pub required: bool, + /// The scope the policy applies within. + #[serde(rename = "scope")] + pub scope: String, + /// The telemetry source that a tag policy applies to. + #[serde(rename = "source")] + pub source: crate::datadogV2::model::TagPolicySource, + /// The tag key that the policy governs. + #[serde(rename = "tag_key")] + pub tag_key: String, + /// The patterns that valid values for the tag key must match. + #[serde(rename = "tag_value_patterns")] + pub tag_value_patterns: Vec, + /// A monotonically increasing version counter that is incremented on each update. + #[serde(rename = "version")] + pub version: i64, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyAttributes { + pub fn new( + created_at: chrono::DateTime, + created_by: String, + enabled: bool, + modified_at: chrono::DateTime, + modified_by: String, + negated: bool, + policy_name: String, + policy_type: crate::datadogV2::model::TagPolicyType, + required: bool, + scope: String, + source: crate::datadogV2::model::TagPolicySource, + tag_key: String, + tag_value_patterns: Vec, + version: i64, + ) -> TagPolicyAttributes { + TagPolicyAttributes { + created_at, + created_by, + deleted_at: None, + deleted_by: None, + enabled, + modified_at, + modified_by, + negated, + policy_name, + policy_type, + required, + scope, + source, + tag_key, + tag_value_patterns, + version, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn deleted_at(mut self, value: Option>) -> Self { + self.deleted_at = Some(value); + self + } + + pub fn deleted_by(mut self, value: Option) -> Self { + self.deleted_by = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyAttributesVisitor; + impl<'a> Visitor<'a> for TagPolicyAttributesVisitor { + type Value = TagPolicyAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut created_at: Option> = None; + let mut created_by: Option = None; + let mut deleted_at: Option>> = None; + let mut deleted_by: Option> = None; + let mut enabled: Option = None; + let mut modified_at: Option> = None; + let mut modified_by: Option = None; + let mut negated: Option = None; + let mut policy_name: Option = None; + let mut policy_type: Option = None; + let mut required: Option = None; + let mut scope: Option = None; + let mut source: Option = None; + let mut tag_key: Option = None; + let mut tag_value_patterns: Option> = None; + let mut version: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "created_at" => { + created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "created_by" => { + created_by = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "deleted_at" => { + deleted_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "deleted_by" => { + deleted_by = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "enabled" => { + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_at" => { + modified_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_by" => { + modified_by = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "negated" => { + negated = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "policy_name" => { + policy_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "policy_type" => { + policy_type = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _policy_type) = policy_type { + match _policy_type { + crate::datadogV2::model::TagPolicyType::UnparsedObject( + _policy_type, + ) => { + _unparsed = true; + } + _ => {} + } + } + } + "required" => { + required = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "source" => { + source = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _source) = source { + match _source { + crate::datadogV2::model::TagPolicySource::UnparsedObject( + _source, + ) => { + _unparsed = true; + } + _ => {} + } + } + } + "tag_key" => { + tag_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "tag_value_patterns" => { + tag_value_patterns = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "version" => { + version = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let created_at = created_at.ok_or_else(|| M::Error::missing_field("created_at"))?; + let created_by = created_by.ok_or_else(|| M::Error::missing_field("created_by"))?; + let enabled = enabled.ok_or_else(|| M::Error::missing_field("enabled"))?; + let modified_at = + modified_at.ok_or_else(|| M::Error::missing_field("modified_at"))?; + let modified_by = + modified_by.ok_or_else(|| M::Error::missing_field("modified_by"))?; + let negated = negated.ok_or_else(|| M::Error::missing_field("negated"))?; + let policy_name = + policy_name.ok_or_else(|| M::Error::missing_field("policy_name"))?; + let policy_type = + policy_type.ok_or_else(|| M::Error::missing_field("policy_type"))?; + let required = required.ok_or_else(|| M::Error::missing_field("required"))?; + let scope = scope.ok_or_else(|| M::Error::missing_field("scope"))?; + let source = source.ok_or_else(|| M::Error::missing_field("source"))?; + let tag_key = tag_key.ok_or_else(|| M::Error::missing_field("tag_key"))?; + let tag_value_patterns = tag_value_patterns + .ok_or_else(|| M::Error::missing_field("tag_value_patterns"))?; + let version = version.ok_or_else(|| M::Error::missing_field("version"))?; + + let content = TagPolicyAttributes { + created_at, + created_by, + deleted_at, + deleted_by, + enabled, + modified_at, + modified_by, + negated, + policy_name, + policy_type, + required, + scope, + source, + tag_key, + tag_value_patterns, + version, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_create_attributes.rs b/src/datadogV2/model/model_tag_policy_create_attributes.rs new file mode 100644 index 000000000..e1798b0fb --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_create_attributes.rs @@ -0,0 +1,227 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Attributes that can be supplied when creating a tag policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyCreateAttributes { + /// Whether the policy is currently enforced. Defaults to `true` for newly created policies. + #[serde(rename = "enabled")] + pub enabled: Option, + /// When `true`, the policy matches tag values that do NOT match any of the supplied patterns. Defaults to `false`. + #[serde(rename = "negated")] + pub negated: Option, + /// Human-readable name for the tag policy. + #[serde(rename = "policy_name")] + pub policy_name: String, + /// The policy type allowed when creating a tag policy. Only `surfacing` is accepted at + /// creation time. + #[serde(rename = "policy_type")] + pub policy_type: crate::datadogV2::model::TagPolicyCreateType, + /// When `true`, telemetry without this tag is treated as a violation. Defaults to `false`. + #[serde(rename = "required")] + pub required: Option, + /// The scope the policy applies within. Typically an environment, team, or + /// organization-level identifier used to limit where the policy is enforced. + #[serde(rename = "scope")] + pub scope: String, + /// The telemetry source that a tag policy applies to. + #[serde(rename = "source")] + pub source: crate::datadogV2::model::TagPolicySource, + /// The tag key that the policy governs (for example, `service`). + #[serde(rename = "tag_key")] + pub tag_key: String, + /// One or more patterns that valid values for the tag key must match. At least one + /// pattern is required. + #[serde(rename = "tag_value_patterns")] + pub tag_value_patterns: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyCreateAttributes { + pub fn new( + policy_name: String, + policy_type: crate::datadogV2::model::TagPolicyCreateType, + scope: String, + source: crate::datadogV2::model::TagPolicySource, + tag_key: String, + tag_value_patterns: Vec, + ) -> TagPolicyCreateAttributes { + TagPolicyCreateAttributes { + enabled: None, + negated: None, + policy_name, + policy_type, + required: None, + scope, + source, + tag_key, + tag_value_patterns, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn enabled(mut self, value: bool) -> Self { + self.enabled = Some(value); + self + } + + pub fn negated(mut self, value: bool) -> Self { + self.negated = Some(value); + self + } + + pub fn required(mut self, value: bool) -> Self { + self.required = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyCreateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyCreateAttributesVisitor; + impl<'a> Visitor<'a> for TagPolicyCreateAttributesVisitor { + type Value = TagPolicyCreateAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut enabled: Option = None; + let mut negated: Option = None; + let mut policy_name: Option = None; + let mut policy_type: Option = None; + let mut required: Option = None; + let mut scope: Option = None; + let mut source: Option = None; + let mut tag_key: Option = None; + let mut tag_value_patterns: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "enabled" => { + if v.is_null() { + continue; + } + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "negated" => { + if v.is_null() { + continue; + } + negated = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "policy_name" => { + policy_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "policy_type" => { + policy_type = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _policy_type) = policy_type { + match _policy_type { + crate::datadogV2::model::TagPolicyCreateType::UnparsedObject(_policy_type) => { + _unparsed = true; + }, + _ => {} + } + } + } + "required" => { + if v.is_null() { + continue; + } + required = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "source" => { + source = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _source) = source { + match _source { + crate::datadogV2::model::TagPolicySource::UnparsedObject( + _source, + ) => { + _unparsed = true; + } + _ => {} + } + } + } + "tag_key" => { + tag_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "tag_value_patterns" => { + tag_value_patterns = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let policy_name = + policy_name.ok_or_else(|| M::Error::missing_field("policy_name"))?; + let policy_type = + policy_type.ok_or_else(|| M::Error::missing_field("policy_type"))?; + let scope = scope.ok_or_else(|| M::Error::missing_field("scope"))?; + let source = source.ok_or_else(|| M::Error::missing_field("source"))?; + let tag_key = tag_key.ok_or_else(|| M::Error::missing_field("tag_key"))?; + let tag_value_patterns = tag_value_patterns + .ok_or_else(|| M::Error::missing_field("tag_value_patterns"))?; + + let content = TagPolicyCreateAttributes { + enabled, + negated, + policy_name, + policy_type, + required, + scope, + source, + tag_key, + tag_value_patterns, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyCreateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_create_data.rs b/src/datadogV2/model/model_tag_policy_create_data.rs new file mode 100644 index 000000000..99287a2b8 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_create_data.rs @@ -0,0 +1,114 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Data object for creating a tag policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyCreateData { + /// Attributes that can be supplied when creating a tag policy. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::TagPolicyCreateAttributes, + /// JSON:API resource type for a tag policy. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::TagPolicyResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyCreateData { + pub fn new( + attributes: crate::datadogV2::model::TagPolicyCreateAttributes, + type_: crate::datadogV2::model::TagPolicyResourceType, + ) -> TagPolicyCreateData { + TagPolicyCreateData { + attributes, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyCreateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyCreateDataVisitor; + impl<'a> Visitor<'a> for TagPolicyCreateDataVisitor { + type Value = TagPolicyCreateData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = + None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::TagPolicyResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = TagPolicyCreateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyCreateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_create_request.rs b/src/datadogV2/model/model_tag_policy_create_request.rs new file mode 100644 index 000000000..ab8c74603 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_create_request.rs @@ -0,0 +1,92 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Payload for creating a new tag policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyCreateRequest { + /// Data object for creating a tag policy. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::TagPolicyCreateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyCreateRequest { + pub fn new(data: crate::datadogV2::model::TagPolicyCreateData) -> TagPolicyCreateRequest { + TagPolicyCreateRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyCreateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyCreateRequestVisitor; + impl<'a> Visitor<'a> for TagPolicyCreateRequestVisitor { + type Value = TagPolicyCreateRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = TagPolicyCreateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyCreateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_create_type.rs b/src/datadogV2/model/model_tag_policy_create_type.rs new file mode 100644 index 000000000..ede00be22 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_create_type.rs @@ -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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TagPolicyCreateType { + SURFACING, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TagPolicyCreateType { + fn to_string(&self) -> String { + match self { + Self::SURFACING => String::from("surfacing"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TagPolicyCreateType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TagPolicyCreateType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "surfacing" => Self::SURFACING, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_tag_policy_data.rs b/src/datadogV2/model/model_tag_policy_data.rs new file mode 100644 index 000000000..ef56ef91e --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_data.rs @@ -0,0 +1,143 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A tag policy resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyData { + /// The attributes of a tag policy resource. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::TagPolicyAttributes, + /// The unique identifier of the tag policy. + #[serde(rename = "id")] + pub id: String, + /// Related resources for a tag policy. Only present when the corresponding `include` query parameter is supplied. + #[serde(rename = "relationships")] + pub relationships: Option, + /// JSON:API resource type for a tag policy. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::TagPolicyResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyData { + pub fn new( + attributes: crate::datadogV2::model::TagPolicyAttributes, + id: String, + type_: crate::datadogV2::model::TagPolicyResourceType, + ) -> TagPolicyData { + TagPolicyData { + attributes, + id, + relationships: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn relationships(mut self, value: crate::datadogV2::model::TagPolicyRelationships) -> Self { + self.relationships = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyDataVisitor; + impl<'a> Visitor<'a> for TagPolicyDataVisitor { + type Value = TagPolicyData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = None; + let mut id: Option = None; + let mut relationships: Option = + None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "relationships" => { + if v.is_null() { + continue; + } + relationships = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::TagPolicyResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = TagPolicyData { + attributes, + id, + relationships, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyDataVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_include.rs b/src/datadogV2/model/model_tag_policy_include.rs new file mode 100644 index 000000000..95e68232e --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_include.rs @@ -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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TagPolicyInclude { + SCORE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TagPolicyInclude { + fn to_string(&self) -> String { + match self { + Self::SCORE => String::from("score"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TagPolicyInclude { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TagPolicyInclude { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "score" => Self::SCORE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_tag_policy_relationships.rs b/src/datadogV2/model/model_tag_policy_relationships.rs new file mode 100644 index 000000000..cedefb795 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_relationships.rs @@ -0,0 +1,105 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Related resources for a tag policy. Only present when the corresponding `include` query parameter is supplied. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyRelationships { + /// A relationship to the compliance score resource for this policy. + #[serde(rename = "score")] + pub score: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyRelationships { + pub fn new() -> TagPolicyRelationships { + TagPolicyRelationships { + score: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn score(mut self, value: crate::datadogV2::model::TagPolicyScoreRelationship) -> Self { + self.score = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for TagPolicyRelationships { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for TagPolicyRelationships { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyRelationshipsVisitor; + impl<'a> Visitor<'a> for TagPolicyRelationshipsVisitor { + type Value = TagPolicyRelationships; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut score: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "score" => { + if v.is_null() { + continue; + } + score = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = TagPolicyRelationships { + score, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyRelationshipsVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_resource_type.rs b/src/datadogV2/model/model_tag_policy_resource_type.rs new file mode 100644 index 000000000..6d31acb4e --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_resource_type.rs @@ -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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TagPolicyResourceType { + TAG_POLICY, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TagPolicyResourceType { + fn to_string(&self) -> String { + match self { + Self::TAG_POLICY => String::from("tag_policy"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TagPolicyResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TagPolicyResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "tag_policy" => Self::TAG_POLICY, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_tag_policy_response.rs b/src/datadogV2/model/model_tag_policy_response.rs new file mode 100644 index 000000000..78e07780d --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_response.rs @@ -0,0 +1,109 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A single tag policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyResponse { + /// A tag policy resource. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::TagPolicyData, + /// Related resources fetched alongside the primary tag policies. Populated when an `include` query parameter is supplied. + #[serde(rename = "included")] + pub included: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyResponse { + pub fn new(data: crate::datadogV2::model::TagPolicyData) -> TagPolicyResponse { + TagPolicyResponse { + data, + included: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn included(mut self, value: Vec) -> Self { + self.included = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyResponseVisitor; + impl<'a> Visitor<'a> for TagPolicyResponseVisitor { + type Value = TagPolicyResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut included: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "included" => { + if v.is_null() { + continue; + } + included = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = TagPolicyResponse { + data, + included, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_score_attributes.rs b/src/datadogV2/model/model_tag_policy_score_attributes.rs new file mode 100644 index 000000000..b420d3051 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_score_attributes.rs @@ -0,0 +1,132 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Attributes of a tag policy compliance score. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyScoreAttributes { + /// The compliance score for the policy over the requested time window, as a percentage + /// between 0 and 100. `null` indicates that no relevant telemetry was found. + #[serialize_always] + #[serde(rename = "score")] + pub score: Option, + /// End of the time window the score was computed over, as a Unix timestamp in milliseconds. + #[serde(rename = "ts_end")] + pub ts_end: i64, + /// Start of the time window the score was computed over, as a Unix timestamp in milliseconds. + #[serde(rename = "ts_start")] + pub ts_start: i64, + /// The version of the tag policy that the score was computed against. + #[serde(rename = "version")] + pub version: i64, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyScoreAttributes { + pub fn new( + score: Option, + ts_end: i64, + ts_start: i64, + version: i64, + ) -> TagPolicyScoreAttributes { + TagPolicyScoreAttributes { + score, + ts_end, + ts_start, + version, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyScoreAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyScoreAttributesVisitor; + impl<'a> Visitor<'a> for TagPolicyScoreAttributesVisitor { + type Value = TagPolicyScoreAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut score: Option> = None; + let mut ts_end: Option = None; + let mut ts_start: Option = None; + let mut version: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "score" => { + if v.as_str() == Some("") { + continue; + } + score = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "ts_end" => { + ts_end = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "ts_start" => { + ts_start = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "version" => { + version = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let score = score.ok_or_else(|| M::Error::missing_field("score"))?; + let ts_end = ts_end.ok_or_else(|| M::Error::missing_field("ts_end"))?; + let ts_start = ts_start.ok_or_else(|| M::Error::missing_field("ts_start"))?; + let version = version.ok_or_else(|| M::Error::missing_field("version"))?; + + let content = TagPolicyScoreAttributes { + score, + ts_end, + ts_start, + version, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyScoreAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_score_data.rs b/src/datadogV2/model/model_tag_policy_score_data.rs new file mode 100644 index 000000000..f4d2f0ed8 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_score_data.rs @@ -0,0 +1,125 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A compliance score resource for a tag policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyScoreData { + /// Attributes of a tag policy compliance score. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::TagPolicyScoreAttributes, + /// The unique identifier of the compliance score resource. + #[serde(rename = "id")] + pub id: String, + /// JSON:API resource type for a tag policy compliance score. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::TagPolicyScoreResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyScoreData { + pub fn new( + attributes: crate::datadogV2::model::TagPolicyScoreAttributes, + id: String, + type_: crate::datadogV2::model::TagPolicyScoreResourceType, + ) -> TagPolicyScoreData { + TagPolicyScoreData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyScoreData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyScoreDataVisitor; + impl<'a> Visitor<'a> for TagPolicyScoreDataVisitor { + type Value = TagPolicyScoreData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = + None; + let mut id: Option = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::TagPolicyScoreResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = TagPolicyScoreData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyScoreDataVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_score_relationship.rs b/src/datadogV2/model/model_tag_policy_score_relationship.rs new file mode 100644 index 000000000..1e660c6da --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_score_relationship.rs @@ -0,0 +1,95 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A relationship to the compliance score resource for this policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyScoreRelationship { + /// Identifier of the related compliance score resource. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::TagPolicyScoreRelationshipData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyScoreRelationship { + pub fn new( + data: crate::datadogV2::model::TagPolicyScoreRelationshipData, + ) -> TagPolicyScoreRelationship { + TagPolicyScoreRelationship { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyScoreRelationship { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyScoreRelationshipVisitor; + impl<'a> Visitor<'a> for TagPolicyScoreRelationshipVisitor { + type Value = TagPolicyScoreRelationship; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = TagPolicyScoreRelationship { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyScoreRelationshipVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_score_relationship_data.rs b/src/datadogV2/model/model_tag_policy_score_relationship_data.rs new file mode 100644 index 000000000..6b86bf485 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_score_relationship_data.rs @@ -0,0 +1,113 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Identifier of the related compliance score resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyScoreRelationshipData { + /// The unique identifier of the related compliance score resource. + #[serde(rename = "id")] + pub id: String, + /// JSON:API resource type for a tag policy compliance score. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::TagPolicyScoreResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyScoreRelationshipData { + pub fn new( + id: String, + type_: crate::datadogV2::model::TagPolicyScoreResourceType, + ) -> TagPolicyScoreRelationshipData { + TagPolicyScoreRelationshipData { + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyScoreRelationshipData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyScoreRelationshipDataVisitor; + impl<'a> Visitor<'a> for TagPolicyScoreRelationshipDataVisitor { + type Value = TagPolicyScoreRelationshipData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut id: Option = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::TagPolicyScoreResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = TagPolicyScoreRelationshipData { + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyScoreRelationshipDataVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_score_resource_type.rs b/src/datadogV2/model/model_tag_policy_score_resource_type.rs new file mode 100644 index 000000000..f71debe6d --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_score_resource_type.rs @@ -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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TagPolicyScoreResourceType { + TAG_POLICY_SCORE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TagPolicyScoreResourceType { + fn to_string(&self) -> String { + match self { + Self::TAG_POLICY_SCORE => String::from("tag_policy_score"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TagPolicyScoreResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TagPolicyScoreResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "tag_policy_score" => Self::TAG_POLICY_SCORE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_tag_policy_score_response.rs b/src/datadogV2/model/model_tag_policy_score_response.rs new file mode 100644 index 000000000..fce36ff59 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_score_response.rs @@ -0,0 +1,92 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A tag policy compliance score. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyScoreResponse { + /// A compliance score resource for a tag policy. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::TagPolicyScoreData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyScoreResponse { + pub fn new(data: crate::datadogV2::model::TagPolicyScoreData) -> TagPolicyScoreResponse { + TagPolicyScoreResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyScoreResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyScoreResponseVisitor; + impl<'a> Visitor<'a> for TagPolicyScoreResponseVisitor { + type Value = TagPolicyScoreResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = TagPolicyScoreResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyScoreResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_source.rs b/src/datadogV2/model/model_tag_policy_source.rs new file mode 100644 index 000000000..358dca2d0 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_source.rs @@ -0,0 +1,60 @@ +// 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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TagPolicySource { + LOGS, + SPANS, + METRICS, + RUM, + FEED, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TagPolicySource { + fn to_string(&self) -> String { + match self { + Self::LOGS => String::from("logs"), + Self::SPANS => String::from("spans"), + Self::METRICS => String::from("metrics"), + Self::RUM => String::from("rum"), + Self::FEED => String::from("feed"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TagPolicySource { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TagPolicySource { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "logs" => Self::LOGS, + "spans" => Self::SPANS, + "metrics" => Self::METRICS, + "rum" => Self::RUM, + "feed" => Self::FEED, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_tag_policy_type.rs b/src/datadogV2/model/model_tag_policy_type.rs new file mode 100644 index 000000000..da4cb2f8b --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_type.rs @@ -0,0 +1,51 @@ +// 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. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TagPolicyType { + BLOCKING, + SURFACING, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TagPolicyType { + fn to_string(&self) -> String { + match self { + Self::BLOCKING => String::from("blocking"), + Self::SURFACING => String::from("surfacing"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TagPolicyType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TagPolicyType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "blocking" => Self::BLOCKING, + "surfacing" => Self::SURFACING, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_tag_policy_update_attributes.rs b/src/datadogV2/model/model_tag_policy_update_attributes.rs new file mode 100644 index 000000000..02cf8aeb3 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_update_attributes.rs @@ -0,0 +1,239 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Mutable attributes of a tag policy. Each field is optional; omitting a field leaves its +/// current value unchanged. The `source` of a policy cannot be changed. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyUpdateAttributes { + /// Whether the policy is currently enforced. + #[serde(rename = "enabled")] + pub enabled: Option, + /// When `true`, the policy matches tag values that do NOT match any of the supplied patterns. + #[serde(rename = "negated")] + pub negated: Option, + /// Human-readable name for the tag policy. + #[serde(rename = "policy_name")] + pub policy_name: Option, + /// How the policy is enforced. `blocking` rejects telemetry that violates the policy. + /// `surfacing` only highlights non-compliant telemetry without blocking it. + #[serde(rename = "policy_type")] + pub policy_type: Option, + /// When `true`, telemetry without this tag is treated as a violation. + #[serde(rename = "required")] + pub required: Option, + /// The scope the policy applies within. + #[serde(rename = "scope")] + pub scope: Option, + /// The tag key that the policy governs. + #[serde(rename = "tag_key")] + pub tag_key: Option, + /// One or more patterns that valid values for the tag key must match. + #[serde(rename = "tag_value_patterns")] + pub tag_value_patterns: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyUpdateAttributes { + pub fn new() -> TagPolicyUpdateAttributes { + TagPolicyUpdateAttributes { + enabled: None, + negated: None, + policy_name: None, + policy_type: None, + required: None, + scope: None, + tag_key: None, + tag_value_patterns: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn enabled(mut self, value: bool) -> Self { + self.enabled = Some(value); + self + } + + pub fn negated(mut self, value: bool) -> Self { + self.negated = Some(value); + self + } + + pub fn policy_name(mut self, value: String) -> Self { + self.policy_name = Some(value); + self + } + + pub fn policy_type(mut self, value: crate::datadogV2::model::TagPolicyType) -> Self { + self.policy_type = Some(value); + self + } + + pub fn required(mut self, value: bool) -> Self { + self.required = Some(value); + self + } + + pub fn scope(mut self, value: String) -> Self { + self.scope = Some(value); + self + } + + pub fn tag_key(mut self, value: String) -> Self { + self.tag_key = Some(value); + self + } + + pub fn tag_value_patterns(mut self, value: Vec) -> Self { + self.tag_value_patterns = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for TagPolicyUpdateAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for TagPolicyUpdateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyUpdateAttributesVisitor; + impl<'a> Visitor<'a> for TagPolicyUpdateAttributesVisitor { + type Value = TagPolicyUpdateAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut enabled: Option = None; + let mut negated: Option = None; + let mut policy_name: Option = None; + let mut policy_type: Option = None; + let mut required: Option = None; + let mut scope: Option = None; + let mut tag_key: Option = None; + let mut tag_value_patterns: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "enabled" => { + if v.is_null() { + continue; + } + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "negated" => { + if v.is_null() { + continue; + } + negated = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "policy_name" => { + if v.is_null() { + continue; + } + policy_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "policy_type" => { + if v.is_null() { + continue; + } + policy_type = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _policy_type) = policy_type { + match _policy_type { + crate::datadogV2::model::TagPolicyType::UnparsedObject( + _policy_type, + ) => { + _unparsed = true; + } + _ => {} + } + } + } + "required" => { + if v.is_null() { + continue; + } + required = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + if v.is_null() { + continue; + } + scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "tag_key" => { + if v.is_null() { + continue; + } + tag_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "tag_value_patterns" => { + if v.is_null() { + continue; + } + tag_value_patterns = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = TagPolicyUpdateAttributes { + enabled, + negated, + policy_name, + policy_type, + required, + scope, + tag_key, + tag_value_patterns, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyUpdateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_update_data.rs b/src/datadogV2/model/model_tag_policy_update_data.rs new file mode 100644 index 000000000..5ddccf193 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_update_data.rs @@ -0,0 +1,132 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Data object for updating a tag policy. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyUpdateData { + /// Mutable attributes of a tag policy. Each field is optional; omitting a field leaves its + /// current value unchanged. The `source` of a policy cannot be changed. + #[serde(rename = "attributes")] + pub attributes: Option, + /// The unique identifier of the tag policy being updated. + #[serde(rename = "id")] + pub id: String, + /// JSON:API resource type for a tag policy. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::TagPolicyResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyUpdateData { + pub fn new( + id: String, + type_: crate::datadogV2::model::TagPolicyResourceType, + ) -> TagPolicyUpdateData { + TagPolicyUpdateData { + attributes: None, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes(mut self, value: crate::datadogV2::model::TagPolicyUpdateAttributes) -> Self { + self.attributes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyUpdateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyUpdateDataVisitor; + impl<'a> Visitor<'a> for TagPolicyUpdateDataVisitor { + type Value = TagPolicyUpdateData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = + None; + let mut id: Option = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::TagPolicyResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = TagPolicyUpdateData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyUpdateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_tag_policy_update_request.rs b/src/datadogV2/model/model_tag_policy_update_request.rs new file mode 100644 index 000000000..a89b89c73 --- /dev/null +++ b/src/datadogV2/model/model_tag_policy_update_request.rs @@ -0,0 +1,92 @@ +// 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. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Payload for updating an existing tag policy. Only the supplied fields are modified. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TagPolicyUpdateRequest { + /// Data object for updating a tag policy. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::TagPolicyUpdateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TagPolicyUpdateRequest { + pub fn new(data: crate::datadogV2::model::TagPolicyUpdateData) -> TagPolicyUpdateRequest { + TagPolicyUpdateRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TagPolicyUpdateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TagPolicyUpdateRequestVisitor; + impl<'a> Visitor<'a> for TagPolicyUpdateRequestVisitor { + type Value = TagPolicyUpdateRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = TagPolicyUpdateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TagPolicyUpdateRequestVisitor) + } +} diff --git a/tests/scenarios/features/v2/tag_policies.feature b/tests/scenarios/features/v2/tag_policies.feature new file mode 100644 index 000000000..b5d064c20 --- /dev/null +++ b/tests/scenarios/features/v2/tag_policies.feature @@ -0,0 +1,150 @@ +@endpoint(tag-policies) @endpoint(tag-policies-v2) +Feature: Tag Policies + Tag Policies define rules that govern which tag values are accepted for a + given tag key, scoped to a particular telemetry source (such as logs, + spans, or metrics). Policies can be `blocking` (data not matching the + policy is rejected) or `surfacing` (matching data is highlighted but not + blocked). Each policy reports a compliance `score` derived from how much + recent telemetry adheres to the policy. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "TagPolicies" API + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Create a tag policy returns "Bad Request" response + Given operation "CreateTagPolicy" enabled + And new "CreateTagPolicy" request + And body with value {"data": {"attributes": {"enabled": true, "negated": false, "policy_name": "Service tag must be one of api or web", "policy_type": "surfacing", "required": true, "scope": "env", "source": "logs", "tag_key": "service", "tag_value_patterns": ["api", "web"]}, "type": "tag_policy"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Create a tag policy returns "Conflict" response + Given operation "CreateTagPolicy" enabled + And new "CreateTagPolicy" request + And body with value {"data": {"attributes": {"enabled": true, "negated": false, "policy_name": "Service tag must be one of api or web", "policy_type": "surfacing", "required": true, "scope": "env", "source": "logs", "tag_key": "service", "tag_value_patterns": ["api", "web"]}, "type": "tag_policy"}} + When the request is sent + Then the response status is 409 Conflict + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Create a tag policy returns "Created" response + Given operation "CreateTagPolicy" enabled + And new "CreateTagPolicy" request + And body with value {"data": {"attributes": {"enabled": true, "negated": false, "policy_name": "Service tag must be one of api or web", "policy_type": "surfacing", "required": true, "scope": "env", "source": "logs", "tag_key": "service", "tag_value_patterns": ["api", "web"]}, "type": "tag_policy"}} + When the request is sent + Then the response status is 201 Created + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Delete a tag policy returns "Bad Request" response + Given operation "DeleteTagPolicy" enabled + And new "DeleteTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Delete a tag policy returns "No Content" response + Given operation "DeleteTagPolicy" enabled + And new "DeleteTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 204 No Content + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Delete a tag policy returns "Not Found" response + Given operation "DeleteTagPolicy" enabled + And new "DeleteTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a tag policy compliance score returns "Bad Request" response + Given operation "GetTagPolicyScore" enabled + And new "GetTagPolicyScore" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a tag policy compliance score returns "Not Found" response + Given operation "GetTagPolicyScore" enabled + And new "GetTagPolicyScore" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a tag policy compliance score returns "OK" response + Given operation "GetTagPolicyScore" enabled + And new "GetTagPolicyScore" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a tag policy returns "Bad Request" response + Given operation "GetTagPolicy" enabled + And new "GetTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a tag policy returns "Not Found" response + Given operation "GetTagPolicy" enabled + And new "GetTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a tag policy returns "OK" response + Given operation "GetTagPolicy" enabled + And new "GetTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List tag policies returns "Bad Request" response + Given operation "ListTagPolicies" enabled + And new "ListTagPolicies" request + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List tag policies returns "OK" response + Given operation "ListTagPolicies" enabled + And new "ListTagPolicies" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update a tag policy returns "Bad Request" response + Given operation "UpdateTagPolicy" enabled + And new "UpdateTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"policy_type": "surfacing", "tag_value_patterns": []}, "id": "123", "type": "tag_policy"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update a tag policy returns "Not Found" response + Given operation "UpdateTagPolicy" enabled + And new "UpdateTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"policy_type": "surfacing", "tag_value_patterns": []}, "id": "123", "type": "tag_policy"}} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update a tag policy returns "OK" response + Given operation "UpdateTagPolicy" enabled + And new "UpdateTagPolicy" request + And request contains "policy_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"policy_type": "surfacing", "tag_value_patterns": []}, "id": "123", "type": "tag_policy"}} + When the request is sent + Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 8cd923c97..e947f19f5 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -8655,6 +8655,49 @@ "type": "safe" } }, + "ListTagPolicies": { + "tag": "Tag Policies", + "undo": { + "type": "safe" + } + }, + "CreateTagPolicy": { + "tag": "Tag Policies", + "undo": { + "operationId": "DeleteTagPolicy", + "parameters": [ + { + "name": "policy_id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, + "DeleteTagPolicy": { + "tag": "Tag Policies", + "undo": { + "type": "idempotent" + } + }, + "GetTagPolicy": { + "tag": "Tag Policies", + "undo": { + "type": "safe" + } + }, + "UpdateTagPolicy": { + "tag": "Tag Policies", + "undo": { + "type": "idempotent" + } + }, + "GetTagPolicyScore": { + "tag": "Tag Policies", + "undo": { + "type": "safe" + } + }, "ListTagPipelinesRulesets": { "tag": "Cloud Cost Management", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 45411385d..ef6d1603d 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -213,6 +213,7 @@ pub struct ApiInstances { pub v2_api_status_pages: Option, pub v2_api_stegadography: Option, pub v2_api_synthetics: Option, + pub v2_api_tag_policies: Option, pub v2_api_teams: Option, pub v2_api_web_integrations: Option, pub v2_api_widgets: Option, @@ -1364,6 +1365,14 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { ), ); } + "TagPolicies" => { + world.api_instances.v2_api_tag_policies = Some( + datadogV2::api_tag_policies::TagPoliciesAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone(), + ), + ); + } "Teams" => { world.api_instances.v2_api_teams = Some(datadogV2::api_teams::TeamsAPI::with_client_and_config( @@ -7148,6 +7157,24 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.PatchGlobalVariable".into(), test_v2_patch_global_variable, ); + world + .function_mappings + .insert("v2.ListTagPolicies".into(), test_v2_list_tag_policies); + world + .function_mappings + .insert("v2.CreateTagPolicy".into(), test_v2_create_tag_policy); + world + .function_mappings + .insert("v2.DeleteTagPolicy".into(), test_v2_delete_tag_policy); + world + .function_mappings + .insert("v2.GetTagPolicy".into(), test_v2_get_tag_policy); + world + .function_mappings + .insert("v2.UpdateTagPolicy".into(), test_v2_update_tag_policy); + world + .function_mappings + .insert("v2.GetTagPolicyScore".into(), test_v2_get_tag_policy_score); world .function_mappings .insert("v2.ListTeams".into(), test_v2_list_teams); @@ -56799,6 +56826,208 @@ fn test_v2_patch_global_variable(world: &mut DatadogWorld, _parameters: &HashMap world.response.code = response.status.as_u16(); } +fn test_v2_list_tag_policies(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_tag_policies + .as_ref() + .expect("api instance not found"); + let include_disabled = _parameters + .get("include_disabled") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let include_deleted = _parameters + .get("include_deleted") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let include = _parameters + .get("include") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let filter_source = _parameters + .get("filter[source]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let ts_start = _parameters + .get("ts_start") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let ts_end = _parameters + .get("ts_end") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_tag_policies::ListTagPoliciesOptionalParams::default(); + params.include_disabled = include_disabled; + params.include_deleted = include_deleted; + params.include = include; + params.filter_source = filter_source; + params.ts_start = ts_start; + params.ts_end = ts_end; + let response = match block_on(api.list_tag_policies_with_http_info(params)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_create_tag_policy(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_tag_policies + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.create_tag_policy_with_http_info(body)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_delete_tag_policy(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_tag_policies + .as_ref() + .expect("api instance not found"); + let policy_id = serde_json::from_value(_parameters.get("policy_id").unwrap().clone()).unwrap(); + let hard_delete = _parameters + .get("hard_delete") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_tag_policies::DeleteTagPolicyOptionalParams::default(); + params.hard_delete = hard_delete; + let response = match block_on(api.delete_tag_policy_with_http_info(policy_id, params)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_get_tag_policy(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_tag_policies + .as_ref() + .expect("api instance not found"); + let policy_id = serde_json::from_value(_parameters.get("policy_id").unwrap().clone()).unwrap(); + let include = _parameters + .get("include") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let ts_start = _parameters + .get("ts_start") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let ts_end = _parameters + .get("ts_end") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_tag_policies::GetTagPolicyOptionalParams::default(); + params.include = include; + params.ts_start = ts_start; + params.ts_end = ts_end; + let response = match block_on(api.get_tag_policy_with_http_info(policy_id, params)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_update_tag_policy(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_tag_policies + .as_ref() + .expect("api instance not found"); + let policy_id = serde_json::from_value(_parameters.get("policy_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.update_tag_policy_with_http_info(policy_id, body)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_get_tag_policy_score(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_tag_policies + .as_ref() + .expect("api instance not found"); + let policy_id = serde_json::from_value(_parameters.get("policy_id").unwrap().clone()).unwrap(); + let ts_start = _parameters + .get("ts_start") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let ts_end = _parameters + .get("ts_end") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_tag_policies::GetTagPolicyScoreOptionalParams::default(); + params.ts_start = ts_start; + params.ts_end = ts_end; + let response = match block_on(api.get_tag_policy_score_with_http_info(policy_id, params)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_list_teams(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances