Files
argo-cd/server/notification/notification.go
github-actions[bot] 4d9835927d Bump major version to 3 (#21410)
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: crenshaw-dev <350466+crenshaw-dev@users.noreply.github.com>
2025-01-10 16:14:00 -05:00

70 lines
2.1 KiB
Go

package notification
import (
"context"
"github.com/argoproj/notifications-engine/pkg/api"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/ptr"
"github.com/argoproj/argo-cd/v3/pkg/apiclient/notification"
)
// 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(_ context.Context, _ *notification.TriggersListRequest) (*notification.TriggerList, error) {
api, err := s.apiFactory.GetAPI()
if err != nil {
if apierrors.IsNotFound(err) {
return &notification.TriggerList{}, nil
}
}
triggers := []*notification.Trigger{}
for trigger := range api.GetConfig().Triggers {
triggers = append(triggers, &notification.Trigger{Name: ptr.To(trigger)})
}
return &notification.TriggerList{Items: triggers}, nil
}
// List returns list of notification services
func (s *Server) ListServices(_ context.Context, _ *notification.ServicesListRequest) (*notification.ServiceList, error) {
api, err := s.apiFactory.GetAPI()
if err != nil {
if apierrors.IsNotFound(err) {
return &notification.ServiceList{}, nil
}
return nil, err
}
services := []*notification.Service{}
for svc := range api.GetConfig().Services {
services = append(services, &notification.Service{Name: ptr.To(svc)})
}
return &notification.ServiceList{Items: services}, nil
}
// List returns list of notification templates
func (s *Server) ListTemplates(_ context.Context, _ *notification.TemplatesListRequest) (*notification.TemplateList, error) {
api, err := s.apiFactory.GetAPI()
if err != nil {
if apierrors.IsNotFound(err) {
return &notification.TemplateList{}, nil
}
return nil, err
}
templates := []*notification.Template{}
for tmpl := range api.GetConfig().Templates {
templates = append(templates, &notification.Template{Name: ptr.To(tmpl)})
}
return &notification.TemplateList{Items: templates}, nil
}