Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
kenxu95 committed May 9, 2023
1 parent 352195c commit ef4b6a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
33 changes: 33 additions & 0 deletions src/golang/lib/lib_utils/notification.go
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 0 additions & 27 deletions src/golang/lib/lib_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ef4b6a2

Please sign in to comment.