From 1661188788458a12de798358fd05b73eda275764 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Thu, 18 Dec 2025 19:44:18 +0000 Subject: [PATCH] Regenerate client from commit 91df58e of spec repo --- .generator/schemas/v2/openapi.yaml | 495 ++++++++++ .../v2_on-call_CreateUserNotificationRule.rs | 51 ++ .../v2_on-call_DeleteUserNotificationRule.rs | 26 + .../v2_on-call_GetUserNotificationRule.rs | 28 + .../v2_on-call_ListUserNotificationRules.rs | 23 + .../v2_on-call_UpdateUserNotificationRule.rs | 62 ++ src/datadogV2/api/api_on_call.rs | 846 +++++++++++++++++- src/datadogV2/model/mod.rs | 38 + ...reate_on_call_notification_rule_request.rs | 96 ++ ..._on_call_notification_rule_request_data.rs | 147 +++ ...ist_on_call_notification_rules_response.rs | 126 +++ .../model/model_on_call_notification_rule.rs | 115 +++ ...el_on_call_notification_rule_attributes.rs | 166 ++++ ...odel_on_call_notification_rule_category.rs | 51 ++ ..._notification_rule_channel_relationship.rs | 96 ++ ...fication_rule_channel_relationship_data.rs | 130 +++ ...call_notification_rule_channel_settings.rs | 38 + .../model_on_call_notification_rule_data.rs | 164 ++++ ...on_call_notification_rule_relationships.rs | 110 +++ ...ll_notification_rule_request_attributes.rs | 166 ++++ .../model_on_call_notification_rule_type.rs | 48 + ...del_on_call_notification_rules_included.rs | 34 + ..._on_call_phone_notification_rule_method.rs | 51 ++ ...n_call_phone_notification_rule_settings.rs | 123 +++ ...pdate_on_call_notification_rule_request.rs | 96 ++ ...ll_notification_rule_request_attributes.rs | 166 ++++ ..._on_call_notification_rule_request_data.rs | 164 ++++ ...for-a-user-returns-Created-response.frozen | 1 + ...e-for-a-user-returns-Created-response.json | 131 +++ ...-a-user-returns-No-Content-response.frozen | 1 + ...or-a-user-returns-No-Content-response.json | 155 ++++ ...rule-for-a-user-returns-OK-response.frozen | 1 + ...n-rule-for-a-user-returns-OK-response.json | 159 ++++ ...ules-for-a-user-returns-OK-response.frozen | 1 + ...-rules-for-a-user-returns-OK-response.json | 159 ++++ ...rule-for-a-user-returns-OK-response.frozen | 1 + ...n-rule-for-a-user-returns-OK-response.json | 165 ++++ tests/scenarios/features/v2/given.json | 16 + tests/scenarios/features/v2/on-call.feature | 143 +++ tests/scenarios/features/v2/undo.json | 30 + tests/scenarios/function_mappings.rs | 185 ++++ 41 files changed, 4762 insertions(+), 42 deletions(-) create mode 100644 examples/v2_on-call_CreateUserNotificationRule.rs create mode 100644 examples/v2_on-call_DeleteUserNotificationRule.rs create mode 100644 examples/v2_on-call_GetUserNotificationRule.rs create mode 100644 examples/v2_on-call_ListUserNotificationRules.rs create mode 100644 examples/v2_on-call_UpdateUserNotificationRule.rs create mode 100644 src/datadogV2/model/model_create_on_call_notification_rule_request.rs create mode 100644 src/datadogV2/model/model_create_on_call_notification_rule_request_data.rs create mode 100644 src/datadogV2/model/model_list_on_call_notification_rules_response.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_attributes.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_category.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_channel_relationship.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_channel_relationship_data.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_channel_settings.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_data.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_relationships.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_request_attributes.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rule_type.rs create mode 100644 src/datadogV2/model/model_on_call_notification_rules_included.rs create mode 100644 src/datadogV2/model/model_on_call_phone_notification_rule_method.rs create mode 100644 src/datadogV2/model/model_on_call_phone_notification_rule_settings.rs create mode 100644 src/datadogV2/model/model_update_on_call_notification_rule_request.rs create mode 100644 src/datadogV2/model/model_update_on_call_notification_rule_request_attributes.rs create mode 100644 src/datadogV2/model/model_update_on_call_notification_rule_request_data.rs create mode 100644 tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.frozen create mode 100644 tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.json create mode 100644 tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.frozen create mode 100644 tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.json create mode 100644 tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.json create mode 100644 tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen create mode 100644 tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.json diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 196165112..f2a1dc5e0 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -13374,6 +13374,40 @@ components: - name - targets type: object + CreateOnCallNotificationRuleRequest: + description: A top-level wrapper for creating a notification rule for a user + example: + data: + attributes: + category: high_urgency + channel_settings: + method: sms + type: phone + delay_minutes: 1 + relationships: + channel: + data: + id: 1562fab3-a8c2-49e2-8f3a-28dcda2405e2 + type: notification_channels + type: notification_rules + properties: + data: + $ref: '#/components/schemas/CreateOnCallNotificationRuleRequestData' + required: + - data + type: object + CreateOnCallNotificationRuleRequestData: + description: Data for creating an on-call notification rule + properties: + attributes: + $ref: '#/components/schemas/OnCallNotificationRuleRequestAttributes' + relationships: + $ref: '#/components/schemas/OnCallNotificationRuleRelationships' + type: + $ref: '#/components/schemas/OnCallNotificationRuleType' + required: + - type + type: object CreateOpenAPIResponse: description: Response for `CreateOpenAPI` operation. properties: @@ -30599,6 +30633,18 @@ components: $ref: '#/components/schemas/NotificationChannelData' type: array type: object + ListOnCallNotificationRulesResponse: + description: Response type for listing notification rules for a user + properties: + data: + items: + $ref: '#/components/schemas/OnCallNotificationRuleData' + type: array + included: + items: + $ref: '#/components/schemas/OnCallNotificationRulesIncluded' + type: array + type: object ListPipelinesResponse: description: Represents the response payload containing a list of pipelines and associated metadata. @@ -39053,6 +39099,130 @@ components: required: - type type: object + OnCallNotificationRule: + description: A top-level wrapper for a notification rule + example: + data: + attributes: + category: high_urgency + channel_settings: + method: sms + type: phone + delay_minutes: 1 + id: 27590dae-47be-4a7d-9abf-8f4e45124020 + relationships: + channel: + data: + id: 1562fab3-a8c2-49e2-8f3a-28dcda2405e2 + type: notification_channels + type: notification_rules + properties: + data: + $ref: '#/components/schemas/OnCallNotificationRuleData' + included: + items: + $ref: '#/components/schemas/OnCallNotificationRulesIncluded' + type: array + required: + - data + type: object + OnCallNotificationRuleAttributes: + description: Attributes for an on-call notification rule. + properties: + category: + $ref: '#/components/schemas/OnCallNotificationRuleCategory' + channel_settings: + $ref: '#/components/schemas/OnCallNotificationRuleChannelSettings' + description: Configuration for the associated channel, if necessary + nullable: true + delay_minutes: + description: The number of minutes that will elapse before this rule is + evaluated. 0 indicates immediate evaluation + format: int64 + type: integer + type: object + OnCallNotificationRuleCategory: + default: high_urgency + description: Specifies the category a notification rule will apply to + enum: + - high_urgency + - low_urgency + type: string + x-enum-varnames: + - HIGH_URGENCY + - LOW_URGENCY + OnCallNotificationRuleChannelRelationship: + description: Relationship object for creating a notification rule + properties: + data: + $ref: '#/components/schemas/OnCallNotificationRuleChannelRelationshipData' + required: + - data + type: object + OnCallNotificationRuleChannelRelationshipData: + description: Channel relationship data for creating a notification rule + properties: + id: + description: ID of the notification channel + type: string + type: + $ref: '#/components/schemas/NotificationChannelType' + type: object + OnCallNotificationRuleChannelSettings: + description: Defines the configuration for a channel associated with a notification + rule + oneOf: + - $ref: '#/components/schemas/OnCallPhoneNotificationRuleSettings' + OnCallNotificationRuleData: + description: Data for an on-call notification rule + properties: + attributes: + $ref: '#/components/schemas/OnCallNotificationRuleAttributes' + id: + description: Unique identifier for the rule + type: string + relationships: + $ref: '#/components/schemas/OnCallNotificationRuleRelationships' + type: + $ref: '#/components/schemas/OnCallNotificationRuleType' + required: + - type + type: object + OnCallNotificationRuleRelationships: + description: Relationship object for creating a notification rule + properties: + channel: + $ref: '#/components/schemas/OnCallNotificationRuleChannelRelationship' + type: object + OnCallNotificationRuleRequestAttributes: + description: Attributes for creating or modifying an on-call notification rule. + properties: + category: + $ref: '#/components/schemas/OnCallNotificationRuleCategory' + channel_settings: + $ref: '#/components/schemas/OnCallNotificationRuleChannelSettings' + description: Configuration for the associated channel, if necessary + nullable: true + delay_minutes: + description: The number of minutes that will elapse before this rule is + evaluated. 0 indicates immediate evaluation + format: int64 + type: integer + type: object + OnCallNotificationRuleType: + default: notification_rules + description: Indicates that the resource is of type 'notification_rules'. + enum: + - notification_rules + example: notification_rules + type: string + x-enum-varnames: + - NOTIFICATION_RULES + OnCallNotificationRulesIncluded: + description: Represents additional included resources for a on-call notification + rules + oneOf: + - $ref: '#/components/schemas/NotificationChannelData' OnCallPageTargetType: description: The kind of target, `team_id` | `team_handle` | `user_id`. enum: @@ -39065,6 +39235,29 @@ components: - TEAM_ID - TEAM_HANDLE - USER_ID + OnCallPhoneNotificationRuleMethod: + description: Specifies the method in which a phone is used in a notification + rule + enum: + - sms + - voice + example: sms + type: string + x-enum-varnames: + - SMS + - VOICE + OnCallPhoneNotificationRuleSettings: + description: Configuration for using a phone notification channel in a notification + rule + properties: + method: + $ref: '#/components/schemas/OnCallPhoneNotificationRuleMethod' + type: + $ref: '#/components/schemas/NotificationChannelPhoneConfigType' + required: + - type + - method + type: object OnDemandConcurrencyCap: description: On-demand concurrency cap. properties: @@ -56304,6 +56497,59 @@ components: - name - options type: object + UpdateOnCallNotificationRuleRequest: + description: A top-level wrapper for updating a notification rule for a user + example: + data: + attributes: + category: high_urgency + channel_settings: + method: sms + type: phone + delay_minutes: 1 + id: 2462ace1-49e2-aab1-xc4f-29cc4ae1105n7 + relationships: + channel: + data: + id: 1562fab3-a8c2-49e2-8f3a-28dcda2405e2 + type: notification_channels + type: notification_rules + properties: + data: + $ref: '#/components/schemas/UpdateOnCallNotificationRuleRequestData' + required: + - data + type: object + UpdateOnCallNotificationRuleRequestAttributes: + description: Attributes for creating or modifying an on-call notification rule. + properties: + category: + $ref: '#/components/schemas/OnCallNotificationRuleCategory' + channel_settings: + $ref: '#/components/schemas/OnCallNotificationRuleChannelSettings' + description: Configuration for the associated channel, if necessary + nullable: true + delay_minutes: + description: The number of minutes that will elapse before this rule is + evaluated. 0 indicates immediate evaluation + format: int64 + type: integer + type: object + UpdateOnCallNotificationRuleRequestData: + description: Data for updating an on-call notification rule + properties: + attributes: + $ref: '#/components/schemas/UpdateOnCallNotificationRuleRequestAttributes' + id: + description: Unique identifier for the rule + type: string + relationships: + $ref: '#/components/schemas/OnCallNotificationRuleRelationships' + type: + $ref: '#/components/schemas/OnCallNotificationRuleType' + required: + - type + type: object UpdateOpenAPIResponse: description: Response for `UpdateOpenAPI`. properties: @@ -76343,6 +76589,255 @@ paths: operator: AND permissions: - on_call_read + /api/v2/on-call/users/{user_id}/notification-rules: + get: + description: List the notification rules for a user. The authenticated user + must be the target user or have the `on_call_admin` permission + operationId: ListUserNotificationRules + parameters: + - description: 'Comma-separated list of included relationships to be returned. + Allowed values: `channel`.' + in: query + name: include + schema: + type: string + - description: The user ID + in: path + name: user_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ListOnCallNotificationRulesResponse' + description: OK + '400': + $ref: '#/components/responses/BadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: List On-Call notification rules for a user + tags: + - On-Call + x-permission: + operator: AND + permissions: + - on_call_read + post: + description: Create a new notification rule for a user. The authenticated user + must be the target user or have the `on_call_admin` permission + operationId: CreateUserNotificationRule + parameters: + - description: The user ID + in: path + name: user_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateOnCallNotificationRuleRequest' + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/OnCallNotificationRule' + description: Created + '400': + $ref: '#/components/responses/BadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Create an On-Call notification rule for a user + tags: + - On-Call + x-permission: + operator: AND + permissions: + - on_call_respond + /api/v2/on-call/users/{user_id}/notification-rules/{rule_id}: + delete: + description: Delete a notification rule for a user. The authenticated user must + be the target user or have the `on_call_admin` permission + operationId: DeleteUserNotificationRule + parameters: + - description: The user ID + in: path + name: user_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + - description: The rule ID + in: path + name: rule_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + responses: + '204': + description: No Content + '400': + $ref: '#/components/responses/BadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Delete an On-Call notification rule for a user + tags: + - On-Call + x-permission: + operator: OR + permissions: + - on_call_respond + get: + description: Get a notification rule for a user. The authenticated user must + be the target user or have the `on_call_admin` permission + operationId: GetUserNotificationRule + parameters: + - description: The user ID + in: path + name: user_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + - description: The rule ID + in: path + name: rule_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + - description: 'Comma-separated list of included relationships to be returned. + Allowed values: `channel`.' + in: query + name: include + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/OnCallNotificationRule' + description: OK + '400': + $ref: '#/components/responses/BadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Get an On-Call notification rule for a user + tags: + - On-Call + x-permission: + operator: OR + permissions: + - on_call_read + put: + description: Update a notification rule for a user. The authenticated user must + be the target user or have the `on_call_admin` permission + operationId: UpdateUserNotificationRule + parameters: + - description: The user ID + in: path + name: user_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + - description: The rule ID + in: path + name: rule_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string + - description: 'Comma-separated list of included relationships to be returned. + Allowed values: `channel`.' + in: query + name: include + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/UpdateOnCallNotificationRuleRequest' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/OnCallNotificationRule' + description: OK + '400': + $ref: '#/components/responses/BadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Update an On-Call notification rule for a user + tags: + - On-Call + x-permission: + operator: OR + permissions: + - on_call_read /api/v2/org_configs: get: description: Returns all Org Configs (name, description, and value). diff --git a/examples/v2_on-call_CreateUserNotificationRule.rs b/examples/v2_on-call_CreateUserNotificationRule.rs new file mode 100644 index 000000000..3e541fb95 --- /dev/null +++ b/examples/v2_on-call_CreateUserNotificationRule.rs @@ -0,0 +1,51 @@ +// Create an On-Call notification rule for a user returns "Created" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_on_call::OnCallAPI; +use datadog_api_client::datadogV2::model::CreateOnCallNotificationRuleRequest; +use datadog_api_client::datadogV2::model::CreateOnCallNotificationRuleRequestData; +use datadog_api_client::datadogV2::model::NotificationChannelType; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleCategory; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleChannelRelationship; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleChannelRelationshipData; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleRelationships; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleRequestAttributes; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleType; + +#[tokio::main] +async fn main() { + // there is a valid "user" in the system + let user_data_id = std::env::var("USER_DATA_ID").unwrap(); + + // there is a valid "oncall_email_notification_channel" in the system + let oncall_email_notification_channel_data_id = + std::env::var("ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID").unwrap(); + let body = CreateOnCallNotificationRuleRequest::new( + CreateOnCallNotificationRuleRequestData::new( + OnCallNotificationRuleType::NOTIFICATION_RULES, + ) + .attributes( + OnCallNotificationRuleRequestAttributes::new() + .category(OnCallNotificationRuleCategory::HIGH_URGENCY) + .delay_minutes(0), + ) + .relationships( + OnCallNotificationRuleRelationships::new().channel( + OnCallNotificationRuleChannelRelationship::new( + OnCallNotificationRuleChannelRelationshipData::new() + .id(oncall_email_notification_channel_data_id.clone()) + .type_(NotificationChannelType::NOTIFICATION_CHANNELS), + ), + ), + ), + ); + let configuration = datadog::Configuration::new(); + let api = OnCallAPI::with_config(configuration); + let resp = api + .create_user_notification_rule(user_data_id.clone(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_on-call_DeleteUserNotificationRule.rs b/examples/v2_on-call_DeleteUserNotificationRule.rs new file mode 100644 index 000000000..c8471406e --- /dev/null +++ b/examples/v2_on-call_DeleteUserNotificationRule.rs @@ -0,0 +1,26 @@ +// Delete an On-Call notification rule for a user returns "No Content" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_on_call::OnCallAPI; + +#[tokio::main] +async fn main() { + // there is a valid "user" in the system + let user_data_id = std::env::var("USER_DATA_ID").unwrap(); + + // there is a valid "oncall_email_notification_rule" in the system + let oncall_email_notification_rule_data_id = + std::env::var("ONCALL_EMAIL_NOTIFICATION_RULE_DATA_ID").unwrap(); + let configuration = datadog::Configuration::new(); + let api = OnCallAPI::with_config(configuration); + let resp = api + .delete_user_notification_rule( + user_data_id.clone(), + oncall_email_notification_rule_data_id.clone(), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_on-call_GetUserNotificationRule.rs b/examples/v2_on-call_GetUserNotificationRule.rs new file mode 100644 index 000000000..65b0d9418 --- /dev/null +++ b/examples/v2_on-call_GetUserNotificationRule.rs @@ -0,0 +1,28 @@ +// Get an On-Call notification rule for a user returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_on_call::GetUserNotificationRuleOptionalParams; +use datadog_api_client::datadogV2::api_on_call::OnCallAPI; + +#[tokio::main] +async fn main() { + // there is a valid "user" in the system + let user_data_id = std::env::var("USER_DATA_ID").unwrap(); + + // there is a valid "oncall_email_notification_rule" in the system + let oncall_email_notification_rule_data_id = + std::env::var("ONCALL_EMAIL_NOTIFICATION_RULE_DATA_ID").unwrap(); + let configuration = datadog::Configuration::new(); + let api = OnCallAPI::with_config(configuration); + let resp = api + .get_user_notification_rule( + user_data_id.clone(), + oncall_email_notification_rule_data_id.clone(), + GetUserNotificationRuleOptionalParams::default().include("channel".to_string()), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_on-call_ListUserNotificationRules.rs b/examples/v2_on-call_ListUserNotificationRules.rs new file mode 100644 index 000000000..f5cc2319d --- /dev/null +++ b/examples/v2_on-call_ListUserNotificationRules.rs @@ -0,0 +1,23 @@ +// List On-Call notification rules for a user returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_on_call::ListUserNotificationRulesOptionalParams; +use datadog_api_client::datadogV2::api_on_call::OnCallAPI; + +#[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 configuration = datadog::Configuration::new(); + let api = OnCallAPI::with_config(configuration); + let resp = api + .list_user_notification_rules( + user_data_id.clone(), + ListUserNotificationRulesOptionalParams::default().include("channel".to_string()), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_on-call_UpdateUserNotificationRule.rs b/examples/v2_on-call_UpdateUserNotificationRule.rs new file mode 100644 index 000000000..9536429b7 --- /dev/null +++ b/examples/v2_on-call_UpdateUserNotificationRule.rs @@ -0,0 +1,62 @@ +// Update an On-Call notification rule for a user returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_on_call::OnCallAPI; +use datadog_api_client::datadogV2::api_on_call::UpdateUserNotificationRuleOptionalParams; +use datadog_api_client::datadogV2::model::NotificationChannelType; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleCategory; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleChannelRelationship; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleChannelRelationshipData; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleRelationships; +use datadog_api_client::datadogV2::model::OnCallNotificationRuleType; +use datadog_api_client::datadogV2::model::UpdateOnCallNotificationRuleRequest; +use datadog_api_client::datadogV2::model::UpdateOnCallNotificationRuleRequestAttributes; +use datadog_api_client::datadogV2::model::UpdateOnCallNotificationRuleRequestData; + +#[tokio::main] +async fn main() { + // there is a valid "user" in the system + let user_data_id = std::env::var("USER_DATA_ID").unwrap(); + + // there is a valid "oncall_email_notification_rule" in the system + let oncall_email_notification_rule_data_id = + std::env::var("ONCALL_EMAIL_NOTIFICATION_RULE_DATA_ID").unwrap(); + + // there is a valid "oncall_email_notification_channel" in the system + let oncall_email_notification_channel_data_id = + std::env::var("ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID").unwrap(); + let body = UpdateOnCallNotificationRuleRequest::new( + UpdateOnCallNotificationRuleRequestData::new( + OnCallNotificationRuleType::NOTIFICATION_RULES, + ) + .attributes( + UpdateOnCallNotificationRuleRequestAttributes::new() + .category(OnCallNotificationRuleCategory::HIGH_URGENCY) + .delay_minutes(1), + ) + .id(oncall_email_notification_rule_data_id.clone()) + .relationships( + OnCallNotificationRuleRelationships::new().channel( + OnCallNotificationRuleChannelRelationship::new( + OnCallNotificationRuleChannelRelationshipData::new() + .id(oncall_email_notification_channel_data_id.clone()) + .type_(NotificationChannelType::NOTIFICATION_CHANNELS), + ), + ), + ), + ); + let configuration = datadog::Configuration::new(); + let api = OnCallAPI::with_config(configuration); + let resp = api + .update_user_notification_rule( + user_data_id.clone(), + oncall_email_notification_rule_data_id.clone(), + body, + UpdateUserNotificationRuleOptionalParams::default().include("channel".to_string()), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadogV2/api/api_on_call.rs b/src/datadogV2/api/api_on_call.rs index 85f18e523..557e29a61 100644 --- a/src/datadogV2/api/api_on_call.rs +++ b/src/datadogV2/api/api_on_call.rs @@ -129,6 +129,38 @@ impl GetTeamOnCallUsersOptionalParams { } } +/// GetUserNotificationRuleOptionalParams is a struct for passing parameters to the method [`OnCallAPI::get_user_notification_rule`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct GetUserNotificationRuleOptionalParams { + /// Comma-separated list of included relationships to be returned. Allowed values: `channel`. + pub include: Option, +} + +impl GetUserNotificationRuleOptionalParams { + /// Comma-separated list of included relationships to be returned. Allowed values: `channel`. + pub fn include(mut self, value: String) -> Self { + self.include = Some(value); + self + } +} + +/// ListUserNotificationRulesOptionalParams is a struct for passing parameters to the method [`OnCallAPI::list_user_notification_rules`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct ListUserNotificationRulesOptionalParams { + /// Comma-separated list of included relationships to be returned. Allowed values: `channel`. + pub include: Option, +} + +impl ListUserNotificationRulesOptionalParams { + /// Comma-separated list of included relationships to be returned. Allowed values: `channel`. + pub fn include(mut self, value: String) -> Self { + self.include = Some(value); + self + } +} + /// SetOnCallTeamRoutingRulesOptionalParams is a struct for passing parameters to the method [`OnCallAPI::set_on_call_team_routing_rules`] #[non_exhaustive] #[derive(Clone, Default, Debug)] @@ -177,6 +209,22 @@ impl UpdateOnCallScheduleOptionalParams { } } +/// UpdateUserNotificationRuleOptionalParams is a struct for passing parameters to the method [`OnCallAPI::update_user_notification_rule`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct UpdateUserNotificationRuleOptionalParams { + /// Comma-separated list of included relationships to be returned. Allowed values: `channel`. + pub include: Option, +} + +impl UpdateUserNotificationRuleOptionalParams { + /// Comma-separated list of included relationships to be returned. Allowed values: `channel`. + pub fn include(mut self, value: String) -> Self { + self.include = Some(value); + self + } +} + /// CreateOnCallEscalationPolicyError is a struct for typed errors of method [`OnCallAPI::create_on_call_escalation_policy`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -201,6 +249,14 @@ pub enum CreateUserNotificationChannelError { UnknownValue(serde_json::Value), } +/// CreateUserNotificationRuleError is a struct for typed errors of method [`OnCallAPI::create_user_notification_rule`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateUserNotificationRuleError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// DeleteOnCallEscalationPolicyError is a struct for typed errors of method [`OnCallAPI::delete_on_call_escalation_policy`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -225,6 +281,14 @@ pub enum DeleteUserNotificationChannelError { UnknownValue(serde_json::Value), } +/// DeleteUserNotificationRuleError is a struct for typed errors of method [`OnCallAPI::delete_user_notification_rule`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteUserNotificationRuleError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// GetOnCallEscalationPolicyError is a struct for typed errors of method [`OnCallAPI::get_on_call_escalation_policy`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -273,6 +337,14 @@ pub enum GetUserNotificationChannelError { UnknownValue(serde_json::Value), } +/// GetUserNotificationRuleError is a struct for typed errors of method [`OnCallAPI::get_user_notification_rule`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetUserNotificationRuleError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// ListUserNotificationChannelsError is a struct for typed errors of method [`OnCallAPI::list_user_notification_channels`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -281,6 +353,14 @@ pub enum ListUserNotificationChannelsError { UnknownValue(serde_json::Value), } +/// ListUserNotificationRulesError is a struct for typed errors of method [`OnCallAPI::list_user_notification_rules`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListUserNotificationRulesError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// SetOnCallTeamRoutingRulesError is a struct for typed errors of method [`OnCallAPI::set_on_call_team_routing_rules`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -305,6 +385,14 @@ pub enum UpdateOnCallScheduleError { UnknownValue(serde_json::Value), } +/// UpdateUserNotificationRuleError is a struct for typed errors of method [`OnCallAPI::update_user_notification_rule`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateUserNotificationRuleError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// Configure your [Datadog On-Call]() /// directly through the Datadog API. #[derive(Debug, Clone)] @@ -859,6 +947,166 @@ impl OnCallAPI { } } + /// Create a new notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn create_user_notification_rule( + &self, + user_id: String, + body: crate::datadogV2::model::CreateOnCallNotificationRuleRequest, + ) -> Result< + crate::datadogV2::model::OnCallNotificationRule, + datadog::Error, + > { + match self + .create_user_notification_rule_with_http_info(user_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), + } + } + + /// Create a new notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn create_user_notification_rule_with_http_info( + &self, + user_id: String, + body: crate::datadogV2::model::CreateOnCallNotificationRuleRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_user_notification_rule"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/on-call/users/{user_id}/notification-rules", + local_configuration.get_operation_host(operation_id), + user_id = datadog::urlencode(user_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::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } + /// Delete an On-Call escalation policy pub async fn delete_on_call_escalation_policy( &self, @@ -1137,65 +1385,44 @@ impl OnCallAPI { } } - /// Get an On-Call escalation policy - pub async fn get_on_call_escalation_policy( + /// Delete a notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn delete_user_notification_rule( &self, - policy_id: String, - params: GetOnCallEscalationPolicyOptionalParams, - ) -> Result< - crate::datadogV2::model::EscalationPolicy, - datadog::Error, - > { + user_id: String, + rule_id: String, + ) -> Result<(), datadog::Error> { match self - .get_on_call_escalation_policy_with_http_info(policy_id, params) + .delete_user_notification_rule_with_http_info(user_id, rule_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", - ))) - } - } + Ok(_) => Ok(()), Err(err) => Err(err), } } - /// Get an On-Call escalation policy - pub async fn get_on_call_escalation_policy_with_http_info( + /// Delete a notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn delete_user_notification_rule_with_http_info( &self, - policy_id: String, - params: GetOnCallEscalationPolicyOptionalParams, - ) -> Result< - datadog::ResponseContent, - datadog::Error, - > { + user_id: String, + rule_id: String, + ) -> Result, datadog::Error> { let local_configuration = &self.config; - let operation_id = "v2.get_on_call_escalation_policy"; - - // unbox and build optional parameters - let include = params.include; + let operation_id = "v2.delete_user_notification_rule"; let local_client = &self.client; let local_uri_str = format!( - "{}/api/v2/on-call/escalation-policies/{policy_id}", + "{}/api/v2/on-call/users/{user_id}/notification-rules/{rule_id}", local_configuration.get_operation_host(operation_id), - policy_id = datadog::urlencode(policy_id) + user_id = datadog::urlencode(user_id), + rule_id = datadog::urlencode(rule_id) ); let mut local_req_builder = - local_client.request(reqwest::Method::GET, local_uri_str.as_str()); - - if let Some(ref local_query_param) = include { - local_req_builder = - local_req_builder.query(&[("include", &local_query_param.to_string())]); - }; + local_client.request(reqwest::Method::DELETE, local_uri_str.as_str()); // build headers let mut headers = HeaderMap::new(); - headers.insert("Accept", HeaderValue::from_static("application/json")); + headers.insert("Accept", HeaderValue::from_static("*/*")); // build user agent match HeaderValue::from_str(local_configuration.user_agent.as_str()) { @@ -1235,9 +1462,124 @@ impl OnCallAPI { 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) => { + 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 an On-Call escalation policy + pub async fn get_on_call_escalation_policy( + &self, + policy_id: String, + params: GetOnCallEscalationPolicyOptionalParams, + ) -> Result< + crate::datadogV2::model::EscalationPolicy, + datadog::Error, + > { + match self + .get_on_call_escalation_policy_with_http_info(policy_id, params) + .await + { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Get an On-Call escalation policy + pub async fn get_on_call_escalation_policy_with_http_info( + &self, + policy_id: String, + params: GetOnCallEscalationPolicyOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_on_call_escalation_policy"; + + // unbox and build optional parameters + let include = params.include; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/on-call/escalation-policies/{policy_id}", + local_configuration.get_operation_host(operation_id), + policy_id = datadog::urlencode(policy_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = include { + local_req_builder = + local_req_builder.query(&[("include", &local_query_param.to_string())]); + }; + + // 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, @@ -1855,6 +2197,131 @@ impl OnCallAPI { } } + /// Get a notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn get_user_notification_rule( + &self, + user_id: String, + rule_id: String, + params: GetUserNotificationRuleOptionalParams, + ) -> Result< + crate::datadogV2::model::OnCallNotificationRule, + datadog::Error, + > { + match self + .get_user_notification_rule_with_http_info(user_id, rule_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), + } + } + + /// Get a notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn get_user_notification_rule_with_http_info( + &self, + user_id: String, + rule_id: String, + params: GetUserNotificationRuleOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_user_notification_rule"; + + // unbox and build optional parameters + let include = params.include; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/on-call/users/{user_id}/notification-rules/{rule_id}", + local_configuration.get_operation_host(operation_id), + user_id = datadog::urlencode(user_id), + rule_id = datadog::urlencode(rule_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = include { + local_req_builder = + local_req_builder.query(&[("include", &local_query_param.to_string())]); + }; + + // 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)) + } + } + /// List the notification channels for a user. The authenticated user must be the target user or have the `on_call_admin` permission pub async fn list_user_notification_channels( &self, @@ -1967,6 +2434,128 @@ impl OnCallAPI { } } + /// List the notification rules for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn list_user_notification_rules( + &self, + user_id: String, + params: ListUserNotificationRulesOptionalParams, + ) -> Result< + crate::datadogV2::model::ListOnCallNotificationRulesResponse, + datadog::Error, + > { + match self + .list_user_notification_rules_with_http_info(user_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), + } + } + + /// List the notification rules for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn list_user_notification_rules_with_http_info( + &self, + user_id: String, + params: ListUserNotificationRulesOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_user_notification_rules"; + + // unbox and build optional parameters + let include = params.include; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/on-call/users/{user_id}/notification-rules", + 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()); + + if let Some(ref local_query_param) = include { + local_req_builder = + local_req_builder.query(&[("include", &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)) + } + } + /// Set a team's On-Call routing rules pub async fn set_on_call_team_routing_rules( &self, @@ -2469,4 +3058,177 @@ impl OnCallAPI { Err(datadog::Error::ResponseError(local_error)) } } + + /// Update a notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn update_user_notification_rule( + &self, + user_id: String, + rule_id: String, + body: crate::datadogV2::model::UpdateOnCallNotificationRuleRequest, + params: UpdateUserNotificationRuleOptionalParams, + ) -> Result< + crate::datadogV2::model::OnCallNotificationRule, + datadog::Error, + > { + match self + .update_user_notification_rule_with_http_info(user_id, rule_id, body, 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), + } + } + + /// Update a notification rule for a user. The authenticated user must be the target user or have the `on_call_admin` permission + pub async fn update_user_notification_rule_with_http_info( + &self, + user_id: String, + rule_id: String, + body: crate::datadogV2::model::UpdateOnCallNotificationRuleRequest, + params: UpdateUserNotificationRuleOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_user_notification_rule"; + + // unbox and build optional parameters + let include = params.include; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/on-call/users/{user_id}/notification-rules/{rule_id}", + local_configuration.get_operation_host(operation_id), + user_id = datadog::urlencode(user_id), + rule_id = datadog::urlencode(rule_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PUT, local_uri_str.as_str()); + + if let Some(ref local_query_param) = include { + local_req_builder = + local_req_builder.query(&[("include", &local_query_param.to_string())]); + }; + + // 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::( + &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/model/mod.rs b/src/datadogV2/model/mod.rs index e63dfc686..4ef2e3a57 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -4348,6 +4348,44 @@ pub mod model_create_notification_channel_config; pub use self::model_create_notification_channel_config::CreateNotificationChannelConfig; pub mod model_notification_channel; pub use self::model_notification_channel::NotificationChannel; +pub mod model_list_on_call_notification_rules_response; +pub use self::model_list_on_call_notification_rules_response::ListOnCallNotificationRulesResponse; +pub mod model_on_call_notification_rule_data; +pub use self::model_on_call_notification_rule_data::OnCallNotificationRuleData; +pub mod model_on_call_notification_rule_attributes; +pub use self::model_on_call_notification_rule_attributes::OnCallNotificationRuleAttributes; +pub mod model_on_call_notification_rule_category; +pub use self::model_on_call_notification_rule_category::OnCallNotificationRuleCategory; +pub mod model_on_call_phone_notification_rule_settings; +pub use self::model_on_call_phone_notification_rule_settings::OnCallPhoneNotificationRuleSettings; +pub mod model_on_call_phone_notification_rule_method; +pub use self::model_on_call_phone_notification_rule_method::OnCallPhoneNotificationRuleMethod; +pub mod model_on_call_notification_rule_channel_settings; +pub use self::model_on_call_notification_rule_channel_settings::OnCallNotificationRuleChannelSettings; +pub mod model_on_call_notification_rule_relationships; +pub use self::model_on_call_notification_rule_relationships::OnCallNotificationRuleRelationships; +pub mod model_on_call_notification_rule_channel_relationship; +pub use self::model_on_call_notification_rule_channel_relationship::OnCallNotificationRuleChannelRelationship; +pub mod model_on_call_notification_rule_channel_relationship_data; +pub use self::model_on_call_notification_rule_channel_relationship_data::OnCallNotificationRuleChannelRelationshipData; +pub mod model_on_call_notification_rule_type; +pub use self::model_on_call_notification_rule_type::OnCallNotificationRuleType; +pub mod model_on_call_notification_rules_included; +pub use self::model_on_call_notification_rules_included::OnCallNotificationRulesIncluded; +pub mod model_create_on_call_notification_rule_request; +pub use self::model_create_on_call_notification_rule_request::CreateOnCallNotificationRuleRequest; +pub mod model_create_on_call_notification_rule_request_data; +pub use self::model_create_on_call_notification_rule_request_data::CreateOnCallNotificationRuleRequestData; +pub mod model_on_call_notification_rule_request_attributes; +pub use self::model_on_call_notification_rule_request_attributes::OnCallNotificationRuleRequestAttributes; +pub mod model_on_call_notification_rule; +pub use self::model_on_call_notification_rule::OnCallNotificationRule; +pub mod model_update_on_call_notification_rule_request; +pub use self::model_update_on_call_notification_rule_request::UpdateOnCallNotificationRuleRequest; +pub mod model_update_on_call_notification_rule_request_data; +pub use self::model_update_on_call_notification_rule_request_data::UpdateOnCallNotificationRuleRequestData; +pub mod model_update_on_call_notification_rule_request_attributes; +pub use self::model_update_on_call_notification_rule_request_attributes::UpdateOnCallNotificationRuleRequestAttributes; pub mod model_org_config_list_response; pub use self::model_org_config_list_response::OrgConfigListResponse; pub mod model_org_config_read; diff --git a/src/datadogV2/model/model_create_on_call_notification_rule_request.rs b/src/datadogV2/model/model_create_on_call_notification_rule_request.rs new file mode 100644 index 000000000..bb8f47a36 --- /dev/null +++ b/src/datadogV2/model/model_create_on_call_notification_rule_request.rs @@ -0,0 +1,96 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A top-level wrapper for creating a notification rule for a user +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct CreateOnCallNotificationRuleRequest { + /// Data for creating an on-call notification rule + #[serde(rename = "data")] + pub data: crate::datadogV2::model::CreateOnCallNotificationRuleRequestData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl CreateOnCallNotificationRuleRequest { + pub fn new( + data: crate::datadogV2::model::CreateOnCallNotificationRuleRequestData, + ) -> CreateOnCallNotificationRuleRequest { + CreateOnCallNotificationRuleRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for CreateOnCallNotificationRuleRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct CreateOnCallNotificationRuleRequestVisitor; + impl<'a> Visitor<'a> for CreateOnCallNotificationRuleRequestVisitor { + type Value = CreateOnCallNotificationRuleRequest; + + 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::CreateOnCallNotificationRuleRequestData, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = CreateOnCallNotificationRuleRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(CreateOnCallNotificationRuleRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_create_on_call_notification_rule_request_data.rs b/src/datadogV2/model/model_create_on_call_notification_rule_request_data.rs new file mode 100644 index 000000000..3460e8582 --- /dev/null +++ b/src/datadogV2/model/model_create_on_call_notification_rule_request_data.rs @@ -0,0 +1,147 @@ +// 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 for creating an on-call notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct CreateOnCallNotificationRuleRequestData { + /// Attributes for creating or modifying an on-call notification rule. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Relationship object for creating a notification rule + #[serde(rename = "relationships")] + pub relationships: Option, + /// Indicates that the resource is of type 'notification_rules'. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::OnCallNotificationRuleType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl CreateOnCallNotificationRuleRequestData { + pub fn new( + type_: crate::datadogV2::model::OnCallNotificationRuleType, + ) -> CreateOnCallNotificationRuleRequestData { + CreateOnCallNotificationRuleRequestData { + attributes: None, + relationships: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleRequestAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn relationships( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleRelationships, + ) -> Self { + self.relationships = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for CreateOnCallNotificationRuleRequestData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct CreateOnCallNotificationRuleRequestDataVisitor; + impl<'a> Visitor<'a> for CreateOnCallNotificationRuleRequestDataVisitor { + type Value = CreateOnCallNotificationRuleRequestData; + + 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::OnCallNotificationRuleRequestAttributes, + > = None; + let mut relationships: Option< + crate::datadogV2::model::OnCallNotificationRuleRelationships, + > = 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)?); + } + "relationships" => { + if v.is_null() { + continue; + } + relationships = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::OnCallNotificationRuleType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = CreateOnCallNotificationRuleRequestData { + attributes, + relationships, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(CreateOnCallNotificationRuleRequestDataVisitor) + } +} diff --git a/src/datadogV2/model/model_list_on_call_notification_rules_response.rs b/src/datadogV2/model/model_list_on_call_notification_rules_response.rs new file mode 100644 index 000000000..6851564b2 --- /dev/null +++ b/src/datadogV2/model/model_list_on_call_notification_rules_response.rs @@ -0,0 +1,126 @@ +// 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 type for listing notification rules for a user +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ListOnCallNotificationRulesResponse { + #[serde(rename = "data")] + pub data: Option>, + #[serde(rename = "included")] + pub included: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ListOnCallNotificationRulesResponse { + pub fn new() -> ListOnCallNotificationRulesResponse { + ListOnCallNotificationRulesResponse { + data: None, + included: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: Vec) -> 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 ListOnCallNotificationRulesResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ListOnCallNotificationRulesResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ListOnCallNotificationRulesResponseVisitor; + impl<'a> Visitor<'a> for ListOnCallNotificationRulesResponseVisitor { + type Value = ListOnCallNotificationRulesResponse; + + 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 = ListOnCallNotificationRulesResponse { + data, + included, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ListOnCallNotificationRulesResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule.rs b/src/datadogV2/model/model_on_call_notification_rule.rs new file mode 100644 index 000000000..39267aa8a --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule.rs @@ -0,0 +1,115 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A top-level wrapper for a notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRule { + /// Data for an on-call notification rule + #[serde(rename = "data")] + pub data: crate::datadogV2::model::OnCallNotificationRuleData, + #[serde(rename = "included")] + pub included: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRule { + pub fn new( + data: crate::datadogV2::model::OnCallNotificationRuleData, + ) -> OnCallNotificationRule { + OnCallNotificationRule { + data, + included: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn included( + mut self, + value: Vec, + ) -> Self { + self.included = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRule { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleVisitor { + type Value = OnCallNotificationRule; + + 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" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "included" => { + if v.is_null() { + continue; + } + included = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = OnCallNotificationRule { + data, + included, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_attributes.rs b/src/datadogV2/model/model_on_call_notification_rule_attributes.rs new file mode 100644 index 000000000..c17d9fb4e --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_attributes.rs @@ -0,0 +1,166 @@ +// 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 for an on-call notification rule. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRuleAttributes { + /// Specifies the category a notification rule will apply to + #[serde(rename = "category")] + pub category: Option, + /// Defines the configuration for a channel associated with a notification rule + #[serde(rename = "channel_settings")] + pub channel_settings: Option, + /// The number of minutes that will elapse before this rule is evaluated. 0 indicates immediate evaluation + #[serde(rename = "delay_minutes")] + pub delay_minutes: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRuleAttributes { + pub fn new() -> OnCallNotificationRuleAttributes { + OnCallNotificationRuleAttributes { + category: None, + channel_settings: None, + delay_minutes: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn category( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleCategory, + ) -> Self { + self.category = Some(value); + self + } + + pub fn channel_settings( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleChannelSettings, + ) -> Self { + self.channel_settings = Some(value); + self + } + + pub fn delay_minutes(mut self, value: i64) -> Self { + self.delay_minutes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for OnCallNotificationRuleAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleAttributesVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleAttributesVisitor { + type Value = OnCallNotificationRuleAttributes; + + 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 category: Option = + None; + let mut channel_settings: Option< + crate::datadogV2::model::OnCallNotificationRuleChannelSettings, + > = None; + let mut delay_minutes: 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() { + "category" => { + if v.is_null() { + continue; + } + category = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _category) = category { + match _category { + crate::datadogV2::model::OnCallNotificationRuleCategory::UnparsedObject(_category) => { + _unparsed = true; + }, + _ => {} + } + } + } + "channel_settings" => { + if v.is_null() { + continue; + } + channel_settings = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _channel_settings) = channel_settings { + match _channel_settings { + crate::datadogV2::model::OnCallNotificationRuleChannelSettings::UnparsedObject(_channel_settings) => { + _unparsed = true; + }, + _ => {} + } + } + } + "delay_minutes" => { + if v.is_null() { + continue; + } + delay_minutes = + 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 = OnCallNotificationRuleAttributes { + category, + channel_settings, + delay_minutes, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_category.rs b/src/datadogV2/model/model_on_call_notification_rule_category.rs new file mode 100644 index 000000000..ffc3eb08c --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_category.rs @@ -0,0 +1,51 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum OnCallNotificationRuleCategory { + HIGH_URGENCY, + LOW_URGENCY, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for OnCallNotificationRuleCategory { + fn to_string(&self) -> String { + match self { + Self::HIGH_URGENCY => String::from("high_urgency"), + Self::LOW_URGENCY => String::from("low_urgency"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for OnCallNotificationRuleCategory { + 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 OnCallNotificationRuleCategory { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "high_urgency" => Self::HIGH_URGENCY, + "low_urgency" => Self::LOW_URGENCY, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_channel_relationship.rs b/src/datadogV2/model/model_on_call_notification_rule_channel_relationship.rs new file mode 100644 index 000000000..9d85e7bbd --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_channel_relationship.rs @@ -0,0 +1,96 @@ +// 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}; + +/// Relationship object for creating a notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRuleChannelRelationship { + /// Channel relationship data for creating a notification rule + #[serde(rename = "data")] + pub data: crate::datadogV2::model::OnCallNotificationRuleChannelRelationshipData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRuleChannelRelationship { + pub fn new( + data: crate::datadogV2::model::OnCallNotificationRuleChannelRelationshipData, + ) -> OnCallNotificationRuleChannelRelationship { + OnCallNotificationRuleChannelRelationship { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleChannelRelationship { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleChannelRelationshipVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleChannelRelationshipVisitor { + type Value = OnCallNotificationRuleChannelRelationship; + + 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::OnCallNotificationRuleChannelRelationshipData, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = OnCallNotificationRuleChannelRelationship { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleChannelRelationshipVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_channel_relationship_data.rs b/src/datadogV2/model/model_on_call_notification_rule_channel_relationship_data.rs new file mode 100644 index 000000000..b46ddcee5 --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_channel_relationship_data.rs @@ -0,0 +1,130 @@ +// 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}; + +/// Channel relationship data for creating a notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRuleChannelRelationshipData { + /// ID of the notification channel + #[serde(rename = "id")] + pub id: Option, + /// Indicates that the resource is of type 'notification_channels'. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRuleChannelRelationshipData { + pub fn new() -> OnCallNotificationRuleChannelRelationshipData { + OnCallNotificationRuleChannelRelationshipData { + id: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::NotificationChannelType) -> 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 OnCallNotificationRuleChannelRelationshipData { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleChannelRelationshipData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleChannelRelationshipDataVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleChannelRelationshipDataVisitor { + type Value = OnCallNotificationRuleChannelRelationshipData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut id: Option = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "id" => { + 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 Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::NotificationChannelType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = OnCallNotificationRuleChannelRelationshipData { + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleChannelRelationshipDataVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_channel_settings.rs b/src/datadogV2/model/model_on_call_notification_rule_channel_settings.rs new file mode 100644 index 000000000..3a2b403fc --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_channel_settings.rs @@ -0,0 +1,38 @@ +// 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}; + +/// Defines the configuration for a channel associated with a notification rule +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum OnCallNotificationRuleChannelSettings { + OnCallPhoneNotificationRuleSettings( + Box, + ), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleChannelSettings { + 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::< + Box, + >(value.clone()) + { + if !_v._unparsed { + return Ok( + OnCallNotificationRuleChannelSettings::OnCallPhoneNotificationRuleSettings(_v), + ); + } + } + + return Ok(OnCallNotificationRuleChannelSettings::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_data.rs b/src/datadogV2/model/model_on_call_notification_rule_data.rs new file mode 100644 index 000000000..841099b42 --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_data.rs @@ -0,0 +1,164 @@ +// 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 for an on-call notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRuleData { + /// Attributes for an on-call notification rule. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Unique identifier for the rule + #[serde(rename = "id")] + pub id: Option, + /// Relationship object for creating a notification rule + #[serde(rename = "relationships")] + pub relationships: Option, + /// Indicates that the resource is of type 'notification_rules'. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::OnCallNotificationRuleType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRuleData { + pub fn new( + type_: crate::datadogV2::model::OnCallNotificationRuleType, + ) -> OnCallNotificationRuleData { + OnCallNotificationRuleData { + attributes: None, + id: None, + relationships: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleAttributes, + ) -> 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::OnCallNotificationRuleRelationships, + ) -> Self { + self.relationships = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleDataVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleDataVisitor { + type Value = OnCallNotificationRuleData; + + 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::OnCallNotificationRuleAttributes, + > = None; + let mut id: Option = None; + let mut relationships: Option< + crate::datadogV2::model::OnCallNotificationRuleRelationships, + > = 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" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::OnCallNotificationRuleType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = OnCallNotificationRuleData { + attributes, + id, + relationships, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleDataVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_relationships.rs b/src/datadogV2/model/model_on_call_notification_rule_relationships.rs new file mode 100644 index 000000000..c1de33b9f --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_relationships.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}; + +/// Relationship object for creating a notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRuleRelationships { + /// Relationship object for creating a notification rule + #[serde(rename = "channel")] + pub channel: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRuleRelationships { + pub fn new() -> OnCallNotificationRuleRelationships { + OnCallNotificationRuleRelationships { + channel: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn channel( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleChannelRelationship, + ) -> Self { + self.channel = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for OnCallNotificationRuleRelationships { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleRelationships { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleRelationshipsVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleRelationshipsVisitor { + type Value = OnCallNotificationRuleRelationships; + + 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 channel: Option< + crate::datadogV2::model::OnCallNotificationRuleChannelRelationship, + > = 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() { + "channel" => { + if v.is_null() { + continue; + } + channel = 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 = OnCallNotificationRuleRelationships { + channel, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleRelationshipsVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_request_attributes.rs b/src/datadogV2/model/model_on_call_notification_rule_request_attributes.rs new file mode 100644 index 000000000..812e7a567 --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_request_attributes.rs @@ -0,0 +1,166 @@ +// 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 for creating or modifying an on-call notification rule. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallNotificationRuleRequestAttributes { + /// Specifies the category a notification rule will apply to + #[serde(rename = "category")] + pub category: Option, + /// Defines the configuration for a channel associated with a notification rule + #[serde(rename = "channel_settings")] + pub channel_settings: Option, + /// The number of minutes that will elapse before this rule is evaluated. 0 indicates immediate evaluation + #[serde(rename = "delay_minutes")] + pub delay_minutes: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallNotificationRuleRequestAttributes { + pub fn new() -> OnCallNotificationRuleRequestAttributes { + OnCallNotificationRuleRequestAttributes { + category: None, + channel_settings: None, + delay_minutes: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn category( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleCategory, + ) -> Self { + self.category = Some(value); + self + } + + pub fn channel_settings( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleChannelSettings, + ) -> Self { + self.channel_settings = Some(value); + self + } + + pub fn delay_minutes(mut self, value: i64) -> Self { + self.delay_minutes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for OnCallNotificationRuleRequestAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for OnCallNotificationRuleRequestAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallNotificationRuleRequestAttributesVisitor; + impl<'a> Visitor<'a> for OnCallNotificationRuleRequestAttributesVisitor { + type Value = OnCallNotificationRuleRequestAttributes; + + 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 category: Option = + None; + let mut channel_settings: Option< + crate::datadogV2::model::OnCallNotificationRuleChannelSettings, + > = None; + let mut delay_minutes: 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() { + "category" => { + if v.is_null() { + continue; + } + category = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _category) = category { + match _category { + crate::datadogV2::model::OnCallNotificationRuleCategory::UnparsedObject(_category) => { + _unparsed = true; + }, + _ => {} + } + } + } + "channel_settings" => { + if v.is_null() { + continue; + } + channel_settings = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _channel_settings) = channel_settings { + match _channel_settings { + crate::datadogV2::model::OnCallNotificationRuleChannelSettings::UnparsedObject(_channel_settings) => { + _unparsed = true; + }, + _ => {} + } + } + } + "delay_minutes" => { + if v.is_null() { + continue; + } + delay_minutes = + 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 = OnCallNotificationRuleRequestAttributes { + category, + channel_settings, + delay_minutes, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallNotificationRuleRequestAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rule_type.rs b/src/datadogV2/model/model_on_call_notification_rule_type.rs new file mode 100644 index 000000000..756fadffc --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rule_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 OnCallNotificationRuleType { + NOTIFICATION_RULES, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for OnCallNotificationRuleType { + fn to_string(&self) -> String { + match self { + Self::NOTIFICATION_RULES => String::from("notification_rules"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for OnCallNotificationRuleType { + 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 OnCallNotificationRuleType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "notification_rules" => Self::NOTIFICATION_RULES, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_on_call_notification_rules_included.rs b/src/datadogV2/model/model_on_call_notification_rules_included.rs new file mode 100644 index 000000000..f74a81dd9 --- /dev/null +++ b/src/datadogV2/model/model_on_call_notification_rules_included.rs @@ -0,0 +1,34 @@ +// 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}; + +/// Represents additional included resources for a on-call notification rules +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum OnCallNotificationRulesIncluded { + NotificationChannelData(Box), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for OnCallNotificationRulesIncluded { + 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::< + Box, + >(value.clone()) + { + if !_v._unparsed { + return Ok(OnCallNotificationRulesIncluded::NotificationChannelData(_v)); + } + } + + return Ok(OnCallNotificationRulesIncluded::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/src/datadogV2/model/model_on_call_phone_notification_rule_method.rs b/src/datadogV2/model/model_on_call_phone_notification_rule_method.rs new file mode 100644 index 000000000..044d88e9d --- /dev/null +++ b/src/datadogV2/model/model_on_call_phone_notification_rule_method.rs @@ -0,0 +1,51 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum OnCallPhoneNotificationRuleMethod { + SMS, + VOICE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for OnCallPhoneNotificationRuleMethod { + fn to_string(&self) -> String { + match self { + Self::SMS => String::from("sms"), + Self::VOICE => String::from("voice"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for OnCallPhoneNotificationRuleMethod { + 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 OnCallPhoneNotificationRuleMethod { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "sms" => Self::SMS, + "voice" => Self::VOICE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_on_call_phone_notification_rule_settings.rs b/src/datadogV2/model/model_on_call_phone_notification_rule_settings.rs new file mode 100644 index 000000000..bd6192631 --- /dev/null +++ b/src/datadogV2/model/model_on_call_phone_notification_rule_settings.rs @@ -0,0 +1,123 @@ +// 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}; + +/// Configuration for using a phone notification channel in a notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct OnCallPhoneNotificationRuleSettings { + /// Specifies the method in which a phone is used in a notification rule + #[serde(rename = "method")] + pub method: crate::datadogV2::model::OnCallPhoneNotificationRuleMethod, + /// Indicates that the notification channel is a phone + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::NotificationChannelPhoneConfigType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl OnCallPhoneNotificationRuleSettings { + pub fn new( + method: crate::datadogV2::model::OnCallPhoneNotificationRuleMethod, + type_: crate::datadogV2::model::NotificationChannelPhoneConfigType, + ) -> OnCallPhoneNotificationRuleSettings { + OnCallPhoneNotificationRuleSettings { + method, + 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 OnCallPhoneNotificationRuleSettings { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct OnCallPhoneNotificationRuleSettingsVisitor; + impl<'a> Visitor<'a> for OnCallPhoneNotificationRuleSettingsVisitor { + type Value = OnCallPhoneNotificationRuleSettings; + + 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 method: 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() { + "method" => { + method = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _method) = method { + match _method { + crate::datadogV2::model::OnCallPhoneNotificationRuleMethod::UnparsedObject(_method) => { + _unparsed = true; + }, + _ => {} + } + } + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::NotificationChannelPhoneConfigType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let method = method.ok_or_else(|| M::Error::missing_field("method"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = OnCallPhoneNotificationRuleSettings { + method, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(OnCallPhoneNotificationRuleSettingsVisitor) + } +} diff --git a/src/datadogV2/model/model_update_on_call_notification_rule_request.rs b/src/datadogV2/model/model_update_on_call_notification_rule_request.rs new file mode 100644 index 000000000..e4b7fee6d --- /dev/null +++ b/src/datadogV2/model/model_update_on_call_notification_rule_request.rs @@ -0,0 +1,96 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A top-level wrapper for updating a notification rule for a user +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct UpdateOnCallNotificationRuleRequest { + /// Data for updating an on-call notification rule + #[serde(rename = "data")] + pub data: crate::datadogV2::model::UpdateOnCallNotificationRuleRequestData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl UpdateOnCallNotificationRuleRequest { + pub fn new( + data: crate::datadogV2::model::UpdateOnCallNotificationRuleRequestData, + ) -> UpdateOnCallNotificationRuleRequest { + UpdateOnCallNotificationRuleRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for UpdateOnCallNotificationRuleRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct UpdateOnCallNotificationRuleRequestVisitor; + impl<'a> Visitor<'a> for UpdateOnCallNotificationRuleRequestVisitor { + type Value = UpdateOnCallNotificationRuleRequest; + + 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::UpdateOnCallNotificationRuleRequestData, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = UpdateOnCallNotificationRuleRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(UpdateOnCallNotificationRuleRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_update_on_call_notification_rule_request_attributes.rs b/src/datadogV2/model/model_update_on_call_notification_rule_request_attributes.rs new file mode 100644 index 000000000..aac4ed976 --- /dev/null +++ b/src/datadogV2/model/model_update_on_call_notification_rule_request_attributes.rs @@ -0,0 +1,166 @@ +// 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 for creating or modifying an on-call notification rule. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct UpdateOnCallNotificationRuleRequestAttributes { + /// Specifies the category a notification rule will apply to + #[serde(rename = "category")] + pub category: Option, + /// Defines the configuration for a channel associated with a notification rule + #[serde(rename = "channel_settings")] + pub channel_settings: Option, + /// The number of minutes that will elapse before this rule is evaluated. 0 indicates immediate evaluation + #[serde(rename = "delay_minutes")] + pub delay_minutes: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl UpdateOnCallNotificationRuleRequestAttributes { + pub fn new() -> UpdateOnCallNotificationRuleRequestAttributes { + UpdateOnCallNotificationRuleRequestAttributes { + category: None, + channel_settings: None, + delay_minutes: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn category( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleCategory, + ) -> Self { + self.category = Some(value); + self + } + + pub fn channel_settings( + mut self, + value: crate::datadogV2::model::OnCallNotificationRuleChannelSettings, + ) -> Self { + self.channel_settings = Some(value); + self + } + + pub fn delay_minutes(mut self, value: i64) -> Self { + self.delay_minutes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for UpdateOnCallNotificationRuleRequestAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for UpdateOnCallNotificationRuleRequestAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct UpdateOnCallNotificationRuleRequestAttributesVisitor; + impl<'a> Visitor<'a> for UpdateOnCallNotificationRuleRequestAttributesVisitor { + type Value = UpdateOnCallNotificationRuleRequestAttributes; + + 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 category: Option = + None; + let mut channel_settings: Option< + crate::datadogV2::model::OnCallNotificationRuleChannelSettings, + > = None; + let mut delay_minutes: 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() { + "category" => { + if v.is_null() { + continue; + } + category = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _category) = category { + match _category { + crate::datadogV2::model::OnCallNotificationRuleCategory::UnparsedObject(_category) => { + _unparsed = true; + }, + _ => {} + } + } + } + "channel_settings" => { + if v.is_null() { + continue; + } + channel_settings = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _channel_settings) = channel_settings { + match _channel_settings { + crate::datadogV2::model::OnCallNotificationRuleChannelSettings::UnparsedObject(_channel_settings) => { + _unparsed = true; + }, + _ => {} + } + } + } + "delay_minutes" => { + if v.is_null() { + continue; + } + delay_minutes = + 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 = UpdateOnCallNotificationRuleRequestAttributes { + category, + channel_settings, + delay_minutes, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(UpdateOnCallNotificationRuleRequestAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_update_on_call_notification_rule_request_data.rs b/src/datadogV2/model/model_update_on_call_notification_rule_request_data.rs new file mode 100644 index 000000000..ddd0435f5 --- /dev/null +++ b/src/datadogV2/model/model_update_on_call_notification_rule_request_data.rs @@ -0,0 +1,164 @@ +// 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 for updating an on-call notification rule +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct UpdateOnCallNotificationRuleRequestData { + /// Attributes for creating or modifying an on-call notification rule. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Unique identifier for the rule + #[serde(rename = "id")] + pub id: Option, + /// Relationship object for creating a notification rule + #[serde(rename = "relationships")] + pub relationships: Option, + /// Indicates that the resource is of type 'notification_rules'. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::OnCallNotificationRuleType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl UpdateOnCallNotificationRuleRequestData { + pub fn new( + type_: crate::datadogV2::model::OnCallNotificationRuleType, + ) -> UpdateOnCallNotificationRuleRequestData { + UpdateOnCallNotificationRuleRequestData { + attributes: None, + id: None, + relationships: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::UpdateOnCallNotificationRuleRequestAttributes, + ) -> 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::OnCallNotificationRuleRelationships, + ) -> Self { + self.relationships = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for UpdateOnCallNotificationRuleRequestData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct UpdateOnCallNotificationRuleRequestDataVisitor; + impl<'a> Visitor<'a> for UpdateOnCallNotificationRuleRequestDataVisitor { + type Value = UpdateOnCallNotificationRuleRequestData; + + 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::UpdateOnCallNotificationRuleRequestAttributes, + > = None; + let mut id: Option = None; + let mut relationships: Option< + crate::datadogV2::model::OnCallNotificationRuleRelationships, + > = 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" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::OnCallNotificationRuleType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = UpdateOnCallNotificationRuleRequestData { + attributes, + id, + relationships, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(UpdateOnCallNotificationRuleRequestDataVisitor) + } +} diff --git a/tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.frozen b/tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.frozen new file mode 100644 index 000000000..fd26d2eef --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.frozen @@ -0,0 +1 @@ +2025-12-16T19:30:04.834Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.json b/tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.json new file mode 100644 index 000000000..49a9da6b7 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Create-an-On-Call-notification-rule-for-a-user-returns-Created-response.json @@ -0,0 +1,131 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"email\":\"Test-Create_an_On_Call_notification_rule_for_a_user_returns_Created_response-1765913404@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/users" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"users\",\"id\":\"2ab53f07-289f-4060-b21a-3d704096aadf\",\"attributes\":{\"name\":null,\"handle\":\"test-create_an_on_call_notification_rule_for_a_user_returns_created_response-1765913404@datadoghq.com\",\"created_at\":\"2025-12-16T19:30:05.014723+00:00\",\"modified_at\":\"2025-12-16T19:30:05.014723+00:00\",\"email\":\"test-create_an_on_call_notification_rule_for_a_user_returns_created_response-1765913404@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/c5ddb15c50d998db06711e0a31591216?s=48&d=retro\",\"title\":\"user title\",\"verified\":false,\"service_account\":false,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Pending\",\"last_login_time\":null},\"relationships\":{\"roles\":{\"data\":[]},\"org\":{\"data\":{\"type\":\"orgs\",\"id\":\"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:30:04 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"config\":{\"address\":\"test-create_an_on_call_notification_rule_for_a_user_returns_created_response-1765913404@datadoghq.com\",\"formats\":[\"html\"],\"type\":\"email\"}},\"type\":\"notification_channels\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/2ab53f07-289f-4060-b21a-3d704096aadf/notification-channels" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"ca8520ce-27e0-4bba-997f-004047cda45d\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-create_an_on_call_notification_rule_for_a_user_returns_created_response-1765913404@datadoghq.com\",\"formats\":[\"html\"]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:30:04 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"ca8520ce-27e0-4bba-997f-004047cda45d\",\"type\":\"notification_channels\"}}},\"type\":\"notification_rules\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/2ab53f07-289f-4060-b21a-3d704096aadf/notification-rules" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"4e551e4f-d1aa-4fce-8cc7-c6bf98925efe\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"ca8520ce-27e0-4bba-997f-004047cda45d\",\"type\":\"notification_channels\"}}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:30:04 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/users/2ab53f07-289f-4060-b21a-3d704096aadf" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:30:04 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.frozen b/tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.frozen new file mode 100644 index 000000000..3b1ee11b9 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.frozen @@ -0,0 +1 @@ +2025-12-16T19:29:36.256Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.json b/tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.json new file mode 100644 index 000000000..024f8ab07 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Delete-an-On-Call-notification-rule-for-a-user-returns-No-Content-response.json @@ -0,0 +1,155 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"email\":\"Test-Delete_an_On_Call_notification_rule_for_a_user_returns_No_Content_response-1765913376@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/users" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"users\",\"id\":\"5ebbe76d-c072-4909-ba24-ffa71f4597a0\",\"attributes\":{\"name\":null,\"handle\":\"test-delete_an_on_call_notification_rule_for_a_user_returns_no_content_response-1765913376@datadoghq.com\",\"created_at\":\"2025-12-16T19:29:36.461504+00:00\",\"modified_at\":\"2025-12-16T19:29:36.461504+00:00\",\"email\":\"test-delete_an_on_call_notification_rule_for_a_user_returns_no_content_response-1765913376@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/dad7a8a5508730e67ad8dea90bcc189c?s=48&d=retro\",\"title\":\"user title\",\"verified\":false,\"service_account\":false,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Pending\",\"last_login_time\":null},\"relationships\":{\"roles\":{\"data\":[]},\"org\":{\"data\":{\"type\":\"orgs\",\"id\":\"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:29:36 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"config\":{\"address\":\"test-delete_an_on_call_notification_rule_for_a_user_returns_no_content_response-1765913376@datadoghq.com\",\"formats\":[\"html\"],\"type\":\"email\"}},\"type\":\"notification_channels\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/5ebbe76d-c072-4909-ba24-ffa71f4597a0/notification-channels" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"a557eb68-8b0a-48cf-ac65-73aede790994\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-delete_an_on_call_notification_rule_for_a_user_returns_no_content_response-1765913376@datadoghq.com\",\"formats\":[\"html\"]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:29:36 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"a557eb68-8b0a-48cf-ac65-73aede790994\",\"type\":\"notification_channels\"}}},\"type\":\"notification_rules\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/5ebbe76d-c072-4909-ba24-ffa71f4597a0/notification-rules" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"71e9f009-5a69-4946-992e-d76b05d1ae61\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"a557eb68-8b0a-48cf-ac65-73aede790994\",\"type\":\"notification_channels\"}}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:29:36 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/5ebbe76d-c072-4909-ba24-ffa71f4597a0/notification-rules/71e9f009-5a69-4946-992e-d76b05d1ae61" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:29:36 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/users/5ebbe76d-c072-4909-ba24-ffa71f4597a0" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Tue, 16 Dec 2025 19:29:36 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen new file mode 100644 index 000000000..d938f1a43 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-12-16T21:16:24.271Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.json b/tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.json new file mode 100644 index 000000000..a90b547c5 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Get-an-On-Call-notification-rule-for-a-user-returns-OK-response.json @@ -0,0 +1,159 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"email\":\"Test-Get_an_On_Call_notification_rule_for_a_user_returns_OK_response-1765919784@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/users" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"users\",\"id\":\"b2a555c9-ac2d-430d-b321-10e4c0201ce3\",\"attributes\":{\"name\":null,\"handle\":\"test-get_an_on_call_notification_rule_for_a_user_returns_ok_response-1765919784@datadoghq.com\",\"created_at\":\"2025-12-16T21:16:24.480454+00:00\",\"modified_at\":\"2025-12-16T21:16:24.480454+00:00\",\"email\":\"test-get_an_on_call_notification_rule_for_a_user_returns_ok_response-1765919784@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/8e38ab440c2cdd2808a61dfa83f734d7?s=48&d=retro\",\"title\":\"user title\",\"verified\":false,\"service_account\":false,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Pending\",\"last_login_time\":null},\"relationships\":{\"roles\":{\"data\":[]},\"org\":{\"data\":{\"type\":\"orgs\",\"id\":\"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:24 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"config\":{\"address\":\"test-get_an_on_call_notification_rule_for_a_user_returns_ok_response-1765919784@datadoghq.com\",\"formats\":[\"html\"],\"type\":\"email\"}},\"type\":\"notification_channels\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/b2a555c9-ac2d-430d-b321-10e4c0201ce3/notification-channels" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"767234b0-0c79-4092-9b44-a8963021795b\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-get_an_on_call_notification_rule_for_a_user_returns_ok_response-1765919784@datadoghq.com\",\"formats\":[\"html\"]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:24 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"767234b0-0c79-4092-9b44-a8963021795b\",\"type\":\"notification_channels\"}}},\"type\":\"notification_rules\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/b2a555c9-ac2d-430d-b321-10e4c0201ce3/notification-rules" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"d07cc90b-4fc5-455f-8f57-45d48a658bc6\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"767234b0-0c79-4092-9b44-a8963021795b\",\"type\":\"notification_channels\"}}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:24 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/b2a555c9-ac2d-430d-b321-10e4c0201ce3/notification-rules/d07cc90b-4fc5-455f-8f57-45d48a658bc6?include=channel" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"d07cc90b-4fc5-455f-8f57-45d48a658bc6\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"767234b0-0c79-4092-9b44-a8963021795b\",\"type\":\"notification_channels\"}}}},\"included\":[{\"id\":\"767234b0-0c79-4092-9b44-a8963021795b\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-get_an_on_call_notification_rule_for_a_user_returns_ok_response-1765919784@datadoghq.com\",\"formats\":[\"html\"]}}}]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:24 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/users/b2a555c9-ac2d-430d-b321-10e4c0201ce3" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:24 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.frozen new file mode 100644 index 000000000..11e9c7c90 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-12-16T21:16:48.356Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.json b/tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.json new file mode 100644 index 000000000..325905954 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/List-On-Call-notification-rules-for-a-user-returns-OK-response.json @@ -0,0 +1,159 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"email\":\"Test-List_On_Call_notification_rules_for_a_user_returns_OK_response-1765919808@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/users" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"users\",\"id\":\"0730802a-ee45-404b-a21d-5908d4c6b3c4\",\"attributes\":{\"name\":null,\"handle\":\"test-list_on_call_notification_rules_for_a_user_returns_ok_response-1765919808@datadoghq.com\",\"created_at\":\"2025-12-16T21:16:48.579239+00:00\",\"modified_at\":\"2025-12-16T21:16:48.579239+00:00\",\"email\":\"test-list_on_call_notification_rules_for_a_user_returns_ok_response-1765919808@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/c2f584fb6a42fbc0f0aad204ea40c0fc?s=48&d=retro\",\"title\":\"user title\",\"verified\":false,\"service_account\":false,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Pending\",\"last_login_time\":null},\"relationships\":{\"roles\":{\"data\":[]},\"org\":{\"data\":{\"type\":\"orgs\",\"id\":\"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:48 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"config\":{\"address\":\"test-list_on_call_notification_rules_for_a_user_returns_ok_response-1765919808@datadoghq.com\",\"formats\":[\"html\"],\"type\":\"email\"}},\"type\":\"notification_channels\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/0730802a-ee45-404b-a21d-5908d4c6b3c4/notification-channels" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"3073e724-15e8-4aec-897a-478e31cca3a8\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-list_on_call_notification_rules_for_a_user_returns_ok_response-1765919808@datadoghq.com\",\"formats\":[\"html\"]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:48 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"3073e724-15e8-4aec-897a-478e31cca3a8\",\"type\":\"notification_channels\"}}},\"type\":\"notification_rules\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/0730802a-ee45-404b-a21d-5908d4c6b3c4/notification-rules" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"d93215d1-85c1-4528-a92f-1b604c1f4b2a\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"3073e724-15e8-4aec-897a-478e31cca3a8\",\"type\":\"notification_channels\"}}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:48 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/0730802a-ee45-404b-a21d-5908d4c6b3c4/notification-rules?include=channel" + }, + "response": { + "body": { + "string": "{\"data\":[{\"id\":\"d93215d1-85c1-4528-a92f-1b604c1f4b2a\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"3073e724-15e8-4aec-897a-478e31cca3a8\",\"type\":\"notification_channels\"}}}}],\"included\":[{\"id\":\"3073e724-15e8-4aec-897a-478e31cca3a8\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-list_on_call_notification_rules_for_a_user_returns_ok_response-1765919808@datadoghq.com\",\"formats\":[\"html\"]}}}]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:48 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/users/0730802a-ee45-404b-a21d-5908d4c6b3c4" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Tue, 16 Dec 2025 21:16:48 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen new file mode 100644 index 000000000..f55a35ff1 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-12-17T01:04:35.713Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.json b/tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.json new file mode 100644 index 000000000..244459fa2 --- /dev/null +++ b/tests/scenarios/cassettes/v2/on-call/Update-an-On-Call-notification-rule-for-a-user-returns-OK-response.json @@ -0,0 +1,165 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"email\":\"Test-Update_an_On_Call_notification_rule_for_a_user_returns_OK_response-1765933475@datadoghq.com\",\"title\":\"user title\"},\"type\":\"users\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/users" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"users\",\"id\":\"4ef9cf45-30a8-4117-9b56-adba96671dff\",\"attributes\":{\"name\":null,\"handle\":\"test-update_an_on_call_notification_rule_for_a_user_returns_ok_response-1765933475@datadoghq.com\",\"created_at\":\"2025-12-17T01:04:36.246950+00:00\",\"modified_at\":\"2025-12-17T01:04:36.246950+00:00\",\"email\":\"test-update_an_on_call_notification_rule_for_a_user_returns_ok_response-1765933475@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/53cbcba1803f4569f759fcc6b3f90bb6?s=48&d=retro\",\"title\":\"user title\",\"verified\":false,\"service_account\":false,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Pending\",\"last_login_time\":null},\"relationships\":{\"roles\":{\"data\":[]},\"org\":{\"data\":{\"type\":\"orgs\",\"id\":\"4dee724d-00cc-11ea-a77b-570c9d03c6c5\"}}}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Wed, 17 Dec 2025 01:04:35 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"config\":{\"address\":\"test-update_an_on_call_notification_rule_for_a_user_returns_ok_response-1765933475@datadoghq.com\",\"formats\":[\"html\"],\"type\":\"email\"}},\"type\":\"notification_channels\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/4ef9cf45-30a8-4117-9b56-adba96671dff/notification-channels" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"7fc326c9-f3dc-4858-80c2-d88c24dcf54b\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-update_an_on_call_notification_rule_for_a_user_returns_ok_response-1765933475@datadoghq.com\",\"formats\":[\"html\"]}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Wed, 17 Dec 2025 01:04:35 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"7fc326c9-f3dc-4858-80c2-d88c24dcf54b\",\"type\":\"notification_channels\"}}},\"type\":\"notification_rules\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/4ef9cf45-30a8-4117-9b56-adba96671dff/notification-rules" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"c7b724f1-eb73-43d4-889f-d8f3e6fbe664\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":0},\"relationships\":{\"channel\":{\"data\":{\"id\":\"7fc326c9-f3dc-4858-80c2-d88c24dcf54b\",\"type\":\"notification_channels\"}}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 201, + "message": "Created" + } + }, + "recorded_at": "Wed, 17 Dec 2025 01:04:35 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":1},\"id\":\"c7b724f1-eb73-43d4-889f-d8f3e6fbe664\",\"relationships\":{\"channel\":{\"data\":{\"id\":\"7fc326c9-f3dc-4858-80c2-d88c24dcf54b\",\"type\":\"notification_channels\"}}},\"type\":\"notification_rules\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "put", + "uri": "https://api.datadoghq.com/api/v2/on-call/users/4ef9cf45-30a8-4117-9b56-adba96671dff/notification-rules/c7b724f1-eb73-43d4-889f-d8f3e6fbe664?include=channel" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"c7b724f1-eb73-43d4-889f-d8f3e6fbe664\",\"type\":\"notification_rules\",\"attributes\":{\"category\":\"high_urgency\",\"delay_minutes\":1},\"relationships\":{\"channel\":{\"data\":{\"id\":\"7fc326c9-f3dc-4858-80c2-d88c24dcf54b\",\"type\":\"notification_channels\"}}}},\"included\":[{\"id\":\"7fc326c9-f3dc-4858-80c2-d88c24dcf54b\",\"type\":\"notification_channels\",\"attributes\":{\"active\":true,\"config\":{\"type\":\"email\",\"address\":\"test-update_an_on_call_notification_rule_for_a_user_returns_ok_response-1765933475@datadoghq.com\",\"formats\":[\"html\"]}}}]}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 17 Dec 2025 01:04:35 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/users/4ef9cf45-30a8-4117-9b56-adba96671dff" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Wed, 17 Dec 2025 01:04:35 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 8cf1925f4..4651a346e 100644 --- a/tests/scenarios/features/v2/given.json +++ b/tests/scenarios/features/v2/given.json @@ -799,6 +799,22 @@ "tag": "On-Call", "operationId": "CreateUserNotificationChannel" }, + { + "parameters": [ + { + "name": "user_id", + "source": "user.data.id" + }, + { + "name": "body", + "value": "{\n \"data\": {\n \"type\": \"notification_rules\",\n \"attributes\": {\n \"delay_minutes\": 0,\n \"category\": \"high_urgency\"\n },\n \"relationships\": {\n \"channel\": {\n \"data\": {\n \"id\": \"{{ oncall_email_notification_channel.data.id }}\",\n \"type\": \"notification_channels\"\n }\n }\n }\n }\n}" + } + ], + "step": "there is a valid \"oncall_email_notification_rule\" in the system", + "key": "oncall_email_notification_rule", + "tag": "On-Call", + "operationId": "CreateUserNotificationRule" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v2/on-call.feature b/tests/scenarios/features/v2/on-call.feature index 9f4750eef..0f4b2a0e3 100644 --- a/tests/scenarios/features/v2/on-call.feature +++ b/tests/scenarios/features/v2/on-call.feature @@ -70,6 +70,32 @@ Feature: On-Call When the request is sent Then the response status is 404 Not Found + @generated @skip @team:DataDog/on-call + Scenario: Create an On-Call notification rule for a user returns "Bad Request" response + Given new "CreateUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"category": "high_urgency", "channel_settings": {"method": "sms", "type": "phone"}, "delay_minutes": 1}, "relationships": {"channel": {"data": {"id": "1562fab3-a8c2-49e2-8f3a-28dcda2405e2", "type": "notification_channels"}}}, "type": "notification_rules"}} + When the request is sent + Then the response status is 400 Bad Request + + @replay-only @team:DataDog/on-call + Scenario: Create an On-Call notification rule for a user returns "Created" response + Given new "CreateUserNotificationRule" request + And there is a valid "user" in the system + And request contains "user_id" parameter from "user.data.id" + And there is a valid "oncall_email_notification_channel" in the system + And body with value {"data": {"attributes": {"category": "high_urgency", "delay_minutes": 0}, "relationships": {"channel": {"data": {"id": "{{ oncall_email_notification_channel.data.id }}", "type": "notification_channels"}}}, "type": "notification_rules"}} + When the request is sent + Then the response status is 201 Created + + @generated @skip @team:DataDog/on-call + Scenario: Create an On-Call notification rule for a user returns "Not Found" response + Given new "CreateUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"category": "high_urgency", "channel_settings": {"method": "sms", "type": "phone"}, "delay_minutes": 1}, "relationships": {"channel": {"data": {"id": "1562fab3-a8c2-49e2-8f3a-28dcda2405e2", "type": "notification_channels"}}}, "type": "notification_rules"}} + When the request is sent + Then the response status is 404 Not Found + @team:DataDog/on-call Scenario: Delete On-Call escalation policy returns "No Content" response Given new "DeleteOnCallEscalationPolicy" request @@ -130,6 +156,33 @@ Feature: On-Call When the request is sent Then the response status is 404 Not Found + @generated @skip @team:DataDog/on-call + Scenario: Delete an On-Call notification rule for a user returns "Bad Request" response + Given new "DeleteUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @replay-only @team:DataDog/on-call + Scenario: Delete an On-Call notification rule for a user returns "No Content" response + Given new "DeleteUserNotificationRule" request + And there is a valid "user" in the system + And there is a valid "oncall_email_notification_channel" in the system + And there is a valid "oncall_email_notification_rule" in the system + And request contains "user_id" parameter from "user.data.id" + And request contains "rule_id" parameter from "oncall_email_notification_rule.data.id" + When the request is sent + Then the response status is 204 No Content + + @generated @skip @team:DataDog/on-call + Scenario: Delete an On-Call notification rule for a user returns "Not Found" response + Given new "DeleteUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + @generated @skip @team:DataDog/on-call Scenario: Get On-Call escalation policy returns "Bad Request" response Given new "GetOnCallEscalationPolicy" request @@ -207,6 +260,36 @@ Feature: On-Call And the response "data.attributes.config.type" is equal to "email" And the response "data.attributes.config.address" is equal to "{{ user.data.attributes.email }}" + @generated @skip @team:DataDog/on-call + Scenario: Get an On-Call notification rule for a user returns "Bad Request" response + Given new "GetUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/on-call + Scenario: Get an On-Call notification rule for a user returns "Not Found" response + Given new "GetUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And request contains "rule_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @replay-only @team:DataDog/on-call + Scenario: Get an On-Call notification rule for a user returns "OK" response + Given new "GetUserNotificationRule" request + And there is a valid "user" in the system + And there is a valid "oncall_email_notification_channel" in the system + And there is a valid "oncall_email_notification_rule" in the system + And request contains "user_id" parameter from "user.data.id" + And request contains "rule_id" parameter from "oncall_email_notification_rule.data.id" + And request contains "include" parameter with value "channel" + When the request is sent + Then the response status is 200 OK + And the response "data.attributes.category" is equal to "high_urgency" + And the response "included" has length 1 + @generated @skip @team:DataDog/on-call Scenario: Get scheduled on-call user returns "Bad Request" response Given new "GetScheduleOnCallUser" request @@ -283,6 +366,33 @@ Feature: On-Call And the response "data[0].attributes.config.type" is equal to "email" And the response "data[0].attributes.config.address" is equal to "{{ user.data.attributes.email }}" + @generated @skip @team:DataDog/on-call + Scenario: List On-Call notification rules for a user returns "Bad Request" response + Given new "ListUserNotificationRules" request + And request contains "user_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/on-call + Scenario: List On-Call notification rules for a user returns "Not Found" response + Given new "ListUserNotificationRules" request + And request contains "user_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @replay-only @team:DataDog/on-call + Scenario: List On-Call notification rules for a user returns "OK" response + Given new "ListUserNotificationRules" request + And there is a valid "user" in the system + And there is a valid "oncall_email_notification_channel" in the system + And there is a valid "oncall_email_notification_rule" in the system + And request contains "user_id" parameter from "user.data.id" + And request contains "include" parameter with value "channel" + When the request is sent + Then the response status is 200 OK + And the response "data" has length 1 + And the response "included" has length 1 + @skip-python @team:DataDog/on-call Scenario: Set On-Call team routing rules returns "OK" response Given new "SetOnCallTeamRoutingRules" request @@ -350,3 +460,36 @@ Feature: On-Call And body with value {"data": { "id": "{{ schedule.data.id }}", "attributes": {"layers": [{"id": "{{ schedule.data.relationships.layers.data[0].id }}" , "effective_date": "{{ timeISO('now - 10d') }}", "end_date": "{{ timeISO('now + 10d') }}", "interval": {"seconds": 3600}, "members": [{"user": {"id": "{{user.data.id}}"}}], "name": "Layer 1", "restrictions": [{"end_day": "friday", "end_time": "17:00:00", "start_day": "monday", "start_time": "09:00:00"}], "rotation_start": "{{ timeISO('now - 5d') }}"}], "name": "{{ unique }}", "time_zone": "America/New_York"}, "relationships": {"teams": {"data": [{"id": "{{dd_team.data.id}}", "type": "teams"}]}}, "type": "schedules"}} When the request is sent Then the response status is 200 OK + + @generated @skip @team:DataDog/on-call + Scenario: Update an On-Call notification rule for a user returns "Bad Request" response + Given new "UpdateUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And request contains "rule_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"category": "high_urgency", "channel_settings": {"method": "sms", "type": "phone"}, "delay_minutes": 1}, "id": "2462ace1-49e2-aab1-xc4f-29cc4ae1105n7", "relationships": {"channel": {"data": {"id": "1562fab3-a8c2-49e2-8f3a-28dcda2405e2", "type": "notification_channels"}}}, "type": "notification_rules"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/on-call + Scenario: Update an On-Call notification rule for a user returns "Not Found" response + Given new "UpdateUserNotificationRule" request + And request contains "user_id" parameter from "REPLACE.ME" + And request contains "rule_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"category": "high_urgency", "channel_settings": {"method": "sms", "type": "phone"}, "delay_minutes": 1}, "id": "2462ace1-49e2-aab1-xc4f-29cc4ae1105n7", "relationships": {"channel": {"data": {"id": "1562fab3-a8c2-49e2-8f3a-28dcda2405e2", "type": "notification_channels"}}}, "type": "notification_rules"}} + When the request is sent + Then the response status is 404 Not Found + + @replay-only @team:DataDog/on-call + Scenario: Update an On-Call notification rule for a user returns "OK" response + Given new "UpdateUserNotificationRule" request + And there is a valid "user" in the system + And there is a valid "oncall_email_notification_channel" in the system + And there is a valid "oncall_email_notification_rule" in the system + And request contains "user_id" parameter from "user.data.id" + And request contains "rule_id" parameter from "oncall_email_notification_rule.data.id" + And body with value {"data": {"attributes": {"category": "high_urgency", "delay_minutes": 1}, "id": "{{ oncall_email_notification_rule.data.id }}", "relationships": {"channel": {"data": {"id": "{{ oncall_email_notification_channel.data.id }}", "type": "notification_channels"}}}, "type": "notification_rules"}} + And request contains "include" parameter with value "channel" + When the request is sent + Then the response status is 200 OK + And the response "included" has length 1 + And the response "data.attributes.delay_minutes" is equal to 1 diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index e0f0b98d0..d398c05fc 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2964,6 +2964,36 @@ "type": "safe" } }, + "ListUserNotificationRules": { + "tag": "On-Call", + "undo": { + "type": "safe" + } + }, + "CreateUserNotificationRule": { + "tag": "On-Call", + "undo": { + "type": "safe" + } + }, + "DeleteUserNotificationRule": { + "tag": "On-Call", + "undo": { + "type": "idempotent" + } + }, + "GetUserNotificationRule": { + "tag": "On-Call", + "undo": { + "type": "safe" + } + }, + "UpdateUserNotificationRule": { + "tag": "On-Call", + "undo": { + "type": "safe" + } + }, "ListOrgConfigs": { "tag": "Organizations", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 0c30294c8..2e7783c27 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -3785,6 +3785,26 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.GetUserNotificationChannel".into(), test_v2_get_user_notification_channel, ); + world.function_mappings.insert( + "v2.ListUserNotificationRules".into(), + test_v2_list_user_notification_rules, + ); + world.function_mappings.insert( + "v2.CreateUserNotificationRule".into(), + test_v2_create_user_notification_rule, + ); + world.function_mappings.insert( + "v2.DeleteUserNotificationRule".into(), + test_v2_delete_user_notification_rule, + ); + world.function_mappings.insert( + "v2.GetUserNotificationRule".into(), + test_v2_get_user_notification_rule, + ); + world.function_mappings.insert( + "v2.UpdateUserNotificationRule".into(), + test_v2_update_user_notification_rule, + ); world .function_mappings .insert("v2.CreateOnCallPage".into(), test_v2_create_on_call_page); @@ -28735,6 +28755,171 @@ fn test_v2_get_user_notification_channel( world.response.code = response.status.as_u16(); } +fn test_v2_list_user_notification_rules( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_on_call + .as_ref() + .expect("api instance not found"); + let user_id = serde_json::from_value(_parameters.get("user_id").unwrap().clone()).unwrap(); + let include = _parameters + .get("include") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_on_call::ListUserNotificationRulesOptionalParams::default(); + params.include = include; + let response = match block_on(api.list_user_notification_rules_with_http_info(user_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_create_user_notification_rule( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_on_call + .as_ref() + .expect("api instance not found"); + let user_id = serde_json::from_value(_parameters.get("user_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.create_user_notification_rule_with_http_info(user_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_delete_user_notification_rule( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_on_call + .as_ref() + .expect("api instance not found"); + let user_id = serde_json::from_value(_parameters.get("user_id").unwrap().clone()).unwrap(); + let rule_id = serde_json::from_value(_parameters.get("rule_id").unwrap().clone()).unwrap(); + let response = + match block_on(api.delete_user_notification_rule_with_http_info(user_id, rule_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_user_notification_rule( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_on_call + .as_ref() + .expect("api instance not found"); + let user_id = serde_json::from_value(_parameters.get("user_id").unwrap().clone()).unwrap(); + let rule_id = serde_json::from_value(_parameters.get("rule_id").unwrap().clone()).unwrap(); + let include = _parameters + .get("include") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_on_call::GetUserNotificationRuleOptionalParams::default(); + params.include = include; + let response = + match block_on(api.get_user_notification_rule_with_http_info(user_id, rule_id, params)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_update_user_notification_rule( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_on_call + .as_ref() + .expect("api instance not found"); + let user_id = serde_json::from_value(_parameters.get("user_id").unwrap().clone()).unwrap(); + let rule_id = serde_json::from_value(_parameters.get("rule_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let include = _parameters + .get("include") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV2::api_on_call::UpdateUserNotificationRuleOptionalParams::default(); + params.include = include; + let response = match block_on( + api.update_user_notification_rule_with_http_info(user_id, rule_id, body, 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_on_call_page(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances