-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
notification.go
68 lines (61 loc) · 2.11 KB
/
notification.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package notification
import (
"context"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/notification"
"github.com/argoproj/notifications-engine/pkg/api"
apierr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/pointer"
)
// Server provides an Application service
type Server struct {
apiFactory api.Factory
}
// NewServer returns a new instance of the Application service
func NewServer(apiFactory api.Factory) notification.NotificationServiceServer {
s := &Server{apiFactory: apiFactory}
return s
}
// List returns list of notification triggers
func (s *Server) ListTriggers(ctx context.Context, q *notification.TriggersListRequest) (*notification.TriggerList, error) {
api, err := s.apiFactory.GetAPI()
if err != nil {
if apierr.IsNotFound(err) {
return ¬ification.TriggerList{}, nil
}
}
triggers := []*notification.Trigger{}
for trigger := range api.GetConfig().Triggers {
triggers = append(triggers, ¬ification.Trigger{Name: pointer.String(trigger)})
}
return ¬ification.TriggerList{Items: triggers}, nil
}
// List returns list of notification services
func (s *Server) ListServices(ctx context.Context, q *notification.ServicesListRequest) (*notification.ServiceList, error) {
api, err := s.apiFactory.GetAPI()
if err != nil {
if apierr.IsNotFound(err) {
return ¬ification.ServiceList{}, nil
}
return nil, err
}
services := []*notification.Service{}
for svc := range api.GetConfig().Services {
services = append(services, ¬ification.Service{Name: pointer.String(svc)})
}
return ¬ification.ServiceList{Items: services}, nil
}
// List returns list of notification templates
func (s *Server) ListTemplates(ctx context.Context, q *notification.TemplatesListRequest) (*notification.TemplateList, error) {
api, err := s.apiFactory.GetAPI()
if err != nil {
if apierr.IsNotFound(err) {
return ¬ification.TemplateList{}, nil
}
return nil, err
}
templates := []*notification.Template{}
for tmpl := range api.GetConfig().Templates {
templates = append(templates, ¬ification.Template{Name: pointer.String(tmpl)})
}
return ¬ification.TemplateList{Items: templates}, nil
}