Skip to content

Commit

Permalink
Configure event_orchestration_service status
Browse files Browse the repository at this point in the history
Add utilities methods to get the current status of activation of a
event_orchestration_service and to update it

fixes heimweh#121
  • Loading branch information
stefanoboriero committed Feb 5, 2023
1 parent 310c225 commit 1213513
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pagerduty/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ type Service struct {
Type string `json:"type,omitempty"`
}

type EventOrchestrationServiceStatusPayload struct {
Active bool `json:"active"`
}

// ServicePayload represents a service.
type ServicePayload struct {
Service *Service `json:"service,omitempty"`
Expand Down Expand Up @@ -395,3 +399,28 @@ func (s *ServicesService) DeleteEventRule(serviceID, ruleID string) (*Response,
u := fmt.Sprintf("/services/%s/rules/%s", serviceID, ruleID)
return s.client.newRequestDo("DELETE", u, nil, nil, nil)
}

func (s *ServicesService) GetEventOrchestrationServiceStatus(serviceID string) (*EventOrchestrationServiceStatusPayload, *Response, error) {
u := fmt.Sprintf("/event_orchestrations/services/%s/active", serviceID)
v := new(EventOrchestrationServiceStatusPayload)

resp, err := s.client.newRequestDo("GET", u, nil, nil, &v)
if err != nil {
return nil, nil, err
}

return v, resp, nil
}

func (s *ServicesService) UpdateEventOrchestrationServiceStatus(serviceID string, active bool) (*EventOrchestrationServiceStatusPayload, *Response, error) {
u := fmt.Sprintf("/event_orchestrations/services/%s/active", serviceID)
v := new(EventOrchestrationServiceStatusPayload)
p := EventOrchestrationServiceStatusPayload{Active: active}

resp, err := s.client.newRequestDo("PUT", u, nil, p, &v)
if err != nil {
return nil, nil, err
}

return v, resp, nil
}
54 changes: 54 additions & 0 deletions pagerduty/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,57 @@ func TestServicesDeleteEventRule(t *testing.T) {
t.Fatal(err)
}
}

func TestEventOrchestrationServiceStatusGet(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/event_orchestrations/services/1/active", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.Write([]byte(`{"active": true}`))
})

resp, _, err := client.Services.GetEventOrchestrationServiceStatus("1")
if err != nil {
t.Fatal(err)
}

want := &EventOrchestrationServiceStatusPayload{
Active: true,
}

if !reflect.DeepEqual(resp, want) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want)
}
}

func TestEventOrchestrationServiceStatusUpdate(t *testing.T) {
setup()
defer teardown()

input := true


mux.HandleFunc("/event_orchestrations/services/1/active", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
v := true
json.NewDecoder(r.Body).Decode(v)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.Write([]byte(`{"active": true}`))
})

resp, _, err := client.Services.UpdateEventOrchestrationServiceStatus("1", input)
if err != nil {
t.Fatal(err)
}

want := &EventOrchestrationServiceStatusPayload{
Active: true,
}

if !reflect.DeepEqual(resp, want) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want)
}
}

0 comments on commit 1213513

Please sign in to comment.