Skip to content

Commit

Permalink
Merge pull request #854 from imjaroiswebdev/issue-844-repatch
Browse files Browse the repository at this point in the history
Handle nil pointer conversions across `pagerduty_service` implementation
  • Loading branch information
imjaroiswebdev authored Apr 12, 2024
2 parents 97daab9 + 9243905 commit 396c86e
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,17 @@ func expandAlertGroupingParameters(v interface{}) *pagerduty.AlertGroupingParame
}

func expandAutoPauseNotificationsParameters(v interface{}) *pagerduty.AutoPauseNotificationsParameters {
riur := v.([]interface{})[0].(map[string]interface{})
autoPauseNotificationsParameters := &pagerduty.AutoPauseNotificationsParameters{
Enabled: riur["enabled"].(bool),
autoPauseNotificationsParameters := &pagerduty.AutoPauseNotificationsParameters{}
riur := make(map[string]interface{})

data, ok := v.([]interface{})
if ok && len(data) > 0 && !isNilFunc(data[0]) {
riur = data[0].(map[string]interface{})
} else {
return autoPauseNotificationsParameters
}

autoPauseNotificationsParameters.Enabled = riur["enabled"].(bool)
if autoPauseNotificationsParameters.Enabled {
timeout := riur["timeout"].(int)
autoPauseNotificationsParameters.Timeout = &timeout
Expand Down Expand Up @@ -727,11 +734,18 @@ func flattenAutoPauseNotificationsParameters(v *pagerduty.AutoPauseNotifications
}

func expandIncidentUrgencyRule(v interface{}) *pagerduty.IncidentUrgencyRule {
riur := v.([]interface{})[0].(map[string]interface{})
incidentUrgencyRule := &pagerduty.IncidentUrgencyRule{
Type: riur["type"].(string),
incidentUrgencyRule := &pagerduty.IncidentUrgencyRule{}
riur := make(map[string]interface{})

data, ok := v.([]interface{})
if ok && len(data) > 0 && !isNilFunc(data[0]) {
riur = data[0].(map[string]interface{})
} else {
return incidentUrgencyRule
}

incidentUrgencyRule.Type = riur["type"].(string)

if val, ok := riur["urgency"]; ok {
incidentUrgencyRule.Urgency = val.(string)
}
Expand Down Expand Up @@ -801,7 +815,14 @@ func flattenIncidentUrgencyType(v *pagerduty.IncidentUrgencyType) []interface{}
func expandSupportHours(v interface{}) *pagerduty.SupportHours {
supportHours := &pagerduty.SupportHours{}

rsh := v.([]interface{})[0].(map[string]interface{})
rsh := make(map[string]interface{})

data, ok := v.([]interface{})
if ok && len(data) > 0 && !isNilFunc(data[0]) {
rsh = data[0].(map[string]interface{})
} else {
return supportHours
}

if v, ok := rsh["type"]; ok {
supportHours.Type = v.(string)
Expand Down Expand Up @@ -892,7 +913,15 @@ func flattenScheduledActions(v []*pagerduty.ScheduledAction) []interface{} {
}

func expandScheduledActionAt(v interface{}) *pagerduty.At {
rat := v.([]interface{})[0].(map[string]interface{})
rat := make(map[string]interface{})

data, ok := v.([]interface{})
if ok && len(data) > 0 && !isNilFunc(data[0]) {
rat = data[0].(map[string]interface{})
} else {
return nil
}

return &pagerduty.At{
Type: rat["type"].(string),
Name: rat["name"].(string),
Expand Down

0 comments on commit 396c86e

Please sign in to comment.