From e069bbfcbe0d74e4a8b19d079a1bef35ca522fd2 Mon Sep 17 00:00:00 2001 From: Julianna Green Date: Mon, 28 Oct 2024 14:22:07 -0700 Subject: [PATCH] AA-1837 add only_invocable_on_unresolved_incidents option to automation actions --- pagerduty/automation_actions_action.go | 29 +++++++------- pagerduty/automation_actions_action_test.go | 44 ++++++++++++--------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/pagerduty/automation_actions_action.go b/pagerduty/automation_actions_action.go index a2eb1ec..3b5e06b 100644 --- a/pagerduty/automation_actions_action.go +++ b/pagerduty/automation_actions_action.go @@ -7,20 +7,21 @@ import "fmt" type AutomationActionsActionService service type AutomationActionsAction struct { - ID string `json:"id"` - Name string `json:"name"` - Description *string `json:"description,omitempty"` - ActionType string `json:"action_type"` - RunnerID *string `json:"runner,omitempty"` - ActionDataReference AutomationActionsActionDataReference `json:"action_data_reference"` - Services []*ServiceReference `json:"services,omitempty"` - Teams []*TeamReference `json:"teams,omitempty"` - Privileges *AutomationActionsPrivileges `json:"privileges,omitempty"` - Type *string `json:"type,omitempty"` - ActionClassification *string `json:"action_classification,omitempty"` - RunnerType *string `json:"runner_type,omitempty"` - CreationTime *string `json:"creation_time,omitempty"` - ModifyTime *string `json:"modify_time,omitempty"` + ID string `json:"id"` + Name string `json:"name"` + Description *string `json:"description,omitempty"` + ActionType string `json:"action_type"` + RunnerID *string `json:"runner,omitempty"` + ActionDataReference AutomationActionsActionDataReference `json:"action_data_reference"` + Services []*ServiceReference `json:"services,omitempty"` + Teams []*TeamReference `json:"teams,omitempty"` + Privileges *AutomationActionsPrivileges `json:"privileges,omitempty"` + Type *string `json:"type,omitempty"` + ActionClassification *string `json:"action_classification,omitempty"` + RunnerType *string `json:"runner_type,omitempty"` + CreationTime *string `json:"creation_time,omitempty"` + ModifyTime *string `json:"modify_time,omitempty"` + OnlyInvocableOnUnresolvedIncidents bool `json:"only_invocable_on_unresolved_incidents,omitempty"` } type AutomationActionsActionDataReference struct { diff --git a/pagerduty/automation_actions_action_test.go b/pagerduty/automation_actions_action_test.go index 74707ff..e33bb86 100644 --- a/pagerduty/automation_actions_action_test.go +++ b/pagerduty/automation_actions_action_test.go @@ -93,17 +93,19 @@ func TestAutomationActionsActionTypeProcessAutomationCreate(t *testing.T) { adf_arg := "-arg 123" adf_node_filter := "tags: production" job_id := "1519578e-a22a-4340-b58f-08194691e10b" + only_invocable_on_unresolved_incidents := true adf := AutomationActionsActionDataReference{ ProcessAutomationJobId: &job_id, ProcessAutomationJobArguments: &adf_arg, ProcessAutomationNodeFilter: &adf_node_filter, } input := &AutomationActionsAction{ - Name: "Action created by TF", - Description: &description, - ActionType: "process_automation", - RunnerID: &runner_id, - ActionDataReference: adf, + Name: "Action created by TF", + Description: &description, + ActionType: "process_automation", + RunnerID: &runner_id, + ActionDataReference: adf, + OnlyInvocableOnUnresolvedIncidents &only_invocable_on_unresolved_incidents } mux.HandleFunc("/automation_actions/actions", func(w http.ResponseWriter, r *http.Request) { @@ -113,7 +115,7 @@ func TestAutomationActionsActionTypeProcessAutomationCreate(t *testing.T) { if !reflect.DeepEqual(v.Action, input) { t.Errorf("Request body = %+v, want %+v", v.Action, input) } - w.Write([]byte(`{"action":{"action_data_reference":{"process_automation_job_id":"1519578e-a22a-4340-b58f-08194691e10b","process_automation_job_arguments":"-arg 123", "process_automation_node_filter":"tags: production"},"action_type":"process_automation","creation_time":"2022-12-12T18:51:42.048162Z","description":"Description of Action created by TF","id":"01DF4OBNYKW84FS9CCYVYS1MOS","last_run":"2022-12-12T18:52:11.937747Z","last_run_by":{"id":"PINL781","type":"user_reference"},"modify_time":"2022-12-12T18:51:42.048162Z","name":"Action created by TF","privileges":{"permissions":["read"]},"runner":"01DF4O9T1MDPYOUT7SUX9EXZ4R","runner_type":"runbook","services":[{"id":"PQWQ0U6","type":"service_reference"}],"teams":[{"id":"PZ31N6S","type":"team_reference"}],"type":"action"}}`)) + w.Write([]byte(`{"action":{"only_invocable_on_unresolved_incidents": true,"action_data_reference":{"process_automation_job_id":"1519578e-a22a-4340-b58f-08194691e10b","process_automation_job_arguments":"-arg 123", "process_automation_node_filter":"tags: production"},"action_type":"process_automation","creation_time":"2022-12-12T18:51:42.048162Z","description":"Description of Action created by TF","id":"01DF4OBNYKW84FS9CCYVYS1MOS","last_run":"2022-12-12T18:52:11.937747Z","last_run_by":{"id":"PINL781","type":"user_reference"},"modify_time":"2022-12-12T18:51:42.048162Z","name":"Action created by TF","privileges":{"permissions":["read"]},"runner":"01DF4O9T1MDPYOUT7SUX9EXZ4R","runner_type":"runbook","services":[{"id":"PQWQ0U6","type":"service_reference"}],"teams":[{"id":"PZ31N6S","type":"team_reference"}],"type":"action"}}`)) }) resp, _, err := client.AutomationActionsAction.Create(input) @@ -167,18 +169,20 @@ func TestAutomationActionsActionUpdate(t *testing.T) { runner_id := "01DF4O9T1MDPYOUT7SUX9EXZ4R" adf_arg := "-arg 123" adf_node_filter := "tags: production" - job_id := "1519578e-a22a-4340-b58f-08194691e10b" + job_id := "1519578e-a22a-4340-b58f-08194691e10b", + only_invocable_on_unresolved_incidents := true adf := AutomationActionsActionDataReference{ ProcessAutomationJobId: &job_id, ProcessAutomationJobArguments: &adf_arg, ProcessAutomationNodeFilter: &adf_node_filter, } input := &AutomationActionsAction{ - Name: "Action created by TF", - Description: &description, - ActionType: "process_automation", - RunnerID: &runner_id, - ActionDataReference: adf, + Name: "Action created by TF", + Description: &description, + ActionType: "process_automation", + RunnerID: &runner_id, + ActionDataReference: adf, + OnlyInvocableOnUnresolvedIncidents &only_invocable_on_unresolved_incidents } var id = "01DF4OBNYKW84FS9CCYVYS1MOS" @@ -191,7 +195,7 @@ func TestAutomationActionsActionUpdate(t *testing.T) { if !reflect.DeepEqual(v.Action, input) { t.Errorf("Request body = %+v, want %+v", v.Action, input) } - w.Write([]byte(`{"action":{"action_data_reference":{"process_automation_job_id":"1519578e-a22a-4340-b58f-08194691e10b","process_automation_job_arguments":"-arg 123", "process_automation_node_filter":"tags: production"},"action_type":"process_automation","creation_time":"2022-12-12T18:51:42.048162Z","description":"Description of Action created by TF","id":"01DF4OBNYKW84FS9CCYVYS1MOS","last_run":"2022-12-12T18:52:11.937747Z","last_run_by":{"id":"PINL781","type":"user_reference"},"modify_time":"2022-12-12T18:51:42.048162Z","name":"Action created by TF","privileges":{"permissions":["read"]},"runner":"01DF4O9T1MDPYOUT7SUX9EXZ4R","runner_type":"runbook","services":[{"id":"PQWQ0U6","type":"service_reference"}],"teams":[{"id":"PZ31N6S","type":"team_reference"}],"type":"action"}}`)) + w.Write([]byte(`{"action":{"only_invocable_on_unresolved_incidents": true,"action_data_reference":{"process_automation_job_id":"1519578e-a22a-4340-b58f-08194691e10b","process_automation_job_arguments":"-arg 123", "process_automation_node_filter":"tags: production"},"action_type":"process_automation","creation_time":"2022-12-12T18:51:42.048162Z","description":"Description of Action created by TF","id":"01DF4OBNYKW84FS9CCYVYS1MOS","last_run":"2022-12-12T18:52:11.937747Z","last_run_by":{"id":"PINL781","type":"user_reference"},"modify_time":"2022-12-12T18:51:42.048162Z","name":"Action created by TF","privileges":{"permissions":["read"]},"runner":"01DF4O9T1MDPYOUT7SUX9EXZ4R","runner_type":"runbook","services":[{"id":"PQWQ0U6","type":"service_reference"}],"teams":[{"id":"PZ31N6S","type":"team_reference"}],"type":"action"}}`)) }) resp, _, err := client.AutomationActionsAction.Update(id, input) @@ -258,17 +262,19 @@ func TestAutomationActionsActionTypeScriptCreate(t *testing.T) { description := "Description of Action created by TF" runner_id := "01DF4O9T1MDPYOUT7SUX9EXZ4R" invocation_command := "/bin/bash" - script_data := "java --version" + script_data := "java --version", + only_invocable_on_unresolved_incidents := true adf := AutomationActionsActionDataReference{ Script: &script_data, InvocationCommand: &invocation_command, } input := &AutomationActionsAction{ - Name: "Action created by TF", - Description: &description, - ActionType: "script", - RunnerID: &runner_id, - ActionDataReference: adf, + Name: "Action created by TF", + Description: &description, + ActionType: "script", + RunnerID: &runner_id, + ActionDataReference: adf, + OnlyInvocableOnUnresolvedIncidents &only_invocable_on_unresolved_incidents } mux.HandleFunc("/automation_actions/actions", func(w http.ResponseWriter, r *http.Request) {