From 3f96653f0a55ad83cb9c9a38758a526a2970e577 Mon Sep 17 00:00:00 2001 From: Or Novogroder <108669655+OrNovo@users.noreply.github.com> Date: Wed, 1 Nov 2023 10:27:45 +0200 Subject: [PATCH] fixing conversion problems (#168) --- coralogix/resource_coralogix_alert.go | 12 ++++++------ coralogix/utils.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/coralogix/resource_coralogix_alert.go b/coralogix/resource_coralogix_alert.go index b3f00d82..6084b2cb 100644 --- a/coralogix/resource_coralogix_alert.go +++ b/coralogix/resource_coralogix_alert.go @@ -2436,9 +2436,9 @@ func expandNotificationSubgroup(v interface{}) (*alerts.AlertNotification, error var isWebhookIdDefined bool if webhookID, ok := m["integration_id"].(string); ok && webhookID != "" { isWebhookIdDefined = true - id, _ := strconv.Atoi(webhookID) + id := parseNumUint32(webhookID) notification.IntegrationType = &alerts.AlertNotification_IntegrationId{ - IntegrationId: wrapperspb.UInt32(uint32(id)), + IntegrationId: wrapperspb.UInt32(id), } } @@ -3429,10 +3429,10 @@ func expandUniqueValueTimeFrame(s string) alerts.Timeframe { func expandTimeInDay(v interface{}) *alerts.Time { timeArr := strings.Split(v.(string), ":") - hours, _ := strconv.Atoi(timeArr[0]) - minutes, _ := strconv.Atoi(timeArr[1]) + hours := parseNumInt32(timeArr[0]) + minutes := parseNumInt32(timeArr[1]) return &alerts.Time{ - Hours: int32(hours), - Minutes: int32(minutes), + Hours: hours, + Minutes: minutes, } } diff --git a/coralogix/utils.go b/coralogix/utils.go index 47b1e9c8..38759c9a 100644 --- a/coralogix/utils.go +++ b/coralogix/utils.go @@ -730,3 +730,19 @@ func GetKeys[K, V comparable](m map[K]V) []K { } return result } + +func parseNumInt32(desired string) int32 { + parsed, err := strconv.ParseInt(desired, 10, 32) + if err != nil { + return 0 + } + return int32(parsed) +} + +func parseNumUint32(desired string) uint32 { + parsed, err := strconv.ParseUint(desired, 10, 32) + if err != nil { + return 0 + } + return uint32(parsed) +}