feat!: allow disabling notifications (#15509)

Resolves https://github.com/coder/coder/issues/15513

Disables notifications when both `$CODER_NOTIFICATIONS_WEBHOOK_ENDPOINT` and `$CODER_EMAIL_SMARTHOST` are unset.

Breaking change: `$CODER_EMAIL_SMARTHOST` is no longer set by default as `localhost:587`, meaning any deployments that make use of this default value will need to add it back.

---------

Co-authored-by: Danny Kopping <danny@coder.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
Danielle Maywood
2024-11-19 15:05:12 +00:00
committed by GitHub
co-authored by Danny Kopping Mathias Fredriksson
parent 1c08580f23
commit 576e1f48fe
15 changed files with 155 additions and 101 deletions
+11 -13
View File
@@ -34,11 +34,10 @@ import (
)
var (
ValidationNoFromAddressErr = xerrors.New("no 'from' address defined")
ValidationNoToAddressErr = xerrors.New("no 'to' address(es) defined")
ValidationNoSmarthostHostErr = xerrors.New("smarthost 'host' is not defined, or is invalid")
ValidationNoSmarthostPortErr = xerrors.New("smarthost 'port' is not defined, or is invalid")
ValidationNoHelloErr = xerrors.New("'hello' not defined")
ValidationNoFromAddressErr = xerrors.New("'from' address not defined")
ValidationNoToAddressErr = xerrors.New("'to' address(es) not defined")
ValidationNoSmarthostErr = xerrors.New("'smarthost' address not defined")
ValidationNoHelloErr = xerrors.New("'hello' not defined")
//go:embed smtp/html.gotmpl
htmlTemplate string
@@ -521,15 +520,14 @@ func (s *SMTPHandler) validateToAddrs(to string) ([]string, error) {
// Does not allow overriding.
// nolint:revive // documented.
func (s *SMTPHandler) smarthost() (string, string, error) {
host := s.cfg.Smarthost.Host
port := s.cfg.Smarthost.Port
// We don't validate the contents themselves; this will be done by the underlying SMTP library.
if host == "" {
return "", "", ValidationNoSmarthostHostErr
smarthost := strings.TrimSpace(string(s.cfg.Smarthost))
if smarthost == "" {
return "", "", ValidationNoSmarthostErr
}
if port == "" {
return "", "", ValidationNoSmarthostPortErr
host, port, err := net.SplitHostPort(string(s.cfg.Smarthost))
if err != nil {
return "", "", xerrors.Errorf("split host port: %w", err)
}
return host, port, nil
+1 -1
View File
@@ -440,7 +440,7 @@ func TestSMTP(t *testing.T) {
var hp serpent.HostPort
require.NoError(t, hp.Set(listen.Addr().String()))
tc.cfg.Smarthost = hp
tc.cfg.Smarthost = serpent.String(hp.String())
handler := dispatch.NewSMTPHandler(tc.cfg, logger.Named("smtp"))