-
Notifications
You must be signed in to change notification settings - Fork 541
/
notifications_validator.go
49 lines (44 loc) · 1.3 KB
/
notifications_validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package validation
import (
"github.com/flyteorg/flyte/flyteadmin/pkg/common"
"github.com/flyteorg/flyte/flyteadmin/pkg/manager/impl/shared"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
)
// TODO: maybe add more sophisticated email validation.
func validateRecipientsEmail(recipients []string) error {
if len(recipients) == 0 {
return shared.GetMissingArgumentError("recipients")
}
for _, recipient := range recipients {
if len(recipient) == 0 {
return shared.GetMissingArgumentError("recipient")
}
}
return nil
}
func validateNotifications(notifications []*admin.Notification) error {
for _, notif := range notifications {
switch {
case notif.GetEmail() != nil:
if err := validateRecipientsEmail(notif.GetEmail().RecipientsEmail); err != nil {
return err
}
case notif.GetSlack() != nil:
if err := validateRecipientsEmail(notif.GetSlack().RecipientsEmail); err != nil {
return err
}
case notif.GetPagerDuty() != nil:
if err := validateRecipientsEmail(notif.GetPagerDuty().RecipientsEmail); err != nil {
return err
}
default:
return shared.GetInvalidArgumentError("notification type")
}
for _, phase := range notif.Phases {
if !common.IsExecutionTerminal(phase) {
return shared.GetInvalidArgumentError("phase")
}
}
}
return nil
}