mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
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>
70 lines
2.1 KiB
Go
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 ¬ification.TriggerList{}, nil
|
|
}
|
|
}
|
|
triggers := []*notification.Trigger{}
|
|
for trigger := range api.GetConfig().Triggers {
|
|
triggers = append(triggers, ¬ification.Trigger{Name: ptr.To(trigger)})
|
|
}
|
|
return ¬ification.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 ¬ification.ServiceList{}, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
services := []*notification.Service{}
|
|
for svc := range api.GetConfig().Services {
|
|
services = append(services, ¬ification.Service{Name: ptr.To(svc)})
|
|
}
|
|
return ¬ification.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 ¬ification.TemplateList{}, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
templates := []*notification.Template{}
|
|
for tmpl := range api.GetConfig().Templates {
|
|
templates = append(templates, ¬ification.Template{Name: ptr.To(tmpl)})
|
|
}
|
|
return ¬ification.TemplateList{Items: templates}, nil
|
|
}
|