notifications

package
v0.0.0-...-fb7f86c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidEmailCode = errors.New("invalid or expired email code")
View Source
var ErrSmtpNotEnabled = errors.New("SMTP not configured, check your grafana.ini config file's [smtp] section")
View Source
var NetClient = &netClient

NetClient is used to export original in test.

Functions

func SetWebhookClient

func SetWebhookClient(client WebhookClient)

SetWebhookClient is used to mock in test.

Types

type AttachedFile

type AttachedFile struct {
	Name    string
	Content []byte
}

AttachedFile struct represents email attached files.

type EmailSender

type EmailSender interface {
	SendEmailCommandHandlerSync(ctx context.Context, cmd *SendEmailCommandSync) error
	SendEmailCommandHandler(ctx context.Context, cmd *SendEmailCommand) error
}

type FakeDisconnectedMailer

type FakeDisconnectedMailer struct{}

func NewFakeDisconnectedMailer

func NewFakeDisconnectedMailer() *FakeDisconnectedMailer

func (*FakeDisconnectedMailer) Send

func (fdm *FakeDisconnectedMailer) Send(messages ...*Message) (int, error)

type FakeMailer

type FakeMailer struct {
	Sent []*Message
}

func NewFakeMailer

func NewFakeMailer() *FakeMailer

func (*FakeMailer) Send

func (fm *FakeMailer) Send(messages ...*Message) (int, error)

type GetUserByLoginFunc

type GetUserByLoginFunc = func(c context.Context, login string) (*user.User, error)

type Mailer

type Mailer interface {
	Send(messages ...*Message) (int, error)
}

func ProvideSmtpService

func ProvideSmtpService(cfg *setting.Cfg) (Mailer, error)

type Message

type Message struct {
	To            []string
	SingleEmail   bool
	From          string
	Subject       string
	Body          map[string]string
	Info          string
	ReplyTo       []string
	EmbeddedFiles []string
	AttachedFiles []*AttachedFile
}

Message is representation of the email message.

type NotificationService

type NotificationService struct {
	Bus bus.Bus
	Cfg *setting.Cfg
	// contains filtered or unexported fields
}

func ProvideService

func ProvideService(bus bus.Bus, cfg *setting.Cfg, mailer Mailer, store TempUserStore) (*NotificationService, error)

func (*NotificationService) GetMailer

func (ns *NotificationService) GetMailer() Mailer

func (*NotificationService) Run

func (*NotificationService) Send

func (ns *NotificationService) Send(msg *Message) (int, error)

func (*NotificationService) SendEmailCommandHandler

func (ns *NotificationService) SendEmailCommandHandler(ctx context.Context, cmd *SendEmailCommand) error

func (*NotificationService) SendEmailCommandHandlerSync

func (ns *NotificationService) SendEmailCommandHandlerSync(ctx context.Context, cmd *SendEmailCommandSync) error

func (*NotificationService) SendResetPasswordEmail

func (ns *NotificationService) SendResetPasswordEmail(ctx context.Context, cmd *SendResetPasswordEmailCommand) error

func (*NotificationService) SendWebhookSync

func (ns *NotificationService) SendWebhookSync(ctx context.Context, cmd *SendWebhookSync) error

func (*NotificationService) ValidateResetPasswordCode

func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, query *ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) (*user.User, error)

type NotificationServiceMock

type NotificationServiceMock struct {
	Webhook     SendWebhookSync
	EmailSync   SendEmailCommandSync
	Email       SendEmailCommand
	ShouldError error

	WebhookHandler   func(context.Context, *SendWebhookSync) error
	EmailHandlerSync func(context.Context, *SendEmailCommandSync) error
	EmailHandler     func(context.Context, *SendEmailCommand) error
}

func MockNotificationService

func MockNotificationService() *NotificationServiceMock

func (*NotificationServiceMock) SendEmailCommandHandler

func (ns *NotificationServiceMock) SendEmailCommandHandler(ctx context.Context, cmd *SendEmailCommand) error

func (*NotificationServiceMock) SendEmailCommandHandlerSync

func (ns *NotificationServiceMock) SendEmailCommandHandlerSync(ctx context.Context, cmd *SendEmailCommandSync) error

func (*NotificationServiceMock) SendWebhookSync

func (ns *NotificationServiceMock) SendWebhookSync(ctx context.Context, cmd *SendWebhookSync) error

type SendEmailAttachFile

type SendEmailAttachFile struct {
	Name    string
	Content []byte
}

SendEmailAttachFile is a definition of the attached files without path

type SendEmailCommand

type SendEmailCommand struct {
	To            []string
	SingleEmail   bool
	Template      string
	Subject       string
	Data          map[string]interface{}
	Info          string
	ReplyTo       []string
	EmbeddedFiles []string
	AttachedFiles []*SendEmailAttachFile
}

SendEmailCommand is the command for sending emails

type SendEmailCommandSync

type SendEmailCommandSync struct {
	SendEmailCommand
}

SendEmailCommandSync is the command for sending emails synchronously

type SendResetPasswordEmailCommand

type SendResetPasswordEmailCommand struct {
	User *user.User
}

type SendWebhookSync

type SendWebhookSync struct {
	Url         string
	User        string
	Password    string
	Body        string
	HttpMethod  string
	HttpHeader  map[string]string
	ContentType string
	Validation  func(body []byte, statusCode int) error
}

type Service

type Service interface {
	WebhookSender
	EmailSender
}

type SmtpClient

type SmtpClient struct {
	// contains filtered or unexported fields
}

func NewSmtpClient

func NewSmtpClient(cfg setting.SmtpSettings) (*SmtpClient, error)

func (*SmtpClient) Send

func (sc *SmtpClient) Send(messages ...*Message) (int, error)

type TempUserStore

type TempUserStore interface {
	UpdateTempUserWithEmailSent(ctx context.Context, cmd *tempuser.UpdateTempUserWithEmailSentCommand) error
}

type ValidateResetPasswordCodeQuery

type ValidateResetPasswordCodeQuery struct {
	Code string
}

type Webhook

type Webhook struct {
	Url         string
	User        string
	Password    string
	Body        string
	HttpMethod  string
	HttpHeader  map[string]string
	ContentType string

	// Validation is a function that will validate the response body and statusCode of the webhook. Any returned error will cause the webhook request to be considered failed.
	// This can be useful when a webhook service communicates failures in creative ways, such as using the response body instead of the status code.
	Validation func(body []byte, statusCode int) error
}

type WebhookClient

type WebhookClient interface {
	Do(req *http.Request) (*http.Response, error)
}

WebhookClient exists to mock the client in tests.

type WebhookSender

type WebhookSender interface {
	SendWebhookSync(ctx context.Context, cmd *SendWebhookSync) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL