From ef4b6a27ffe33eaa697497360d7c45e6fcb3f564 Mon Sep 17 00:00:00 2001 From: kenxu95 Date: Tue, 9 May 2023 14:21:23 -0700 Subject: [PATCH] done --- src/golang/lib/lib_utils/notification.go | 33 ++++++++++++++++++++++++ src/golang/lib/lib_utils/utils.go | 27 ------------------- 2 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 src/golang/lib/lib_utils/notification.go diff --git a/src/golang/lib/lib_utils/notification.go b/src/golang/lib/lib_utils/notification.go new file mode 100644 index 000000000..5c2eb36e3 --- /dev/null +++ b/src/golang/lib/lib_utils/notification.go @@ -0,0 +1,33 @@ +package lib_utils + +import ( + "github.com/aqueducthq/aqueduct/lib/errors" + "github.com/aqueducthq/aqueduct/lib/models" + "github.com/aqueducthq/aqueduct/lib/models/shared" +) + +const ( + notificationEnabledKey = "enabled" + notificationLevelKey = "level" +) + +// Returning a nil level means that `disabled` == true. +func ExtractNotificationLevel(integrationObject *models.Integration) (*shared.NotificationLevel, error) { + enabledStr, ok := integrationObject.Config[notificationEnabledKey] + if !ok { + return nil, errors.Newf("Notification %s is missing 'enabled' key.", integrationObject.Name) + } + if enabledStr == "false" { + return nil, nil + } + + levelStr, ok := integrationObject.Config[notificationLevelKey] + if !ok { + return nil, errors.Newf("Notification %s is enabled but missing 'level' key.", integrationObject.Name) + } + level, err := shared.StrToNotificationLevel(levelStr) + if err != nil { + return nil, err + } + return &level, nil +} diff --git a/src/golang/lib/lib_utils/utils.go b/src/golang/lib/lib_utils/utils.go index eadabcf6c..bd70fae12 100644 --- a/src/golang/lib/lib_utils/utils.go +++ b/src/golang/lib/lib_utils/utils.go @@ -11,7 +11,6 @@ import ( "regexp" "strings" - "github.com/aqueducthq/aqueduct/lib/models" "github.com/aqueducthq/aqueduct/lib/models/shared" "github.com/aqueducthq/aqueduct/lib/workflow/operator/connector/auth" "github.com/dropbox/godropbox/errors" @@ -214,32 +213,6 @@ func ParseEmailConfig(conf auth.Config) (*shared.EmailConfig, error) { }, nil } -const ( - notificationEnabledKey = "enabled" - notificationLevelKey = "level" -) - -// Returning a nil level means that `disabled` == true. -func ExtractNotificationLevel(integrationObject *models.Integration) (*shared.NotificationLevel, error) { - enabledStr, ok := integrationObject.Config[notificationEnabledKey] - if !ok { - return nil, errors.Newf("Notification %s is missing 'enabled' key.", integrationObject.Name) - } - if enabledStr == "false" { - return nil, nil - } - - levelStr, ok := integrationObject.Config[notificationLevelKey] - if !ok { - return nil, errors.Newf("Notification %s is enabled but missing 'level' key.", integrationObject.Name) - } - level, err := shared.StrToNotificationLevel(levelStr) - if err != nil { - return nil, err - } - return &level, nil -} - func ParseSlackConfig(conf auth.Config) (*shared.SlackConfig, error) { data, err := conf.Marshal() if err != nil {