github.com/argoproj/argo-cd/v2@v2.10.9/server/notification/notification.go (about)

     1  package notification
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/argoproj/argo-cd/v2/pkg/apiclient/notification"
     7  	"github.com/argoproj/notifications-engine/pkg/api"
     8  	apierr "k8s.io/apimachinery/pkg/api/errors"
     9  	"k8s.io/utils/pointer"
    10  )
    11  
    12  // Server provides an Application service
    13  type Server struct {
    14  	apiFactory api.Factory
    15  }
    16  
    17  // NewServer returns a new instance of the Application service
    18  func NewServer(apiFactory api.Factory) notification.NotificationServiceServer {
    19  	s := &Server{apiFactory: apiFactory}
    20  	return s
    21  }
    22  
    23  // List returns list of notification triggers
    24  func (s *Server) ListTriggers(ctx context.Context, q *notification.TriggersListRequest) (*notification.TriggerList, error) {
    25  	api, err := s.apiFactory.GetAPI()
    26  	if err != nil {
    27  		if apierr.IsNotFound(err) {
    28  			return &notification.TriggerList{}, nil
    29  		}
    30  	}
    31  	triggers := []*notification.Trigger{}
    32  	for trigger := range api.GetConfig().Triggers {
    33  		triggers = append(triggers, &notification.Trigger{Name: pointer.String(trigger)})
    34  	}
    35  	return &notification.TriggerList{Items: triggers}, nil
    36  }
    37  
    38  // List returns list of notification services
    39  func (s *Server) ListServices(ctx context.Context, q *notification.ServicesListRequest) (*notification.ServiceList, error) {
    40  	api, err := s.apiFactory.GetAPI()
    41  	if err != nil {
    42  		if apierr.IsNotFound(err) {
    43  			return &notification.ServiceList{}, nil
    44  		}
    45  		return nil, err
    46  	}
    47  	services := []*notification.Service{}
    48  	for svc := range api.GetConfig().Services {
    49  		services = append(services, &notification.Service{Name: pointer.String(svc)})
    50  	}
    51  	return &notification.ServiceList{Items: services}, nil
    52  }
    53  
    54  // List returns list of notification templates
    55  func (s *Server) ListTemplates(ctx context.Context, q *notification.TemplatesListRequest) (*notification.TemplateList, error) {
    56  	api, err := s.apiFactory.GetAPI()
    57  	if err != nil {
    58  		if apierr.IsNotFound(err) {
    59  			return &notification.TemplateList{}, nil
    60  		}
    61  		return nil, err
    62  	}
    63  	templates := []*notification.Template{}
    64  	for tmpl := range api.GetConfig().Templates {
    65  		templates = append(templates, &notification.Template{Name: pointer.String(tmpl)})
    66  	}
    67  	return &notification.TemplateList{Items: templates}, nil
    68  }