Documentation
¶
Overview ¶
Package notify implements the warden.Notifier delivery backends used by the watchdog:
- SMTPNotifier sends incident emails over STARTTLS (production).
- LogNotifier writes a structured log line via core.Logger (used when SMTP is not configured).
- FileNotifier appends one JSON-encoded incident per line to a file (used by the e2e harness).
(A test that wants to assert on calls rather than deliver anywhere uses the generated warden.Notifier mock instead; see services/warden/internal/mocks.)
All notifiers are safe for concurrent use, which is the contract the watchdog relies on when it delivers from short-lived goroutines. The SMTP notifier fails closed: it refuses to transmit credentials or mail if the server does not advertise STARTTLS, so secrets never traverse a cleartext link. That refusal is deliberate behaviour, reported as ErrSTARTTLSRequired — a caller must not "fall back" to plaintext around it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSTARTTLSRequired means the server did not advertise STARTTLS; the // notifier fails closed rather than send credentials or mail in cleartext. ErrSTARTTLSRequired = errors.New("notify: smtp server does not advertise STARTTLS") // ErrAuthUnsupported means credentials were configured but the server did // not advertise AUTH after STARTTLS. ErrAuthUnsupported = errors.New("notify: smtp server does not advertise AUTH") // ErrNoRecipients means no To address was configured. ErrNoRecipients = errors.New("notify: no recipients configured") // ErrNoSender means no From address was configured. ErrNoSender = errors.New("notify: no From address configured") // ErrHeaderInjection means a header-contributing field held a CR or LF. ErrHeaderInjection = errors.New("notify: header field contains a CR or LF") )
Errors returned by the SMTP notifier and message builder.
Functions ¶
This section is empty.
Types ¶
type FileNotifier ¶
type FileNotifier struct {
// contains filtered or unexported fields
}
FileNotifier appends one JSON-encoded incident per line to a file. It is used by the e2e harness as a durable, greppable sink.
It is safe for concurrent use without any lock: each Notify opens the file with O_APPEND, writes the fully marshaled line (a single []byte, one Write syscall) and closes it. On a local filesystem the kernel guarantees an O_APPEND write is positioned at end-of-file and applied atomically, so concurrent callers never interleave or lose lines.
func NewFileNotifier ¶
func NewFileNotifier(path string) *FileNotifier
NewFileNotifier returns a FileNotifier writing to path.
type LogNotifier ¶
type LogNotifier struct{}
LogNotifier delivers incidents by writing a structured log line via core.Logger. It is the default notifier when SMTP is not configured. It holds no mutable state and core.Logger is safe for concurrent use, so no synchronization is needed.
type SMTPConfig ¶
type SMTPConfig struct {
Host string
Port int
Username string
Password string
From string
To []string
}
SMTPConfig configures the SMTP notifier. Username may be empty to skip AUTH (e.g. an internal relay that authenticates by network).
type SMTPNotifier ¶
type SMTPNotifier struct {
// contains filtered or unexported fields
}
SMTPNotifier sends incident emails over SMTP with STARTTLS. It holds only immutable configuration, so concurrent Notify calls (each on its own connection) are safe without synchronization.
func NewSMTPNotifier ¶
func NewSMTPNotifier(cfg SMTPConfig) *SMTPNotifier
NewSMTPNotifier returns an SMTPNotifier for cfg.