From a9db15fc77560cd9518a169956481a1ffca3a937 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Mon, 17 Nov 2025 22:06:53 +0000 Subject: [PATCH] Regenerate client from commit 950aa15 of spec repo --- .generator/schemas/v2/openapi.yaml | 734 +++++++ ...ction-queries_AddRoleToRestrictionQuery.rs | 31 + ...triction-queries_CreateRestrictionQuery.rs | 27 + ...triction-queries_DeleteRestrictionQuery.rs | 20 + ...restriction-queries_GetRestrictionQuery.rs | 20 + ...riction-queries_GetRoleRestrictionQuery.rs | 18 + ...triction-queries_ListRestrictionQueries.rs | 19 + ...ction-queries_ListRestrictionQueryRoles.rs | 24 + ...tion-queries_ListUserRestrictionQueries.rs | 20 + ...-queries_RemoveRoleFromRestrictionQuery.rs | 31 + ...riction-queries_ReplaceRestrictionQuery.rs | 31 + ...triction-queries_UpdateRestrictionQuery.rs | 31 + src/datadog/configuration.rs | 11 + .../api/api_logs_restriction_queries.rs | 1759 +++++++++++++++++ src/datadogV2/api/mod.rs | 1 + src/datadogV2/mod.rs | 1 + src/datadogV2/model/mod.rs | 38 +- .../model_logs_restriction_queries_type.rs | 48 + .../model_restriction_query_attributes.rs | 211 ++ ...del_restriction_query_create_attributes.rs | 94 + .../model_restriction_query_create_data.rs | 135 ++ .../model_restriction_query_create_payload.rs | 105 + .../model_restriction_query_list_response.rs | 110 ++ ...estriction_query_response_included_item.rs | 35 + .../model/model_restriction_query_role.rs | 125 ++ .../model_restriction_query_role_attribute.rs | 105 + .../model_restriction_query_roles_response.rs | 105 + ...del_restriction_query_update_attributes.rs | 94 + .../model_restriction_query_update_data.rs | 135 ++ .../model_restriction_query_update_payload.rs | 105 + ...el_restriction_query_with_relationships.rs | 169 ++ ...ction_query_with_relationships_response.rs | 131 ++ ...restriction_query_without_relationships.rs | 143 ++ ...on_query_without_relationships_response.rs | 110 ++ ...-query-returns-Bad-Request-response.frozen | 1 + ...on-query-returns-Bad-Request-response.json | 39 + ...striction-query-returns-OK-response.frozen | 1 + ...restriction-query-returns-OK-response.json | 67 + ...-query-returns-Bad-Request-response.frozen | 1 + ...on-query-returns-Bad-Request-response.json | 33 + ...on-query-returns-Not-found-response.frozen | 1 + ...tion-query-returns-Not-found-response.json | 33 + ...striction-query-returns-OK-response.frozen | 1 + ...restriction-query-returns-OK-response.json | 95 + ...-query-returns-Bad-Request-response.frozen | 1 + ...on-query-returns-Bad-Request-response.json | 33 + ...on-query-returns-Not-found-response.frozen | 1 + ...tion-query-returns-Not-found-response.json | 33 + ...striction-query-returns-OK-response.frozen | 1 + ...restriction-query-returns-OK-response.json | 95 + ...n-user-returns-Bad-Request-response.frozen | 1 + ...ven-user-returns-Bad-Request-response.json | 33 + ...ven-user-returns-Not-found-response.frozen | 1 + ...given-user-returns-Not-found-response.json | 33 + ...n-role-returns-Bad-Request-response.frozen | 1 + ...ven-role-returns-Bad-Request-response.json | 33 + ...ven-role-returns-Not-found-response.frozen | 1 + ...given-role-returns-Not-found-response.json | 33 + ...or-a-given-role-returns-OK-response.frozen | 1 + ...-for-a-given-role-returns-OK-response.json | 91 + ...-query-returns-Bad-Request-response.frozen | 1 + ...on-query-returns-Bad-Request-response.json | 39 + ...on-query-returns-Not-found-response.frozen | 1 + ...tion-query-returns-Not-found-response.json | 39 + ...striction-query-returns-OK-response.frozen | 1 + ...restriction-query-returns-OK-response.json | 159 ++ ...riction-queries-returns-OK-response.frozen | 1 + ...striction-queries-returns-OK-response.json | 33 + ...-query-returns-Bad-Request-response.frozen | 1 + ...on-query-returns-Bad-Request-response.json | 33 + ...on-query-returns-Not-found-response.frozen | 1 + ...tion-query-returns-Not-found-response.json | 33 + ...striction-query-returns-OK-response.frozen | 1 + ...restriction-query-returns-OK-response.json | 95 + tests/scenarios/features/v2/given.json | 12 + .../v2/logs_restriction_queries.feature | 287 +++ tests/scenarios/features/v2/undo.json | 73 + tests/scenarios/function_mappings.rs | 396 ++++ 78 files changed, 6644 insertions(+), 2 deletions(-) create mode 100644 examples/v2_logs-restriction-queries_AddRoleToRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_CreateRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_DeleteRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_GetRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_GetRoleRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_ListRestrictionQueries.rs create mode 100644 examples/v2_logs-restriction-queries_ListRestrictionQueryRoles.rs create mode 100644 examples/v2_logs-restriction-queries_ListUserRestrictionQueries.rs create mode 100644 examples/v2_logs-restriction-queries_RemoveRoleFromRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_ReplaceRestrictionQuery.rs create mode 100644 examples/v2_logs-restriction-queries_UpdateRestrictionQuery.rs create mode 100644 src/datadogV2/api/api_logs_restriction_queries.rs create mode 100644 src/datadogV2/model/model_logs_restriction_queries_type.rs create mode 100644 src/datadogV2/model/model_restriction_query_attributes.rs create mode 100644 src/datadogV2/model/model_restriction_query_create_attributes.rs create mode 100644 src/datadogV2/model/model_restriction_query_create_data.rs create mode 100644 src/datadogV2/model/model_restriction_query_create_payload.rs create mode 100644 src/datadogV2/model/model_restriction_query_list_response.rs create mode 100644 src/datadogV2/model/model_restriction_query_response_included_item.rs create mode 100644 src/datadogV2/model/model_restriction_query_role.rs create mode 100644 src/datadogV2/model/model_restriction_query_role_attribute.rs create mode 100644 src/datadogV2/model/model_restriction_query_roles_response.rs create mode 100644 src/datadogV2/model/model_restriction_query_update_attributes.rs create mode 100644 src/datadogV2/model/model_restriction_query_update_data.rs create mode 100644 src/datadogV2/model/model_restriction_query_update_payload.rs create mode 100644 src/datadogV2/model/model_restriction_query_with_relationships.rs create mode 100644 src/datadogV2/model/model_restriction_query_with_relationships_response.rs create mode 100644 src/datadogV2/model/model_restriction_query_without_relationships.rs create mode 100644 src/datadogV2/model/model_restriction_query_without_relationships_response.rs create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.json create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.json create mode 100644 tests/scenarios/features/v2/logs_restriction_queries.feature diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 2b877f268..c15bda9a5 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -945,6 +945,27 @@ components: required: true schema: type: string + RestrictionQueryID: + description: The ID of the restriction query. + in: path + name: restriction_query_id + required: true + schema: + type: string + RestrictionQueryRoleID: + description: The ID of the role. + in: path + name: role_id + required: true + schema: + type: string + RestrictionQueryUserID: + description: The ID of the user. + in: path + name: user_id + required: true + schema: + type: string RetentionFilterIdParam: description: The ID of the retention filter. in: path @@ -30115,6 +30136,15 @@ components: example: eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ== type: string type: object + LogsRestrictionQueriesType: + default: logs_restriction_queries + description: Restriction query resource type. + enum: + - logs_restriction_queries + example: logs_restriction_queries + type: string + x-enum-varnames: + - LOGS_RESTRICTION_QUERIES LogsSort: description: Sort parameters when querying logs. enum: @@ -41436,6 +41466,191 @@ components: required: - data type: object + RestrictionQueryAttributes: + description: Attributes of the restriction query. + properties: + created_at: + description: Creation time of the restriction query. + example: '2020-03-17T21:06:44.000Z' + format: date-time + readOnly: true + type: string + last_modifier_email: + description: Email of the user who last modified this restriction query. + example: user@example.com + readOnly: true + type: string + last_modifier_name: + description: Name of the user who last modified this restriction query. + example: John Doe + readOnly: true + type: string + modified_at: + description: Time of last restriction query modification. + example: '2020-03-17T21:15:15.000Z' + format: date-time + readOnly: true + type: string + restriction_query: + description: The query that defines the restriction. Only the content matching + the query can be returned. + example: env:sandbox + type: string + role_count: + description: Number of roles associated with this restriction query. + example: 3 + format: int64 + readOnly: true + type: integer + user_count: + description: Number of users associated with this restriction query. + example: 5 + format: int64 + readOnly: true + type: integer + type: object + RestrictionQueryCreateAttributes: + description: Attributes of the created restriction query. + properties: + restriction_query: + description: The restriction query. + example: env:sandbox + type: string + required: + - restriction_query + type: object + RestrictionQueryCreateData: + description: Data related to the creation of a restriction query. + properties: + attributes: + $ref: '#/components/schemas/RestrictionQueryCreateAttributes' + type: + $ref: '#/components/schemas/LogsRestrictionQueriesType' + type: object + RestrictionQueryCreatePayload: + description: Create a restriction query. + properties: + data: + $ref: '#/components/schemas/RestrictionQueryCreateData' + type: object + RestrictionQueryListResponse: + description: Response containing information about multiple restriction queries. + properties: + data: + description: Array of returned restriction queries. + items: + $ref: '#/components/schemas/RestrictionQueryWithoutRelationships' + type: array + type: object + RestrictionQueryResponseIncludedItem: + description: An object related to a restriction query. + oneOf: + - $ref: '#/components/schemas/RestrictionQueryRole' + RestrictionQueryRole: + description: Partial role object. + properties: + attributes: + $ref: '#/components/schemas/RestrictionQueryRoleAttribute' + id: + description: ID of the role. + example: + type: string + type: + $ref: '#/components/schemas/RolesType' + required: + - type + - id + - attributes + type: object + RestrictionQueryRoleAttribute: + description: Attributes of the role for a restriction query. + properties: + name: + description: The role name. + example: Datadog Admin Role + type: string + type: object + RestrictionQueryRolesResponse: + description: Response containing information about roles attached to a restriction + query. + properties: + data: + description: Array of roles. + items: + $ref: '#/components/schemas/RestrictionQueryRole' + type: array + type: object + RestrictionQueryUpdateAttributes: + description: Attributes of the edited restriction query. + properties: + restriction_query: + description: The restriction query. + example: env:sandbox + type: string + required: + - restriction_query + type: object + RestrictionQueryUpdateData: + description: Data related to the update of a restriction query. + properties: + attributes: + $ref: '#/components/schemas/RestrictionQueryUpdateAttributes' + type: + $ref: '#/components/schemas/LogsRestrictionQueriesType' + type: object + RestrictionQueryUpdatePayload: + description: Update a restriction query. + properties: + data: + $ref: '#/components/schemas/RestrictionQueryUpdateData' + type: object + RestrictionQueryWithRelationships: + description: Restriction query object returned by the API. + properties: + attributes: + $ref: '#/components/schemas/RestrictionQueryAttributes' + id: + description: ID of the restriction query. + example: 79a0e60a-644a-11ea-ad29-43329f7f58b5 + type: string + relationships: + $ref: '#/components/schemas/UserRelationships' + type: + $ref: '#/components/schemas/LogsRestrictionQueriesType' + type: object + RestrictionQueryWithRelationshipsResponse: + description: Response containing information about a single restriction query. + properties: + data: + $ref: '#/components/schemas/RestrictionQueryWithRelationships' + included: + description: Array of objects related to the restriction query. + items: + $ref: '#/components/schemas/RestrictionQueryResponseIncludedItem' + type: array + type: object + RestrictionQueryWithoutRelationships: + description: Restriction query object returned by the API. + properties: + attributes: + $ref: '#/components/schemas/RestrictionQueryAttributes' + id: + description: ID of the restriction query. + example: 79a0e60a-644a-11ea-ad29-43329f7f58b5 + type: string + type: + default: logs_restriction_queries + description: Restriction queries type. + example: logs_restriction_queries + readOnly: true + type: string + type: object + RestrictionQueryWithoutRelationshipsResponse: + description: Response containing information about a single restriction query. + properties: + data: + $ref: '#/components/schemas/RestrictionQueryWithoutRelationships' + type: object RetentionFilter: description: The definition of the retention filter. properties: @@ -69398,6 +69613,487 @@ paths: operator: OR permissions: - logs_generate_metrics + /api/v2/logs/config/restriction_queries: + get: + description: Returns all restriction queries, including their names and IDs. + operationId: ListRestrictionQueries + parameters: + - $ref: '#/components/parameters/PageSize' + - $ref: '#/components/parameters/PageNumber' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryListResponse' + description: OK + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: List restriction queries + tags: + - Logs Restriction Queries + x-permission: + operator: OR + permissions: + - logs_read_config + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + post: + description: Create a new restriction query for your organization. + operationId: CreateRestrictionQuery + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryCreatePayload' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryWithoutRelationshipsResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Create a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - user_access_manage + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + /api/v2/logs/config/restriction_queries/role/{role_id}: + get: + description: Get restriction query for a given role. + operationId: GetRoleRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryRoleID' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryListResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get restriction query for a given role + tags: + - Logs Restriction Queries + x-permission: + operator: OR + permissions: + - logs_read_config + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + /api/v2/logs/config/restriction_queries/user/{user_id}: + get: + description: Get all restriction queries for a given user. + operationId: ListUserRestrictionQueries + parameters: + - $ref: '#/components/parameters/RestrictionQueryUserID' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryListResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get all restriction queries for a given user + tags: + - Logs Restriction Queries + x-permission: + operator: OR + permissions: + - logs_read_config + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + /api/v2/logs/config/restriction_queries/{restriction_query_id}: + delete: + description: Deletes a restriction query. + operationId: DeleteRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + responses: + '204': + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Delete a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - user_access_manage + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + get: + description: Get a restriction query in the organization specified by the restriction + query's `restriction_query_id`. + operationId: GetRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryWithRelationshipsResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - logs_read_config + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + patch: + description: Edit a restriction query. + operationId: UpdateRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryUpdatePayload' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryWithoutRelationshipsResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Update a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - user_access_manage + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + put: + description: Replace a restriction query. + operationId: ReplaceRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryUpdatePayload' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryWithoutRelationshipsResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Replace a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - user_access_manage + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + /api/v2/logs/config/restriction_queries/{restriction_query_id}/roles: + delete: + description: Removes a role from a restriction query. + operationId: RemoveRoleFromRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RelationshipToRole' + required: true + responses: + '204': + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Revoke role from a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - user_access_manage + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + get: + description: Returns all roles that have a given restriction query. + operationId: ListRestrictionQueryRoles + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + - $ref: '#/components/parameters/PageSize' + - $ref: '#/components/parameters/PageNumber' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RestrictionQueryRolesResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: List roles for a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - logs_read_config + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' + post: + description: 'Adds a role to a restriction query. + + + **Note**: This operation automatically grants the `logs_read_data` permission + to the role if it doesn''t already have it.' + operationId: AddRoleToRestrictionQuery + parameters: + - $ref: '#/components/parameters/RestrictionQueryID' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RelationshipToRole' + required: true + responses: + '204': + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Grant role to a restriction query + tags: + - Logs Restriction Queries + x-codegen-request-body-name: body + x-permission: + operator: OR + permissions: + - user_access_manage + x-unstable: '**Note**: This endpoint is in public beta. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/logs/events: get: description: 'List endpoint returns logs that match a log search query. @@ -84267,6 +84963,44 @@ tags: description: Find out more at url: https://docs.datadoghq.com/logs/logs_to_metrics/ name: Logs Metrics +- description: '**Note: This endpoint is in public beta. If you have any feedback, + contact [Datadog support](https://docs.datadoghq.com/help/).** + + + A Restriction Query is a logs query that restricts which logs the `logs_read_data` + permission grants read access to. + + For users whose roles have Restriction Queries, any log query they make only returns + those log events that also match + + one of their Restriction Queries. This is true whether the user queries log events + from any log-related feature, including + + the log explorer, Live Tail, re-hydration, or a dashboard widget. + + + Restriction Queries currently only support use of the following components of + log events: + + + - Reserved attributes + + - The log message + + - Tags + + + To restrict read access on log data, add a team tag to log events to indicate + which teams own them, and then scope Restriction Queries to the relevant values + of the team tag. Tags can be applied to log events in many ways, and a log event + can have multiple tags with the same key (like team) and different values. This + means the same log event can be visible to roles whose restriction queries are + scoped to different team values. + + + See [How to Set Up RBAC for Logs](https://docs.datadoghq.com/logs/guide/logs-rbac/?tab=api#restrict-access-to-logs) + for details on how to add restriction queries.' + name: Logs Restriction Queries - description: "The metrics endpoint allows you to:\n\n- Post metrics data so it can be graphed on Datadog\u2019s dashboards\n- Query metrics from any time period (timeseries and scalar)\n- Modify tag configurations for metrics\n- View tags diff --git a/examples/v2_logs-restriction-queries_AddRoleToRestrictionQuery.rs b/examples/v2_logs-restriction-queries_AddRoleToRestrictionQuery.rs new file mode 100644 index 000000000..6dbbd2afe --- /dev/null +++ b/examples/v2_logs-restriction-queries_AddRoleToRestrictionQuery.rs @@ -0,0 +1,31 @@ +// Grant role to a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; +use datadog_api_client::datadogV2::model::RelationshipToRole; +use datadog_api_client::datadogV2::model::RelationshipToRoleData; +use datadog_api_client::datadogV2::model::RolesType; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + + // there is a valid "role" in the system + let role_data_id = std::env::var("ROLE_DATA_ID").unwrap(); + let body = RelationshipToRole::new().data( + RelationshipToRoleData::new() + .id(role_data_id.clone()) + .type_(RolesType::ROLES), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.AddRoleToRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .add_role_to_restriction_query(restriction_query_data_id.clone(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_CreateRestrictionQuery.rs b/examples/v2_logs-restriction-queries_CreateRestrictionQuery.rs new file mode 100644 index 000000000..9e2a79eae --- /dev/null +++ b/examples/v2_logs-restriction-queries_CreateRestrictionQuery.rs @@ -0,0 +1,27 @@ +// Create a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; +use datadog_api_client::datadogV2::model::LogsRestrictionQueriesType; +use datadog_api_client::datadogV2::model::RestrictionQueryCreateAttributes; +use datadog_api_client::datadogV2::model::RestrictionQueryCreateData; +use datadog_api_client::datadogV2::model::RestrictionQueryCreatePayload; + +#[tokio::main] +async fn main() { + let body = RestrictionQueryCreatePayload::new().data( + RestrictionQueryCreateData::new() + .attributes(RestrictionQueryCreateAttributes::new( + "env:sandbox".to_string(), + )) + .type_(LogsRestrictionQueriesType::LOGS_RESTRICTION_QUERIES), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.CreateRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api.create_restriction_query(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_DeleteRestrictionQuery.rs b/examples/v2_logs-restriction-queries_DeleteRestrictionQuery.rs new file mode 100644 index 000000000..a70b1634f --- /dev/null +++ b/examples/v2_logs-restriction-queries_DeleteRestrictionQuery.rs @@ -0,0 +1,20 @@ +// Delete a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.DeleteRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .delete_restriction_query(restriction_query_data_id.clone()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_GetRestrictionQuery.rs b/examples/v2_logs-restriction-queries_GetRestrictionQuery.rs new file mode 100644 index 000000000..a28e09fe3 --- /dev/null +++ b/examples/v2_logs-restriction-queries_GetRestrictionQuery.rs @@ -0,0 +1,20 @@ +// Get a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .get_restriction_query(restriction_query_data_id.clone()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_GetRoleRestrictionQuery.rs b/examples/v2_logs-restriction-queries_GetRoleRestrictionQuery.rs new file mode 100644 index 000000000..188849bf9 --- /dev/null +++ b/examples/v2_logs-restriction-queries_GetRoleRestrictionQuery.rs @@ -0,0 +1,18 @@ +// Get restriction query for a given role returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; + +#[tokio::main] +async fn main() { + // there is a valid "role" in the system + let role_data_id = std::env::var("ROLE_DATA_ID").unwrap(); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetRoleRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api.get_role_restriction_query(role_data_id.clone()).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_ListRestrictionQueries.rs b/examples/v2_logs-restriction-queries_ListRestrictionQueries.rs new file mode 100644 index 000000000..d43079712 --- /dev/null +++ b/examples/v2_logs-restriction-queries_ListRestrictionQueries.rs @@ -0,0 +1,19 @@ +// List restriction queries returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::ListRestrictionQueriesOptionalParams; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListRestrictionQueries", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .list_restriction_queries(ListRestrictionQueriesOptionalParams::default()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_ListRestrictionQueryRoles.rs b/examples/v2_logs-restriction-queries_ListRestrictionQueryRoles.rs new file mode 100644 index 000000000..779add7ad --- /dev/null +++ b/examples/v2_logs-restriction-queries_ListRestrictionQueryRoles.rs @@ -0,0 +1,24 @@ +// List roles for a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::ListRestrictionQueryRolesOptionalParams; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListRestrictionQueryRoles", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .list_restriction_query_roles( + restriction_query_data_id.clone(), + ListRestrictionQueryRolesOptionalParams::default(), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_ListUserRestrictionQueries.rs b/examples/v2_logs-restriction-queries_ListUserRestrictionQueries.rs new file mode 100644 index 000000000..305fdbdea --- /dev/null +++ b/examples/v2_logs-restriction-queries_ListUserRestrictionQueries.rs @@ -0,0 +1,20 @@ +// Get all restriction queries for a given user returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; + +#[tokio::main] +async fn main() { + // there is a valid "user" in the system + let user_data_id = std::env::var("USER_DATA_ID").unwrap(); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListUserRestrictionQueries", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .list_user_restriction_queries(user_data_id.clone()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_RemoveRoleFromRestrictionQuery.rs b/examples/v2_logs-restriction-queries_RemoveRoleFromRestrictionQuery.rs new file mode 100644 index 000000000..492443be4 --- /dev/null +++ b/examples/v2_logs-restriction-queries_RemoveRoleFromRestrictionQuery.rs @@ -0,0 +1,31 @@ +// Revoke role from a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; +use datadog_api_client::datadogV2::model::RelationshipToRole; +use datadog_api_client::datadogV2::model::RelationshipToRoleData; +use datadog_api_client::datadogV2::model::RolesType; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + + // there is a valid "role" in the system + let role_data_id = std::env::var("ROLE_DATA_ID").unwrap(); + let body = RelationshipToRole::new().data( + RelationshipToRoleData::new() + .id(role_data_id.clone()) + .type_(RolesType::ROLES), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.RemoveRoleFromRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .remove_role_from_restriction_query(restriction_query_data_id.clone(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_ReplaceRestrictionQuery.rs b/examples/v2_logs-restriction-queries_ReplaceRestrictionQuery.rs new file mode 100644 index 000000000..5caf7389e --- /dev/null +++ b/examples/v2_logs-restriction-queries_ReplaceRestrictionQuery.rs @@ -0,0 +1,31 @@ +// Replace a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; +use datadog_api_client::datadogV2::model::LogsRestrictionQueriesType; +use datadog_api_client::datadogV2::model::RestrictionQueryUpdateAttributes; +use datadog_api_client::datadogV2::model::RestrictionQueryUpdateData; +use datadog_api_client::datadogV2::model::RestrictionQueryUpdatePayload; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + let body = RestrictionQueryUpdatePayload::new().data( + RestrictionQueryUpdateData::new() + .attributes(RestrictionQueryUpdateAttributes::new( + "env:staging".to_string(), + )) + .type_(LogsRestrictionQueriesType::LOGS_RESTRICTION_QUERIES), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ReplaceRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .replace_restriction_query(restriction_query_data_id.clone(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_logs-restriction-queries_UpdateRestrictionQuery.rs b/examples/v2_logs-restriction-queries_UpdateRestrictionQuery.rs new file mode 100644 index 000000000..181d94c81 --- /dev/null +++ b/examples/v2_logs-restriction-queries_UpdateRestrictionQuery.rs @@ -0,0 +1,31 @@ +// Update a restriction query returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI; +use datadog_api_client::datadogV2::model::LogsRestrictionQueriesType; +use datadog_api_client::datadogV2::model::RestrictionQueryUpdateAttributes; +use datadog_api_client::datadogV2::model::RestrictionQueryUpdateData; +use datadog_api_client::datadogV2::model::RestrictionQueryUpdatePayload; + +#[tokio::main] +async fn main() { + // there is a valid "restriction_query" in the system + let restriction_query_data_id = std::env::var("RESTRICTION_QUERY_DATA_ID").unwrap(); + let body = RestrictionQueryUpdatePayload::new().data( + RestrictionQueryUpdateData::new() + .attributes(RestrictionQueryUpdateAttributes::new( + "env:production".to_string(), + )) + .type_(LogsRestrictionQueriesType::LOGS_RESTRICTION_QUERIES), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.UpdateRestrictionQuery", true); + let api = LogsRestrictionQueriesAPI::with_config(configuration); + let resp = api + .update_restriction_query(restriction_query_data_id.clone(), 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 90d90ee11..e6e109660 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -210,6 +210,17 @@ impl Default for Configuration { ("v2.update_incident_notification_template".to_owned(), false), ("v2.update_incident_todo".to_owned(), false), ("v2.update_incident_type".to_owned(), false), + ("v2.add_role_to_restriction_query".to_owned(), false), + ("v2.create_restriction_query".to_owned(), false), + ("v2.delete_restriction_query".to_owned(), false), + ("v2.get_restriction_query".to_owned(), false), + ("v2.get_role_restriction_query".to_owned(), false), + ("v2.list_restriction_queries".to_owned(), false), + ("v2.list_restriction_query_roles".to_owned(), false), + ("v2.list_user_restriction_queries".to_owned(), false), + ("v2.remove_role_from_restriction_query".to_owned(), false), + ("v2.replace_restriction_query".to_owned(), false), + ("v2.update_restriction_query".to_owned(), false), ("v2.create_monitor_user_template".to_owned(), false), ("v2.delete_monitor_user_template".to_owned(), false), ("v2.get_monitor_user_template".to_owned(), false), diff --git a/src/datadogV2/api/api_logs_restriction_queries.rs b/src/datadogV2/api/api_logs_restriction_queries.rs new file mode 100644 index 000000000..6e986a658 --- /dev/null +++ b/src/datadogV2/api/api_logs_restriction_queries.rs @@ -0,0 +1,1759 @@ +// 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; + +/// ListRestrictionQueriesOptionalParams is a struct for passing parameters to the method [`LogsRestrictionQueriesAPI::list_restriction_queries`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct ListRestrictionQueriesOptionalParams { + /// Size for a given page. The maximum allowed value is 100. + pub page_size: Option, + /// Specific page number to return. + pub page_number: Option, +} + +impl ListRestrictionQueriesOptionalParams { + /// Size for a given page. The maximum allowed value is 100. + pub fn page_size(mut self, value: i64) -> Self { + self.page_size = Some(value); + self + } + /// Specific page number to return. + pub fn page_number(mut self, value: i64) -> Self { + self.page_number = Some(value); + self + } +} + +/// ListRestrictionQueryRolesOptionalParams is a struct for passing parameters to the method [`LogsRestrictionQueriesAPI::list_restriction_query_roles`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct ListRestrictionQueryRolesOptionalParams { + /// Size for a given page. The maximum allowed value is 100. + pub page_size: Option, + /// Specific page number to return. + pub page_number: Option, +} + +impl ListRestrictionQueryRolesOptionalParams { + /// Size for a given page. The maximum allowed value is 100. + pub fn page_size(mut self, value: i64) -> Self { + self.page_size = Some(value); + self + } + /// Specific page number to return. + pub fn page_number(mut self, value: i64) -> Self { + self.page_number = Some(value); + self + } +} + +/// AddRoleToRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::add_role_to_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum AddRoleToRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// CreateRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::create_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// DeleteRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::delete_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::get_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetRoleRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::get_role_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetRoleRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListRestrictionQueriesError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::list_restriction_queries`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListRestrictionQueriesError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListRestrictionQueryRolesError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::list_restriction_query_roles`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListRestrictionQueryRolesError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListUserRestrictionQueriesError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::list_user_restriction_queries`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListUserRestrictionQueriesError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// RemoveRoleFromRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::remove_role_from_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RemoveRoleFromRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ReplaceRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::replace_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ReplaceRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// UpdateRestrictionQueryError is a struct for typed errors of method [`LogsRestrictionQueriesAPI::update_restriction_query`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateRestrictionQueryError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// **Note: This endpoint is in public beta. If you have any feedback, contact [Datadog support]().** +/// +/// A Restriction Query is a logs query that restricts which logs the `logs_read_data` permission grants read access to. +/// For users whose roles have Restriction Queries, any log query they make only returns those log events that also match +/// one of their Restriction Queries. This is true whether the user queries log events from any log-related feature, including +/// the log explorer, Live Tail, re-hydration, or a dashboard widget. +/// +/// Restriction Queries currently only support use of the following components of log events: +/// +/// - Reserved attributes +/// - The log message +/// - Tags +/// +/// To restrict read access on log data, add a team tag to log events to indicate which teams own them, and then scope Restriction Queries to the relevant values of the team tag. Tags can be applied to log events in many ways, and a log event can have multiple tags with the same key (like team) and different values. This means the same log event can be visible to roles whose restriction queries are scoped to different team values. +/// +/// See [How to Set Up RBAC for Logs]() for details on how to add restriction queries. +#[derive(Debug, Clone)] +pub struct LogsRestrictionQueriesAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for LogsRestrictionQueriesAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl LogsRestrictionQueriesAPI { + pub fn new() -> Self { + Self::default() + } + pub fn with_config(config: datadog::Configuration) -> Self { + let mut reqwest_client_builder = reqwest::Client::builder(); + + if let Some(proxy_url) = &config.proxy_url { + let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL"); + reqwest_client_builder = reqwest_client_builder.proxy(proxy); + } + + let mut middleware_client_builder = + reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap()); + + if config.enable_retry { + struct RetryableStatus; + impl reqwest_retry::RetryableStrategy for RetryableStatus { + fn handle( + &self, + res: &Result, + ) -> 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, + ); + + middleware_client_builder = middleware_client_builder.with(retry_middleware); + } + + let client = middleware_client_builder.build(); + + Self { config, client } + } + + pub fn with_client_and_config( + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, + ) -> Self { + Self { config, client } + } + + /// Adds a role to a restriction query. + /// + /// **Note**: This operation automatically grants the `logs_read_data` permission to the role if it doesn't already have it. + pub async fn add_role_to_restriction_query( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RelationshipToRole, + ) -> Result<(), datadog::Error> { + match self + .add_role_to_restriction_query_with_http_info(restriction_query_id, body) + .await + { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + + /// Adds a role to a restriction query. + /// + /// **Note**: This operation automatically grants the `logs_read_data` permission to the role if it doesn't already have it. + pub async fn add_role_to_restriction_query_with_http_info( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RelationshipToRole, + ) -> Result, datadog::Error> { + let local_configuration = &self.config; + let operation_id = "v2.add_role_to_restriction_query"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.add_role_to_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}/roles", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_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("*/*")); + + // 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)), + } + } + "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() { + 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)) + } + } + + /// Create a new restriction query for your organization. + pub async fn create_restriction_query( + &self, + body: crate::datadogV2::model::RestrictionQueryCreatePayload, + ) -> Result< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + datadog::Error, + > { + match self.create_restriction_query_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 restriction query for your organization. + pub async fn create_restriction_query_with_http_info( + &self, + body: crate::datadogV2::model::RestrictionQueryCreatePayload, + ) -> Result< + datadog::ResponseContent< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + >, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_restriction_query"; + 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_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries", + 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)), + } + } + "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::< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + >(&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)) + } + } + + /// Deletes a restriction query. + pub async fn delete_restriction_query( + &self, + restriction_query_id: String, + ) -> Result<(), datadog::Error> { + match self + .delete_restriction_query_with_http_info(restriction_query_id) + .await + { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + + /// Deletes a restriction query. + pub async fn delete_restriction_query_with_http_info( + &self, + restriction_query_id: String, + ) -> Result, datadog::Error> { + let local_configuration = &self.config; + let operation_id = "v2.delete_restriction_query"; + 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_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::DELETE, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("*/*")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: None, + }) + } else { + let local_entity: Option = + 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)) + } + } + + /// Get a restriction query in the organization specified by the restriction query's `restriction_query_id`. + pub async fn get_restriction_query( + &self, + restriction_query_id: String, + ) -> Result< + crate::datadogV2::model::RestrictionQueryWithRelationshipsResponse, + datadog::Error, + > { + match self + .get_restriction_query_with_http_info(restriction_query_id) + .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), + } + } + + /// Get a restriction query in the organization specified by the restriction query's `restriction_query_id`. + pub async fn get_restriction_query_with_http_info( + &self, + restriction_query_id: String, + ) -> Result< + datadog::ResponseContent< + crate::datadogV2::model::RestrictionQueryWithRelationshipsResponse, + >, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_restriction_query"; + 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_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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::< + crate::datadogV2::model::RestrictionQueryWithRelationshipsResponse, + >(&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)) + } + } + + /// Get restriction query for a given role. + pub async fn get_role_restriction_query( + &self, + role_id: String, + ) -> Result< + crate::datadogV2::model::RestrictionQueryListResponse, + datadog::Error, + > { + match self + .get_role_restriction_query_with_http_info(role_id) + .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), + } + } + + /// Get restriction query for a given role. + pub async fn get_role_restriction_query_with_http_info( + &self, + role_id: String, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_role_restriction_query"; + 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_role_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/role/{role_id}", + local_configuration.get_operation_host(operation_id), + role_id = datadog::urlencode(role_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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)) + } + } + + /// Returns all restriction queries, including their names and IDs. + pub async fn list_restriction_queries( + &self, + params: ListRestrictionQueriesOptionalParams, + ) -> Result< + crate::datadogV2::model::RestrictionQueryListResponse, + datadog::Error, + > { + match self.list_restriction_queries_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), + } + } + + /// Returns all restriction queries, including their names and IDs. + pub async fn list_restriction_queries_with_http_info( + &self, + params: ListRestrictionQueriesOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_restriction_queries"; + 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_restriction_queries' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let page_size = params.page_size; + let page_number = params.page_number; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries", + 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) = page_size { + local_req_builder = + local_req_builder.query(&[("page[size]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = page_number { + local_req_builder = + local_req_builder.query(&[("page[number]", &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)) + } + } + + /// Returns all roles that have a given restriction query. + pub async fn list_restriction_query_roles( + &self, + restriction_query_id: String, + params: ListRestrictionQueryRolesOptionalParams, + ) -> Result< + crate::datadogV2::model::RestrictionQueryRolesResponse, + datadog::Error, + > { + match self + .list_restriction_query_roles_with_http_info(restriction_query_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), + } + } + + /// Returns all roles that have a given restriction query. + pub async fn list_restriction_query_roles_with_http_info( + &self, + restriction_query_id: String, + params: ListRestrictionQueryRolesOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_restriction_query_roles"; + 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_restriction_query_roles' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let page_size = params.page_size; + let page_number = params.page_number; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}/roles", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = page_size { + local_req_builder = + local_req_builder.query(&[("page[size]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = page_number { + local_req_builder = + local_req_builder.query(&[("page[number]", &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)) + } + } + + /// Get all restriction queries for a given user. + pub async fn list_user_restriction_queries( + &self, + user_id: String, + ) -> Result< + crate::datadogV2::model::RestrictionQueryListResponse, + datadog::Error, + > { + match self + .list_user_restriction_queries_with_http_info(user_id) + .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), + } + } + + /// Get all restriction queries for a given user. + pub async fn list_user_restriction_queries_with_http_info( + &self, + user_id: String, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_user_restriction_queries"; + 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_user_restriction_queries' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/user/{user_id}", + local_configuration.get_operation_host(operation_id), + user_id = datadog::urlencode(user_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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)) + } + } + + /// Removes a role from a restriction query. + pub async fn remove_role_from_restriction_query( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RelationshipToRole, + ) -> Result<(), datadog::Error> { + match self + .remove_role_from_restriction_query_with_http_info(restriction_query_id, body) + .await + { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + + /// Removes a role from a restriction query. + pub async fn remove_role_from_restriction_query_with_http_info( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RelationshipToRole, + ) -> Result, datadog::Error> + { + let local_configuration = &self.config; + let operation_id = "v2.remove_role_from_restriction_query"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.remove_role_from_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}/roles", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::DELETE, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + 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"), + ); + }; + + // 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)), + } + } + "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() { + 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)) + } + } + + /// Replace a restriction query. + pub async fn replace_restriction_query( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RestrictionQueryUpdatePayload, + ) -> Result< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + datadog::Error, + > { + match self + .replace_restriction_query_with_http_info(restriction_query_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), + } + } + + /// Replace a restriction query. + pub async fn replace_restriction_query_with_http_info( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RestrictionQueryUpdatePayload, + ) -> Result< + datadog::ResponseContent< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + >, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.replace_restriction_query"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.replace_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PUT, 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)), + } + } + "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::< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + >(&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)) + } + } + + /// Edit a restriction query. + pub async fn update_restriction_query( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RestrictionQueryUpdatePayload, + ) -> Result< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + datadog::Error, + > { + match self + .update_restriction_query_with_http_info(restriction_query_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), + } + } + + /// Edit a restriction query. + pub async fn update_restriction_query_with_http_info( + &self, + restriction_query_id: String, + body: crate::datadogV2::model::RestrictionQueryUpdatePayload, + ) -> Result< + datadog::ResponseContent< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + >, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_restriction_query"; + 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_restriction_query' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/logs/config/restriction_queries/{restriction_query_id}", + local_configuration.get_operation_host(operation_id), + restriction_query_id = datadog::urlencode(restriction_query_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)), + } + } + "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::< + crate::datadogV2::model::RestrictionQueryWithoutRelationshipsResponse, + >(&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 9f04d6ed6..1aadfca1b 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -47,6 +47,7 @@ pub mod api_logs; pub mod api_logs_archives; pub mod api_logs_custom_destinations; pub mod api_logs_metrics; +pub mod api_logs_restriction_queries; pub mod api_metrics; pub mod api_microsoft_teams_integration; pub mod api_monitors; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index 4a2411941..b2298597f 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -48,6 +48,7 @@ pub use self::api::api_logs; pub use self::api::api_logs_archives; pub use self::api::api_logs_custom_destinations; pub use self::api::api_logs_metrics; +pub use self::api::api_logs_restriction_queries; pub use self::api::api_metrics; pub use self::api::api_microsoft_teams_integration; pub use self::api::api_monitors; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 1878768c9..3a9335523 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -3502,6 +3502,42 @@ pub mod model_logs_metric_update_attributes; pub use self::model_logs_metric_update_attributes::LogsMetricUpdateAttributes; pub mod model_logs_metric_update_compute; pub use self::model_logs_metric_update_compute::LogsMetricUpdateCompute; +pub mod model_restriction_query_list_response; +pub use self::model_restriction_query_list_response::RestrictionQueryListResponse; +pub mod model_restriction_query_without_relationships; +pub use self::model_restriction_query_without_relationships::RestrictionQueryWithoutRelationships; +pub mod model_restriction_query_attributes; +pub use self::model_restriction_query_attributes::RestrictionQueryAttributes; +pub mod model_restriction_query_create_payload; +pub use self::model_restriction_query_create_payload::RestrictionQueryCreatePayload; +pub mod model_restriction_query_create_data; +pub use self::model_restriction_query_create_data::RestrictionQueryCreateData; +pub mod model_restriction_query_create_attributes; +pub use self::model_restriction_query_create_attributes::RestrictionQueryCreateAttributes; +pub mod model_logs_restriction_queries_type; +pub use self::model_logs_restriction_queries_type::LogsRestrictionQueriesType; +pub mod model_restriction_query_without_relationships_response; +pub use self::model_restriction_query_without_relationships_response::RestrictionQueryWithoutRelationshipsResponse; +pub mod model_restriction_query_with_relationships_response; +pub use self::model_restriction_query_with_relationships_response::RestrictionQueryWithRelationshipsResponse; +pub mod model_restriction_query_with_relationships; +pub use self::model_restriction_query_with_relationships::RestrictionQueryWithRelationships; +pub mod model_user_relationships; +pub use self::model_user_relationships::UserRelationships; +pub mod model_restriction_query_role; +pub use self::model_restriction_query_role::RestrictionQueryRole; +pub mod model_restriction_query_role_attribute; +pub use self::model_restriction_query_role_attribute::RestrictionQueryRoleAttribute; +pub mod model_restriction_query_response_included_item; +pub use self::model_restriction_query_response_included_item::RestrictionQueryResponseIncludedItem; +pub mod model_restriction_query_update_payload; +pub use self::model_restriction_query_update_payload::RestrictionQueryUpdatePayload; +pub mod model_restriction_query_update_data; +pub use self::model_restriction_query_update_data::RestrictionQueryUpdateData; +pub mod model_restriction_query_update_attributes; +pub use self::model_restriction_query_update_attributes::RestrictionQueryUpdateAttributes; +pub mod model_restriction_query_roles_response; +pub use self::model_restriction_query_roles_response::RestrictionQueryRolesResponse; pub mod model_logs_sort; pub use self::model_logs_sort::LogsSort; pub mod model_logs_list_response; @@ -6060,8 +6096,6 @@ pub mod model_service_account_create_data; pub use self::model_service_account_create_data::ServiceAccountCreateData; pub mod model_service_account_create_attributes; pub use self::model_service_account_create_attributes::ServiceAccountCreateAttributes; -pub mod model_user_relationships; -pub use self::model_user_relationships::UserRelationships; pub mod model_user_response; pub use self::model_user_response::UserResponse; pub mod model_partial_application_key_response; diff --git a/src/datadogV2/model/model_logs_restriction_queries_type.rs b/src/datadogV2/model/model_logs_restriction_queries_type.rs new file mode 100644 index 000000000..e57dde39a --- /dev/null +++ b/src/datadogV2/model/model_logs_restriction_queries_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 LogsRestrictionQueriesType { + LOGS_RESTRICTION_QUERIES, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for LogsRestrictionQueriesType { + fn to_string(&self) -> String { + match self { + Self::LOGS_RESTRICTION_QUERIES => String::from("logs_restriction_queries"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for LogsRestrictionQueriesType { + 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 LogsRestrictionQueriesType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "logs_restriction_queries" => Self::LOGS_RESTRICTION_QUERIES, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_restriction_query_attributes.rs b/src/datadogV2/model/model_restriction_query_attributes.rs new file mode 100644 index 000000000..58924aa1d --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_attributes.rs @@ -0,0 +1,211 @@ +// 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 the restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryAttributes { + /// Creation time of the restriction query. + #[serde(rename = "created_at")] + pub created_at: Option>, + /// Email of the user who last modified this restriction query. + #[serde(rename = "last_modifier_email")] + pub last_modifier_email: Option, + /// Name of the user who last modified this restriction query. + #[serde(rename = "last_modifier_name")] + pub last_modifier_name: Option, + /// Time of last restriction query modification. + #[serde(rename = "modified_at")] + pub modified_at: Option>, + /// The query that defines the restriction. Only the content matching the query can be returned. + #[serde(rename = "restriction_query")] + pub restriction_query: Option, + /// Number of roles associated with this restriction query. + #[serde(rename = "role_count")] + pub role_count: Option, + /// Number of users associated with this restriction query. + #[serde(rename = "user_count")] + pub user_count: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryAttributes { + pub fn new() -> RestrictionQueryAttributes { + RestrictionQueryAttributes { + created_at: None, + last_modifier_email: None, + last_modifier_name: None, + modified_at: None, + restriction_query: None, + role_count: None, + user_count: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn created_at(mut self, value: chrono::DateTime) -> Self { + self.created_at = Some(value); + self + } + + pub fn last_modifier_email(mut self, value: String) -> Self { + self.last_modifier_email = Some(value); + self + } + + pub fn last_modifier_name(mut self, value: String) -> Self { + self.last_modifier_name = Some(value); + self + } + + pub fn modified_at(mut self, value: chrono::DateTime) -> Self { + self.modified_at = Some(value); + self + } + + pub fn restriction_query(mut self, value: String) -> Self { + self.restriction_query = Some(value); + self + } + + pub fn role_count(mut self, value: i64) -> Self { + self.role_count = Some(value); + self + } + + pub fn user_count(mut self, value: i64) -> Self { + self.user_count = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryAttributesVisitor; + impl<'a> Visitor<'a> for RestrictionQueryAttributesVisitor { + type Value = RestrictionQueryAttributes; + + 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 last_modifier_email: Option = None; + let mut last_modifier_name: Option = None; + let mut modified_at: Option> = None; + let mut restriction_query: Option = None; + let mut role_count: Option = None; + let mut user_count: 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" => { + if v.is_null() { + continue; + } + created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "last_modifier_email" => { + if v.is_null() { + continue; + } + last_modifier_email = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "last_modifier_name" => { + if v.is_null() { + continue; + } + last_modifier_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_at" => { + if v.is_null() { + continue; + } + modified_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "restriction_query" => { + if v.is_null() { + continue; + } + restriction_query = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "role_count" => { + if v.is_null() { + continue; + } + role_count = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "user_count" => { + if v.is_null() { + continue; + } + user_count = 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 = RestrictionQueryAttributes { + created_at, + last_modifier_email, + last_modifier_name, + modified_at, + restriction_query, + role_count, + user_count, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_create_attributes.rs b/src/datadogV2/model/model_restriction_query_create_attributes.rs new file mode 100644 index 000000000..b195920b9 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_create_attributes.rs @@ -0,0 +1,94 @@ +// 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 the created restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryCreateAttributes { + /// The restriction query. + #[serde(rename = "restriction_query")] + pub restriction_query: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryCreateAttributes { + pub fn new(restriction_query: String) -> RestrictionQueryCreateAttributes { + RestrictionQueryCreateAttributes { + restriction_query, + 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 RestrictionQueryCreateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryCreateAttributesVisitor; + impl<'a> Visitor<'a> for RestrictionQueryCreateAttributesVisitor { + type Value = RestrictionQueryCreateAttributes; + + 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 restriction_query: 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() { + "restriction_query" => { + restriction_query = + 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 restriction_query = restriction_query + .ok_or_else(|| M::Error::missing_field("restriction_query"))?; + + let content = RestrictionQueryCreateAttributes { + restriction_query, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryCreateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_create_data.rs b/src/datadogV2/model/model_restriction_query_create_data.rs new file mode 100644 index 000000000..3dd5ab424 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_create_data.rs @@ -0,0 +1,135 @@ +// 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 related to the creation of a restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryCreateData { + /// Attributes of the created restriction query. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Restriction query resource type. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryCreateData { + pub fn new() -> RestrictionQueryCreateData { + RestrictionQueryCreateData { + attributes: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::RestrictionQueryCreateAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::LogsRestrictionQueriesType) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryCreateData { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryCreateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryCreateDataVisitor; + impl<'a> Visitor<'a> for RestrictionQueryCreateDataVisitor { + type Value = RestrictionQueryCreateData; + + 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< + crate::datadogV2::model::RestrictionQueryCreateAttributes, + > = 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)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::LogsRestrictionQueriesType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = RestrictionQueryCreateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryCreateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_create_payload.rs b/src/datadogV2/model/model_restriction_query_create_payload.rs new file mode 100644 index 000000000..e44ca06c0 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_create_payload.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}; + +/// Create a restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryCreatePayload { + /// Data related to the creation of a restriction query. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryCreatePayload { + pub fn new() -> RestrictionQueryCreatePayload { + RestrictionQueryCreatePayload { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::RestrictionQueryCreateData) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryCreatePayload { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryCreatePayload { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryCreatePayloadVisitor; + impl<'a> Visitor<'a> for RestrictionQueryCreatePayloadVisitor { + type Value = RestrictionQueryCreatePayload; + + 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" => { + if v.is_null() { + continue; + } + 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 content = RestrictionQueryCreatePayload { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryCreatePayloadVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_list_response.rs b/src/datadogV2/model/model_restriction_query_list_response.rs new file mode 100644 index 000000000..11c01fd79 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_list_response.rs @@ -0,0 +1,110 @@ +// 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}; + +/// Response containing information about multiple restriction queries. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryListResponse { + /// Array of returned restriction queries. + #[serde(rename = "data")] + pub data: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryListResponse { + pub fn new() -> RestrictionQueryListResponse { + RestrictionQueryListResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data( + mut self, + value: Vec, + ) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryListResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryListResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryListResponseVisitor; + impl<'a> Visitor<'a> for RestrictionQueryListResponseVisitor { + type Value = RestrictionQueryListResponse; + + 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< + Vec, + > = 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" => { + if v.is_null() { + continue; + } + 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 content = RestrictionQueryListResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryListResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_response_included_item.rs b/src/datadogV2/model/model_restriction_query_response_included_item.rs new file mode 100644 index 000000000..67668e989 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_response_included_item.rs @@ -0,0 +1,35 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::{Deserialize, Deserializer, Serialize}; + +/// An object related to a restriction query. +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum RestrictionQueryResponseIncludedItem { + RestrictionQueryRole(Box), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for RestrictionQueryResponseIncludedItem { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value: serde_json::Value = Deserialize::deserialize(deserializer)?; + if let Ok(_v) = serde_json::from_value::>( + value.clone(), + ) { + if !_v._unparsed { + return Ok(RestrictionQueryResponseIncludedItem::RestrictionQueryRole( + _v, + )); + } + } + + return Ok(RestrictionQueryResponseIncludedItem::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/src/datadogV2/model/model_restriction_query_role.rs b/src/datadogV2/model/model_restriction_query_role.rs new file mode 100644 index 000000000..3369e7ffb --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_role.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}; + +/// Partial role object. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryRole { + /// Attributes of the role for a restriction query. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::RestrictionQueryRoleAttribute, + /// ID of the role. + #[serde(rename = "id")] + pub id: String, + /// Roles type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::RolesType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryRole { + pub fn new( + attributes: crate::datadogV2::model::RestrictionQueryRoleAttribute, + id: String, + type_: crate::datadogV2::model::RolesType, + ) -> RestrictionQueryRole { + RestrictionQueryRole { + 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 RestrictionQueryRole { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryRoleVisitor; + impl<'a> Visitor<'a> for RestrictionQueryRoleVisitor { + type Value = RestrictionQueryRole; + + 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::RolesType::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 = RestrictionQueryRole { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryRoleVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_role_attribute.rs b/src/datadogV2/model/model_restriction_query_role_attribute.rs new file mode 100644 index 000000000..7519f8cbb --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_role_attribute.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}; + +/// Attributes of the role for a restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryRoleAttribute { + /// The role name. + #[serde(rename = "name")] + pub name: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryRoleAttribute { + pub fn new() -> RestrictionQueryRoleAttribute { + RestrictionQueryRoleAttribute { + name: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn name(mut self, value: String) -> Self { + self.name = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryRoleAttribute { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryRoleAttribute { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryRoleAttributeVisitor; + impl<'a> Visitor<'a> for RestrictionQueryRoleAttributeVisitor { + type Value = RestrictionQueryRoleAttribute; + + 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 name: 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() { + "name" => { + if v.is_null() { + continue; + } + name = 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 = RestrictionQueryRoleAttribute { + name, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryRoleAttributeVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_roles_response.rs b/src/datadogV2/model/model_restriction_query_roles_response.rs new file mode 100644 index 000000000..df4537d59 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_roles_response.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}; + +/// Response containing information about roles attached to a restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryRolesResponse { + /// Array of roles. + #[serde(rename = "data")] + pub data: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryRolesResponse { + pub fn new() -> RestrictionQueryRolesResponse { + RestrictionQueryRolesResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: Vec) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryRolesResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryRolesResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryRolesResponseVisitor; + impl<'a> Visitor<'a> for RestrictionQueryRolesResponseVisitor { + type Value = RestrictionQueryRolesResponse; + + 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" => { + if v.is_null() { + continue; + } + 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 content = RestrictionQueryRolesResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryRolesResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_update_attributes.rs b/src/datadogV2/model/model_restriction_query_update_attributes.rs new file mode 100644 index 000000000..85d1c01e7 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_update_attributes.rs @@ -0,0 +1,94 @@ +// 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 the edited restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryUpdateAttributes { + /// The restriction query. + #[serde(rename = "restriction_query")] + pub restriction_query: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryUpdateAttributes { + pub fn new(restriction_query: String) -> RestrictionQueryUpdateAttributes { + RestrictionQueryUpdateAttributes { + restriction_query, + 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 RestrictionQueryUpdateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryUpdateAttributesVisitor; + impl<'a> Visitor<'a> for RestrictionQueryUpdateAttributesVisitor { + type Value = RestrictionQueryUpdateAttributes; + + 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 restriction_query: 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() { + "restriction_query" => { + restriction_query = + 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 restriction_query = restriction_query + .ok_or_else(|| M::Error::missing_field("restriction_query"))?; + + let content = RestrictionQueryUpdateAttributes { + restriction_query, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryUpdateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_update_data.rs b/src/datadogV2/model/model_restriction_query_update_data.rs new file mode 100644 index 000000000..86087a025 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_update_data.rs @@ -0,0 +1,135 @@ +// 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 related to the update of a restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryUpdateData { + /// Attributes of the edited restriction query. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Restriction query resource type. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryUpdateData { + pub fn new() -> RestrictionQueryUpdateData { + RestrictionQueryUpdateData { + attributes: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::RestrictionQueryUpdateAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::LogsRestrictionQueriesType) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryUpdateData { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryUpdateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryUpdateDataVisitor; + impl<'a> Visitor<'a> for RestrictionQueryUpdateDataVisitor { + type Value = RestrictionQueryUpdateData; + + 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< + crate::datadogV2::model::RestrictionQueryUpdateAttributes, + > = 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)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::LogsRestrictionQueriesType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = RestrictionQueryUpdateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryUpdateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_update_payload.rs b/src/datadogV2/model/model_restriction_query_update_payload.rs new file mode 100644 index 000000000..b25b33f56 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_update_payload.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}; + +/// Update a restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryUpdatePayload { + /// Data related to the update of a restriction query. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryUpdatePayload { + pub fn new() -> RestrictionQueryUpdatePayload { + RestrictionQueryUpdatePayload { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::RestrictionQueryUpdateData) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryUpdatePayload { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryUpdatePayload { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryUpdatePayloadVisitor; + impl<'a> Visitor<'a> for RestrictionQueryUpdatePayloadVisitor { + type Value = RestrictionQueryUpdatePayload; + + 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" => { + if v.is_null() { + continue; + } + 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 content = RestrictionQueryUpdatePayload { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryUpdatePayloadVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_with_relationships.rs b/src/datadogV2/model/model_restriction_query_with_relationships.rs new file mode 100644 index 000000000..5a3758fa7 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_with_relationships.rs @@ -0,0 +1,169 @@ +// 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}; + +/// Restriction query object returned by the API. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryWithRelationships { + /// Attributes of the restriction query. + #[serde(rename = "attributes")] + pub attributes: Option, + /// ID of the restriction query. + #[serde(rename = "id")] + pub id: Option, + /// Relationships of the user object. + #[serde(rename = "relationships")] + pub relationships: Option, + /// Restriction query resource type. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryWithRelationships { + pub fn new() -> RestrictionQueryWithRelationships { + RestrictionQueryWithRelationships { + attributes: None, + id: None, + relationships: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::RestrictionQueryAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn relationships(mut self, value: crate::datadogV2::model::UserRelationships) -> Self { + self.relationships = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::LogsRestrictionQueriesType) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryWithRelationships { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryWithRelationships { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryWithRelationshipsVisitor; + impl<'a> Visitor<'a> for RestrictionQueryWithRelationshipsVisitor { + type Value = RestrictionQueryWithRelationships; + + 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" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + if v.is_null() { + continue; + } + 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" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::LogsRestrictionQueriesType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = RestrictionQueryWithRelationships { + attributes, + id, + relationships, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryWithRelationshipsVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_with_relationships_response.rs b/src/datadogV2/model/model_restriction_query_with_relationships_response.rs new file mode 100644 index 000000000..39cb0c378 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_with_relationships_response.rs @@ -0,0 +1,131 @@ +// 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}; + +/// Response containing information about a single restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryWithRelationshipsResponse { + /// Restriction query object returned by the API. + #[serde(rename = "data")] + pub data: Option, + /// Array of objects related to the restriction query. + #[serde(rename = "included")] + pub included: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryWithRelationshipsResponse { + pub fn new() -> RestrictionQueryWithRelationshipsResponse { + RestrictionQueryWithRelationshipsResponse { + data: None, + included: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data( + mut self, + value: crate::datadogV2::model::RestrictionQueryWithRelationships, + ) -> Self { + self.data = Some(value); + self + } + + 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 Default for RestrictionQueryWithRelationshipsResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryWithRelationshipsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryWithRelationshipsResponseVisitor; + impl<'a> Visitor<'a> for RestrictionQueryWithRelationshipsResponseVisitor { + type Value = RestrictionQueryWithRelationshipsResponse; + + 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< + Vec, + > = 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" => { + if v.is_null() { + continue; + } + 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 content = RestrictionQueryWithRelationshipsResponse { + data, + included, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryWithRelationshipsResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_without_relationships.rs b/src/datadogV2/model/model_restriction_query_without_relationships.rs new file mode 100644 index 000000000..b1d9282bb --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_without_relationships.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}; + +/// Restriction query object returned by the API. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryWithoutRelationships { + /// Attributes of the restriction query. + #[serde(rename = "attributes")] + pub attributes: Option, + /// ID of the restriction query. + #[serde(rename = "id")] + pub id: Option, + /// Restriction queries type. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryWithoutRelationships { + pub fn new() -> RestrictionQueryWithoutRelationships { + RestrictionQueryWithoutRelationships { + attributes: None, + id: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::RestrictionQueryAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn type_(mut self, value: String) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryWithoutRelationships { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryWithoutRelationships { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryWithoutRelationshipsVisitor; + impl<'a> Visitor<'a> for RestrictionQueryWithoutRelationshipsVisitor { + type Value = RestrictionQueryWithoutRelationships; + + 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" => { + if v.is_null() { + continue; + } + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = 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 = RestrictionQueryWithoutRelationships { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryWithoutRelationshipsVisitor) + } +} diff --git a/src/datadogV2/model/model_restriction_query_without_relationships_response.rs b/src/datadogV2/model/model_restriction_query_without_relationships_response.rs new file mode 100644 index 000000000..fe8a46af4 --- /dev/null +++ b/src/datadogV2/model/model_restriction_query_without_relationships_response.rs @@ -0,0 +1,110 @@ +// 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}; + +/// Response containing information about a single restriction query. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct RestrictionQueryWithoutRelationshipsResponse { + /// Restriction query object returned by the API. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl RestrictionQueryWithoutRelationshipsResponse { + pub fn new() -> RestrictionQueryWithoutRelationshipsResponse { + RestrictionQueryWithoutRelationshipsResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data( + mut self, + value: crate::datadogV2::model::RestrictionQueryWithoutRelationships, + ) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for RestrictionQueryWithoutRelationshipsResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for RestrictionQueryWithoutRelationshipsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct RestrictionQueryWithoutRelationshipsResponseVisitor; + impl<'a> Visitor<'a> for RestrictionQueryWithoutRelationshipsResponseVisitor { + type Value = RestrictionQueryWithoutRelationshipsResponse; + + 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< + crate::datadogV2::model::RestrictionQueryWithoutRelationships, + > = 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" => { + if v.is_null() { + continue; + } + 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 content = RestrictionQueryWithoutRelationshipsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(RestrictionQueryWithoutRelationshipsResponseVisitor) + } +} diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..0f606a88e --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:33.023Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.json new file mode 100644 index 000000000..6fbd55d96 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-Bad-Request-response.json @@ -0,0 +1,39 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"test\":\"bad_request\"}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"errors\":[\"API input validation failed: {'_schema': [{'detail': 'Object must include `data` key.', 'source': {'pointer': '/'}}]}\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:33 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.frozen new file mode 100644 index 000000000..7c666081c --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:33.792Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.json new file mode 100644 index 000000000..8ecca2415 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Create-a-restriction-query-returns-OK-response.json @@ -0,0 +1,67 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"restriction_query\":\"env:sandbox\"},\"type\":\"logs_restriction_queries\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"logs_restriction_queries\",\"id\":\"7d16b5bc-c3fd-11f0-a3af-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:sandbox\",\"created_at\":\"2025-11-17T21:36:34.125787+00:00\",\"modified_at\":\"2025-11-17T21:36:34.125787+00:00\"}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:33 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/7d16b5bc-c3fd-11f0-a3af-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:33 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..27f3b15bf --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:34.603Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.json new file mode 100644 index 000000000..08bb0c843 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Bad-Request-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/malformed_id" + }, + "response": { + "body": { + "string": "{\"errors\":[\"uuid is not proper type\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:34 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.frozen new file mode 100644 index 000000000..000352ea2 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:34.974Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.json new file mode 100644 index 000000000..5737206ae --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-Not-found-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/00000000-0000-0000-0000-000000000000" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Restriction query not found\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:34 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.frozen new file mode 100644 index 000000000..90bbc2628 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:35.338Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.json new file mode 100644 index 000000000..d381fa279 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Delete-a-restriction-query-returns-OK-response.json @@ -0,0 +1,95 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"restriction_query\":\"env:sandbox\"},\"type\":\"logs_restriction_queries\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"logs_restriction_queries\",\"id\":\"7dfcd704-c3fd-11f0-a70b-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:sandbox\",\"created_at\":\"2025-11-17T21:36:35.634185+00:00\",\"modified_at\":\"2025-11-17T21:36:35.634185+00:00\"}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:35 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/7dfcd704-c3fd-11f0-a70b-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:35 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/7dfcd704-c3fd-11f0-a70b-da7ad0900002" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Restriction query not found\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:35 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..715d1386d --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:36.502Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.json new file mode 100644 index 000000000..888a0a014 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Bad-Request-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/malformed_id" + }, + "response": { + "body": { + "string": "{\"errors\":[\"uuid is not proper type\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:36 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.frozen new file mode 100644 index 000000000..c334b82ce --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:36.858Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.json new file mode 100644 index 000000000..2f5d750eb --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-Not-found-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/00000000-0000-0000-0000-000000000000" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Restriction query not found\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:36 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.frozen new file mode 100644 index 000000000..746afe3f0 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:37.364Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.json new file mode 100644 index 000000000..8a2863859 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-a-restriction-query-returns-OK-response.json @@ -0,0 +1,95 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"restriction_query\":\"env:sandbox\"},\"type\":\"logs_restriction_queries\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"logs_restriction_queries\",\"id\":\"7f34e18e-c3fd-11f0-8c23-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:sandbox\",\"created_at\":\"2025-11-17T21:36:37.678850+00:00\",\"modified_at\":\"2025-11-17T21:36:37.678850+00:00\"}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:37 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/7f34e18e-c3fd-11f0-8c23-da7ad0900002" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"logs_restriction_queries\",\"id\":\"7f34e18e-c3fd-11f0-8c23-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:sandbox\",\"created_at\":\"2025-11-17T21:36:37.678850+00:00\",\"modified_at\":\"2025-11-17T21:36:37.678850+00:00\"},\"relationships\":{\"roles\":{\"data\":[]}}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:37 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/7f34e18e-c3fd-11f0-8c23-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:37 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..5a6a09eb2 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:38.488Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.json new file mode 100644 index 000000000..24559093a --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Bad-Request-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/user/malformed_id" + }, + "response": { + "body": { + "string": "{\"errors\":[\"uuid is not proper type\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:38 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.frozen new file mode 100644 index 000000000..d4fbbc603 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:38.856Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.json new file mode 100644 index 000000000..8131b123a --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-all-restriction-queries-for-a-given-user-returns-Not-found-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/user/00000000-0000-0000-0000-000000000000" + }, + "response": { + "body": { + "string": "{\"errors\":[\"user with uuid 00000000-0000-0000-0000-000000000000 doesn't exist\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:38 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..9cfa72116 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:39.195Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.json new file mode 100644 index 000000000..1b344c857 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Bad-Request-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/role/malformed_id" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Missing Role malformed_id\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:39 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.frozen new file mode 100644 index 000000000..38c656a04 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:39.565Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.json new file mode 100644 index 000000000..acc686e53 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-Not-found-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/role/00000000-0000-0000-0000-000000000000" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Missing Role 00000000-0000-0000-0000-000000000000\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:39 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.frozen new file mode 100644 index 000000000..09d56f7a1 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:39.917Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.json new file mode 100644 index 000000000..b0602625a --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Get-restriction-query-for-a-given-role-returns-OK-response.json @@ -0,0 +1,91 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"name\":\"Test-Get_restriction_query_for_a_given_role_returns_OK_response-1763415399\"},\"type\":\"roles\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/roles" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"80b7ecc2-c3fd-11f0-8d5a-da7ad0900002\",\"type\":\"roles\",\"attributes\":{\"created_at\":\"2025-11-17T21:36:40.216326Z\",\"modified_at\":\"2025-11-17T21:36:40.216269Z\",\"name\":\"Test-Get_restriction_query_for_a_given_role_returns_OK_response-1763415399\",\"team_count\":0,\"user_count\":0},\"relationships\":{\"permissions\":{\"data\":[{\"id\":\"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2\",\"type\":\"permissions\"},{\"id\":\"4441648c-d8b1-11e9-a77a-1b899a04b304\",\"type\":\"permissions\"},{\"id\":\"417ba636-2dce-11eb-84c0-6bce5b0d9de0\",\"type\":\"permissions\"},{\"id\":\"12efc20e-d36c-11eb-a9b8-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"7605ef24-f376-11eb-b90b-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"b6bf9ac6-9a59-11ec-8480-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"f8e941cf-e746-11ec-b22d-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"6c5ad874-7aff-11ed-a5cd-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"a8b4d6e8-4ea4-11ee-b482-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"50c270de-69ee-11ee-9151-da7ad0900002\",\"type\":\"permissions\"}]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:39 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/role/80b7ecc2-c3fd-11f0-8d5a-da7ad0900002" + }, + "response": { + "body": { + "string": "{\"data\":[]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:39 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/roles/80b7ecc2-c3fd-11f0-8d5a-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:39 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..f911f1546 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:40.959Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.json new file mode 100644 index 000000000..be95e94a3 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Bad-Request-response.json @@ -0,0 +1,39 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"id\":\"3653d3c6-0c75-11ea-ad28-fb5701eabc7d\",\"type\":\"roles\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "*/*" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/malformed_id/roles" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Role with id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d not found\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:40 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.frozen new file mode 100644 index 000000000..ad3ca1112 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:41.677Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.json new file mode 100644 index 000000000..be1b33e8a --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-Not-found-response.json @@ -0,0 +1,39 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"id\":\"3653d3c6-0c75-11ea-ad28-fb5701eabc7d\",\"type\":\"roles\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "*/*" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/00000000-0000-0000-0000-000000000000/roles" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Role with id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d not found\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:41 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.frozen new file mode 100644 index 000000000..675f75350 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:42.024Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.json new file mode 100644 index 000000000..f5676450a --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/Grant-role-to-a-restriction-query-returns-OK-response.json @@ -0,0 +1,159 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"restriction_query\":\"env:sandbox\"},\"type\":\"logs_restriction_queries\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"logs_restriction_queries\",\"id\":\"81f63382-c3fd-11f0-be7b-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:sandbox\",\"created_at\":\"2025-11-17T21:36:42.301659+00:00\",\"modified_at\":\"2025-11-17T21:36:42.301659+00:00\"}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:42 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"name\":\"Test-Grant_role_to_a_restriction_query_returns_OK_response-1763415402\"},\"type\":\"roles\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/roles" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"822b736c-c3fd-11f0-8df1-da7ad0900002\",\"type\":\"roles\",\"attributes\":{\"created_at\":\"2025-11-17T21:36:42.650961Z\",\"modified_at\":\"2025-11-17T21:36:42.650523Z\",\"name\":\"Test-Grant_role_to_a_restriction_query_returns_OK_response-1763415402\",\"team_count\":0,\"user_count\":0},\"relationships\":{\"permissions\":{\"data\":[{\"id\":\"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2\",\"type\":\"permissions\"},{\"id\":\"4441648c-d8b1-11e9-a77a-1b899a04b304\",\"type\":\"permissions\"},{\"id\":\"417ba636-2dce-11eb-84c0-6bce5b0d9de0\",\"type\":\"permissions\"},{\"id\":\"12efc20e-d36c-11eb-a9b8-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"7605ef24-f376-11eb-b90b-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"b6bf9ac6-9a59-11ec-8480-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"f8e941cf-e746-11ec-b22d-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"6c5ad874-7aff-11ed-a5cd-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"a8b4d6e8-4ea4-11ee-b482-da7ad0900002\",\"type\":\"permissions\"},{\"id\":\"50c270de-69ee-11ee-9151-da7ad0900002\",\"type\":\"permissions\"}]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:42 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"id\":\"822b736c-c3fd-11f0-8df1-da7ad0900002\",\"type\":\"roles\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "*/*" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/81f63382-c3fd-11f0-be7b-da7ad0900002/roles" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:42 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/roles/822b736c-c3fd-11f0-8df1-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:42 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/81f63382-c3fd-11f0-be7b-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:42 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.frozen new file mode 100644 index 000000000..a989e4c6d --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:43.867Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.json new file mode 100644 index 000000000..97d7345c3 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-restriction-queries-returns-OK-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"data\":[{\"type\":\"logs_restriction_queries\",\"id\":\"6358d012-be7e-11f0-8999-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:production\",\"created_at\":\"2025-11-10T21:44:09.039708+00:00\",\"modified_at\":\"2025-11-10T21:44:09.164487+00:00\"}}]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:43 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.frozen new file mode 100644 index 000000000..bd62a84d0 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:44.211Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.json new file mode 100644 index 000000000..f6e8c5ac2 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Bad-Request-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/malformed_id/roles" + }, + "response": { + "body": { + "string": "{\"errors\":[\"uuid is not proper type\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 400, + "message": "Bad Request" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:44 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.frozen new file mode 100644 index 000000000..4fc3d50c1 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:44.606Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.json new file mode 100644 index 000000000..0b64ac8f4 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-Not-found-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/00000000-0000-0000-0000-000000000000/roles" + }, + "response": { + "body": { + "string": "{\"errors\":[\"Restriction query not found\"]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:44 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.frozen new file mode 100644 index 000000000..b9da306e3 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-11-17T21:36:44.965Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.json b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.json new file mode 100644 index 000000000..77160cc36 --- /dev/null +++ b/tests/scenarios/cassettes/v2/logs_restriction_queries/List-roles-for-a-restriction-query-returns-OK-response.json @@ -0,0 +1,95 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"restriction_query\":\"env:sandbox\"},\"type\":\"logs_restriction_queries\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"logs_restriction_queries\",\"id\":\"83bb0986-c3fd-11f0-8604-da7ad0900002\",\"attributes\":{\"restriction_query\":\"env:sandbox\",\"created_at\":\"2025-11-17T21:36:45.269298+00:00\",\"modified_at\":\"2025-11-17T21:36:45.269298+00:00\"}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:44 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/83bb0986-c3fd-11f0-8604-da7ad0900002/roles" + }, + "response": { + "body": { + "string": "{\"data\":[]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:44 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/logs/config/restriction_queries/83bb0986-c3fd-11f0-8604-da7ad0900002" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Mon, 17 Nov 2025 21:36:44 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v2/given.json b/tests/scenarios/features/v2/given.json index 8afb9b89b..b1cb0acd3 100644 --- a/tests/scenarios/features/v2/given.json +++ b/tests/scenarios/features/v2/given.json @@ -651,6 +651,18 @@ "tag": "Logs Metrics", "operationId": "CreateLogsMetric" }, + { + "parameters": [ + { + "name": "body", + "value": "{\"data\": {\"attributes\": {\"restriction_query\": \"env:sandbox\"}, \"type\": \"logs_restriction_queries\"}}" + } + ], + "step": "there is a valid \"restriction_query\" in the system", + "key": "restriction_query", + "tag": "Logs Restriction Queries", + "operationId": "CreateRestrictionQuery" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v2/logs_restriction_queries.feature b/tests/scenarios/features/v2/logs_restriction_queries.feature new file mode 100644 index 000000000..44d65b92f --- /dev/null +++ b/tests/scenarios/features/v2/logs_restriction_queries.feature @@ -0,0 +1,287 @@ +@endpoint(logs-restriction-queries) @endpoint(logs-restriction-queries-v2) +Feature: Logs Restriction Queries + **Note: This endpoint is in public beta. If you have any feedback, contact + [Datadog support](https://docs.datadoghq.com/help/).** A Restriction + Query is a logs query that restricts which logs the `logs_read_data` + permission grants read access to. For users whose roles have Restriction + Queries, any log query they make only returns those log events that also + match one of their Restriction Queries. This is true whether the user + queries log events from any log-related feature, including the log + explorer, Live Tail, re-hydration, or a dashboard widget. Restriction + Queries currently only support use of the following components of log + events: - Reserved attributes - The log message - Tags To restrict read + access on log data, add a team tag to log events to indicate which teams + own them, and then scope Restriction Queries to the relevant values of the + team tag. Tags can be applied to log events in many ways, and a log event + can have multiple tags with the same key (like team) and different values. + This means the same log event can be visible to roles whose restriction + queries are scoped to different team values. See [How to Set Up RBAC for + Logs](https://docs.datadoghq.com/logs/guide/logs-rbac/?tab=api#restrict- + access-to-logs) for details on how to add restriction queries. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "LogsRestrictionQueries" API + + @skip-go @skip-java @skip-python @skip-ruby @skip-rust @skip-terraform-config @skip-typescript @skip-validation @team:DataDog/logs-app + Scenario: Create a restriction query returns "Bad Request" response + Given operation "CreateRestrictionQuery" enabled + And new "CreateRestrictionQuery" request + And body with value {"test": "bad_request"} + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/logs-app + Scenario: Create a restriction query returns "OK" response + Given operation "CreateRestrictionQuery" enabled + And new "CreateRestrictionQuery" request + And body with value {"data": {"attributes": {"restriction_query": "env:sandbox"}, "type": "logs_restriction_queries"}} + When the request is sent + Then the response status is 200 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Delete a restriction query returns "Bad Request" response + Given operation "DeleteRestrictionQuery" enabled + And new "DeleteRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "malformed_id" + When the request is sent + Then the response status is 400 Bad Request + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Delete a restriction query returns "Not found" response + Given operation "DeleteRestrictionQuery" enabled + And new "DeleteRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + When the request is sent + Then the response status is 404 Not found + + @team:DataDog/logs-app + Scenario: Delete a restriction query returns "OK" response + Given operation "DeleteRestrictionQuery" enabled + And there is a valid "restriction_query" in the system + And new "DeleteRestrictionQuery" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + When the request is sent + Then the response status is 204 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Get a restriction query returns "Bad Request" response + Given operation "GetRestrictionQuery" enabled + And new "GetRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "malformed_id" + When the request is sent + Then the response status is 400 Bad Request + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Get a restriction query returns "Not found" response + Given operation "GetRestrictionQuery" enabled + And new "GetRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + When the request is sent + Then the response status is 404 Not found + + @team:DataDog/logs-app + Scenario: Get a restriction query returns "OK" response + Given operation "GetRestrictionQuery" enabled + And there is a valid "restriction_query" in the system + And new "GetRestrictionQuery" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + When the request is sent + Then the response status is 200 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Get all restriction queries for a given user returns "Bad Request" response + Given operation "ListUserRestrictionQueries" enabled + And new "ListUserRestrictionQueries" request + And request contains "user_id" parameter with value "malformed_id" + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/logs-app + Scenario: Get all restriction queries for a given user returns "Not found" response + Given operation "ListUserRestrictionQueries" enabled + And new "ListUserRestrictionQueries" request + And request contains "user_id" parameter with value "00000000-0000-0000-0000-000000000000" + When the request is sent + Then the response status is 400 Bad Request + + @skip @team:DataDog/logs-app + Scenario: Get all restriction queries for a given user returns "OK" response + Given operation "ListUserRestrictionQueries" enabled + And there is a valid "user" in the system + And new "ListUserRestrictionQueries" request + And request contains "user_id" parameter from "user.data.id" + When the request is sent + Then the response status is 200 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Get restriction query for a given role returns "Bad Request" response + Given operation "GetRoleRestrictionQuery" enabled + And new "GetRoleRestrictionQuery" request + And request contains "role_id" parameter with value "malformed_id" + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/logs-app + Scenario: Get restriction query for a given role returns "Not found" response + Given operation "GetRoleRestrictionQuery" enabled + And new "GetRoleRestrictionQuery" request + And request contains "role_id" parameter with value "00000000-0000-0000-0000-000000000000" + When the request is sent + Then the response status is 400 Bad Request + + @team:DataDog/logs-app + Scenario: Get restriction query for a given role returns "OK" response + Given operation "GetRoleRestrictionQuery" enabled + And there is a valid "role" in the system + And new "GetRoleRestrictionQuery" request + And request contains "role_id" parameter from "role.data.id" + When the request is sent + Then the response status is 200 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Grant role to a restriction query returns "Bad Request" response + Given operation "AddRoleToRestrictionQuery" enabled + And new "AddRoleToRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "malformed_id" + And body with value {"data": {"id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d", "type": "roles"}} + When the request is sent + Then the response status is 404 Not found + + @skip-terraform-config @team:DataDog/logs-app + Scenario: Grant role to a restriction query returns "Not found" response + Given operation "AddRoleToRestrictionQuery" enabled + And new "AddRoleToRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + And body with value {"data": {"id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d", "type": "roles"}} + When the request is sent + Then the response status is 404 Not found + + @team:DataDog/logs-app + Scenario: Grant role to a restriction query returns "OK" response + Given operation "AddRoleToRestrictionQuery" enabled + And there is a valid "restriction_query" in the system + And there is a valid "role" in the system + And new "AddRoleToRestrictionQuery" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + And body with value {"data": {"id": "{{ role.data.id }}", "type": "roles"}} + When the request is sent + Then the response status is 204 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: List restriction queries returns "OK" response + Given operation "ListRestrictionQueries" enabled + And new "ListRestrictionQueries" request + When the request is sent + Then the response status is 200 OK + + @skip-terraform-config @team:DataDog/logs-app + Scenario: List roles for a restriction query returns "Bad Request" response + Given operation "ListRestrictionQueryRoles" enabled + And new "ListRestrictionQueryRoles" request + And request contains "restriction_query_id" parameter with value "malformed_id" + When the request is sent + Then the response status is 400 Bad Request + + @skip-terraform-config @team:DataDog/logs-app + Scenario: List roles for a restriction query returns "Not found" response + Given operation "ListRestrictionQueryRoles" enabled + And new "ListRestrictionQueryRoles" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + When the request is sent + Then the response status is 404 Not found + + @team:DataDog/logs-app + Scenario: List roles for a restriction query returns "OK" response + Given operation "ListRestrictionQueryRoles" enabled + And there is a valid "restriction_query" in the system + And new "ListRestrictionQueryRoles" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + When the request is sent + Then the response status is 200 OK + + @skip @team:DataDog/logs-app + Scenario: Replace a restriction query returns "Bad Request" response + Given operation "ReplaceRestrictionQuery" enabled + And new "ReplaceRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "malformed_id" + And body with value {"data": {"attributes": {"restriction_query": "env:sandbox"}, "type": "logs_restriction_queries"}} + When the request is sent + Then the response status is 400 Bad Request + + @skip @team:DataDog/logs-app + Scenario: Replace a restriction query returns "Not found" response + Given operation "ReplaceRestrictionQuery" enabled + And new "ReplaceRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + And body with value {"data": {"attributes": {"restriction_query": "env:sandbox"}, "type": "logs_restriction_queries"}} + When the request is sent + Then the response status is 404 Not found + + @skip @team:DataDog/logs-app + Scenario: Replace a restriction query returns "OK" response + Given operation "ReplaceRestrictionQuery" enabled + And there is a valid "restriction_query" in the system + And new "ReplaceRestrictionQuery" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + And body with value {"data": {"attributes": {"restriction_query": "env:staging"}, "type": "logs_restriction_queries"}} + When the request is sent + Then the response status is 200 OK + + @skip @skip-terraform-config @team:DataDog/logs-app + Scenario: Revoke role from a restriction query returns "Bad Request" response + Given operation "RemoveRoleFromRestrictionQuery" enabled + And new "RemoveRoleFromRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "malformed_id" + And body with value {"data": {"id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d", "type": "roles"}} + When the request is sent + Then the response status is 400 Bad Request + + @skip @skip-terraform-config @team:DataDog/logs-app + Scenario: Revoke role from a restriction query returns "Not found" response + Given operation "RemoveRoleFromRestrictionQuery" enabled + And new "RemoveRoleFromRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + And body with value {"data": {"id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d", "type": "roles"}} + When the request is sent + Then the response status is 404 Not found + + @skip @team:DataDog/logs-app + Scenario: Revoke role from a restriction query returns "OK" response + Given operation "RemoveRoleFromRestrictionQuery" enabled + And there is a valid "restriction_query" in the system + And there is a valid "role" in the system + And new "RemoveRoleFromRestrictionQuery" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + And body with value {"data": {"id": "{{ role.data.id }}", "type": "roles"}} + When the request is sent + Then the response status is 204 OK + + @skip @skip-terraform-config @team:DataDog/logs-app + Scenario: Update a restriction query returns "Bad Request" response + Given operation "UpdateRestrictionQuery" enabled + And new "UpdateRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "malformed_id" + And body with value {"data": {"attributes": {"restriction_query": "env:sandbox"}, "type": "logs_restriction_queries"}} + When the request is sent + Then the response status is 400 Bad Request + + @skip @skip-terraform-config @team:DataDog/logs-app + Scenario: Update a restriction query returns "Not found" response + Given operation "UpdateRestrictionQuery" enabled + And new "UpdateRestrictionQuery" request + And request contains "restriction_query_id" parameter with value "00000000-0000-0000-0000-000000000000" + And body with value {"data": {"attributes": {"restriction_query": "env:sandbox"}, "type": "logs_restriction_queries"}} + When the request is sent + Then the response status is 404 Not found + + @skip @team:DataDog/logs-app + Scenario: Update a restriction query returns "OK" response + Given operation "UpdateRestrictionQuery" enabled + And there is a valid "restriction_query" in the system + And new "UpdateRestrictionQuery" request + And request contains "restriction_query_id" parameter from "restriction_query.data.id" + And body with value {"data": {"attributes": {"restriction_query": "env:production"}, "type": "logs_restriction_queries"}} + 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 dba9a5e29..a327f0545 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2377,6 +2377,79 @@ "type": "idempotent" } }, + "ListRestrictionQueries": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "safe" + } + }, + "CreateRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "operationId": "DeleteRestrictionQuery", + "parameters": [ + { + "name": "restriction_query_id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, + "GetRoleRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "safe" + } + }, + "ListUserRestrictionQueries": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "safe" + } + }, + "DeleteRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "idempotent" + } + }, + "GetRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "safe" + } + }, + "UpdateRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "idempotent" + } + }, + "ReplaceRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "idempotent" + } + }, + "RemoveRoleFromRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "idempotent" + } + }, + "ListRestrictionQueryRoles": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "safe" + } + }, + "AddRoleToRestrictionQuery": { + "tag": "Logs Restriction Queries", + "undo": { + "type": "safe" + } + }, "ListLogsGet": { "tag": "Logs", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 09a3ab6f6..1a16b826a 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -109,6 +109,8 @@ pub struct ApiInstances { pub v2_api_logs_custom_destinations: Option, pub v2_api_logs_metrics: Option, + pub v2_api_logs_restriction_queries: + Option, pub v2_api_metrics: Option, pub v2_api_monitors: Option, pub v2_api_network_device_monitoring: @@ -764,6 +766,12 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { ), ); } + "LogsRestrictionQueries" => { + world.api_instances.v2_api_logs_restriction_queries = Some(datadogV2::api_logs_restriction_queries::LogsRestrictionQueriesAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone() + )); + } "NetworkDeviceMonitoring" => { world.api_instances.v2_api_network_device_monitoring = Some(datadogV2::api_network_device_monitoring::NetworkDeviceMonitoringAPI::with_client_and_config( world.config.clone(), @@ -3439,6 +3447,50 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { world .function_mappings .insert("v2.UpdateLogsMetric".into(), test_v2_update_logs_metric); + world.function_mappings.insert( + "v2.ListRestrictionQueries".into(), + test_v2_list_restriction_queries, + ); + world.function_mappings.insert( + "v2.CreateRestrictionQuery".into(), + test_v2_create_restriction_query, + ); + world.function_mappings.insert( + "v2.GetRoleRestrictionQuery".into(), + test_v2_get_role_restriction_query, + ); + world.function_mappings.insert( + "v2.ListUserRestrictionQueries".into(), + test_v2_list_user_restriction_queries, + ); + world.function_mappings.insert( + "v2.DeleteRestrictionQuery".into(), + test_v2_delete_restriction_query, + ); + world.function_mappings.insert( + "v2.GetRestrictionQuery".into(), + test_v2_get_restriction_query, + ); + world.function_mappings.insert( + "v2.UpdateRestrictionQuery".into(), + test_v2_update_restriction_query, + ); + world.function_mappings.insert( + "v2.ReplaceRestrictionQuery".into(), + test_v2_replace_restriction_query, + ); + world.function_mappings.insert( + "v2.RemoveRoleFromRestrictionQuery".into(), + test_v2_remove_role_from_restriction_query, + ); + world.function_mappings.insert( + "v2.ListRestrictionQueryRoles".into(), + test_v2_list_restriction_query_roles, + ); + world.function_mappings.insert( + "v2.AddRoleToRestrictionQuery".into(), + test_v2_add_role_to_restriction_query, + ); world.function_mappings.insert( "v2.ListTagConfigurations".into(), test_v2_list_tag_configurations, @@ -25782,6 +25834,350 @@ fn test_v2_update_logs_metric(world: &mut DatadogWorld, _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let page_size = _parameters + .get("page[size]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let page_number = _parameters + .get("page[number]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = + datadogV2::api_logs_restriction_queries::ListRestrictionQueriesOptionalParams::default(); + params.page_size = page_size; + params.page_number = page_number; + let response = match block_on(api.list_restriction_queries_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_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .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_restriction_query_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_get_role_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let role_id = serde_json::from_value(_parameters.get("role_id").unwrap().clone()).unwrap(); + let response = match block_on(api.get_role_restriction_query_with_http_info(role_id)) { + 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_user_restriction_queries( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let user_id = serde_json::from_value(_parameters.get("user_id").unwrap().clone()).unwrap(); + let response = match block_on(api.list_user_restriction_queries_with_http_info(user_id)) { + 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_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let response = match block_on(api.delete_restriction_query_with_http_info(restriction_query_id)) + { + 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_restriction_query(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let response = match block_on(api.get_restriction_query_with_http_info(restriction_query_id)) { + 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_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = + match block_on(api.update_restriction_query_with_http_info(restriction_query_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_replace_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = + match block_on(api.replace_restriction_query_with_http_info(restriction_query_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_remove_role_from_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on( + api.remove_role_from_restriction_query_with_http_info(restriction_query_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_list_restriction_query_roles( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let page_size = _parameters + .get("page[size]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let page_number = _parameters + .get("page[number]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = + datadogV2::api_logs_restriction_queries::ListRestrictionQueryRolesOptionalParams::default(); + params.page_size = page_size; + params.page_number = page_number; + let response = match block_on( + api.list_restriction_query_roles_with_http_info(restriction_query_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_add_role_to_restriction_query( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_logs_restriction_queries + .as_ref() + .expect("api instance not found"); + let restriction_query_id = + serde_json::from_value(_parameters.get("restriction_query_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on( + api.add_role_to_restriction_query_with_http_info(restriction_query_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_list_tag_configurations(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances