Skip to content

Commit

Permalink
removed sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
swbradshaw authored and imjaroiswebdev committed Feb 26, 2024
1 parent e0afdad commit 737736f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 93 deletions.
37 changes: 0 additions & 37 deletions pagerduty/event_orchestration_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ func (s *EventOrchestrationPathService) Update(id string, pathType string, orche
func (s *EventOrchestrationPathService) UpdateContext(ctx context.Context, id string, pathType string, orchestrationPath *EventOrchestrationPath) (*EventOrchestrationPathPayload, *Response, error) {
u := orchestrationPathUrlBuilder(id, pathType)
v := new(EventOrchestrationPathPayload)
sanitizeOrchestrationPath(orchestrationPath)
p := EventOrchestrationPathPayload{OrchestrationPath: orchestrationPath}

resp, err := s.client.newRequestDoContext(ctx, "PUT", u, nil, p, &v)
Expand All @@ -187,42 +186,6 @@ func (s *EventOrchestrationPathService) UpdateContext(ctx context.Context, id st
return v, resp, nil
}

// Sanitize the conditions and actions to ensure that the arrays are not null
func sanitizeOrchestrationPath(servicePath *EventOrchestrationPath) {
for _, set := range servicePath.Sets {
for _, rule := range set.Rules {
if rule.Conditions == nil {
rule.Conditions = []*EventOrchestrationPathRuleCondition{}
}
if rule.Actions != nil {
sanitizeActions(rule.Actions)
}
}
}
if (servicePath.CatchAll != nil) {
sanitizeActions(servicePath.CatchAll.Actions)
}
}

// Sanitize the actions to ensure that the arrays are not null
func sanitizeActions(actions *EventOrchestrationPathRuleActions) {
if actions.IncidentCustomFieldUpdates == nil {
actions.IncidentCustomFieldUpdates = []*EventOrchestrationPathIncidentCustomFieldUpdate{}
}
if actions.AutomationActions == nil {
actions.AutomationActions = []*EventOrchestrationPathAutomationAction{}
}
if actions.PagerdutyAutomationActions == nil {
actions.PagerdutyAutomationActions = []*EventOrchestrationPathPagerdutyAutomationAction{}
}
if actions.Variables == nil {
actions.Variables = []*EventOrchestrationPathActionVariables{}
}
if actions.Extractions == nil {
actions.Extractions = []*EventOrchestrationPathActionExtractions{}
}
}

// UpdateServiceActiveStatus for EventOrchestrationPath
func (s *EventOrchestrationPathService) UpdateServiceActiveStatusContext(ctx context.Context, id string, isActive bool) (*EventOrchestrationPathServiceActiveStatus, *Response, error) {
u := fmt.Sprintf("%s/services/%s/active", eventOrchestrationBaseUrl, id)
Expand Down
56 changes: 0 additions & 56 deletions pagerduty/event_orchestration_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,55 +250,6 @@ func TestEventOrchestrationPathGetServiceActiveStatus(t *testing.T) {
}
}

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

input := &EventOrchestrationPath{
Sets: []*EventOrchestrationPathSet{
{
ID: "start",
Rules: []*EventOrchestrationPathRule{
{
Actions: &EventOrchestrationPathRuleActions{},
},
},
},
},
}

var url = fmt.Sprintf("%s/E-ORC-1/global", eventOrchestrationBaseUrl)

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

// empty arrays are null by default
actionJson, _ := json.Marshal(input.Sets[0].Rules[0].Actions.PagerdutyAutomationActions)
want := "null"
if !reflect.DeepEqual(string(actionJson), want) {
t.Errorf("returned \n\n%#v want \n\n%#v", string(actionJson), want)
}
reflect.DeepEqual(actionJson, nil)
_, _, err := client.EventOrchestrationPaths.Update("E-ORC-1", PathTypeGlobal, input)
if err != nil {
t.Fatal(err)
}
// after sanitize, empty arrays are no longer null
actionJson, _ = json.Marshal(input.Sets[0].Rules[0].Actions.PagerdutyAutomationActions)
want = "[]"
if !reflect.DeepEqual(string(actionJson), want) {
t.Errorf("returned \n\n%#v want \n\n%#v", string(actionJson), want)
}

}

func TestEventOrchestrationPathGlobalUpdate(t *testing.T) {
setup()
defer teardown()
Expand Down Expand Up @@ -424,10 +375,6 @@ func TestEventOrchestrationPathGlobalUpdate(t *testing.T) {
if !reflect.DeepEqual(v.OrchestrationPath, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
actionJson, _ := json.Marshal(input.Sets[0].Rules[0].Actions.IncidentCustomFieldUpdates)
if !reflect.DeepEqual(string(actionJson), "[]") {
t.Errorf("empty action array should be []")
}
w.Write([]byte(`{
"orchestration_path": {
"catch_all": {"actions": {"suppress": true}},
Expand Down Expand Up @@ -542,9 +489,6 @@ func TestEventOrchestrationPathGlobalUpdate(t *testing.T) {
},
}

// Before comparison, we sanitize the response to make it match the already sanitized request
sanitizeOrchestrationPath(resp.OrchestrationPath)

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

0 comments on commit 737736f

Please sign in to comment.