Skip to content

Commit 9c02842

Browse files
chore: drop enabled flag
1 parent 4a72e4f commit 9c02842

File tree

13 files changed

+40
-105
lines changed

13 files changed

+40
-105
lines changed

cli/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
902902
notificationsManager *notifications.Manager
903903
)
904904

905-
if notificationsCfg.Enabled {
905+
if notificationsCfg.Enabled() {
906906
metrics := notifications.NewMetrics(options.PrometheusRegistry)
907907
helpers := templateHelpers(options)
908908

@@ -927,6 +927,8 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
927927
// Run report generator to distribute periodic reports.
928928
notificationReportGenerator := reports.NewReportGenerator(ctx, logger.Named("notifications.report_generator"), options.Database, options.NotificationsEnqueuer, quartz.NewReal())
929929
defer notificationReportGenerator.Close()
930+
} else {
931+
logger.Info(ctx, "notifications disabled as there are no notification methods configured")
930932
}
931933

932934
// Since errCh only has one buffered slot, all routines

cli/testdata/coder_server_--help.golden

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Configure how emails are sent.
118118
--email-hello string, $CODER_EMAIL_HELLO (default: localhost)
119119
The hostname identifying the SMTP server.
120120

121-
--email-smarthost host:port, $CODER_EMAIL_SMARTHOST (default: localhost:587)
121+
--email-smarthost string, $CODER_EMAIL_SMARTHOST
122122
The intermediary SMTP host through which emails are sent.
123123

124124
EMAIL / EMAIL AUTHENTICATION OPTIONS:
@@ -392,9 +392,6 @@ Configure how notifications are processed and delivered.
392392
--notifications-dispatch-timeout duration, $CODER_NOTIFICATIONS_DISPATCH_TIMEOUT (default: 1m0s)
393393
How long to wait while a notification is being sent before giving up.
394394

395-
--notifications-enabled bool, $CODER_NOTIFICATIONS_ENABLED (default: true)
396-
Enable or disable notifications.
397-
398395
--notifications-max-send-attempts int, $CODER_NOTIFICATIONS_MAX_SEND_ATTEMPTS (default: 5)
399396
The upper limit of attempts to send a notification.
400397

@@ -416,7 +413,7 @@ Configure how email notifications are sent.
416413
The hostname identifying the SMTP server.
417414
DEPRECATED: Use --email-hello instead.
418415

419-
--notifications-email-smarthost host:port, $CODER_NOTIFICATIONS_EMAIL_SMARTHOST
416+
--notifications-email-smarthost string, $CODER_NOTIFICATIONS_EMAIL_SMARTHOST
420417
The intermediary SMTP host through which emails are sent.
421418
DEPRECATED: Use --email-smarthost instead.
422419

cli/testdata/server-config.yaml.golden

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ email:
524524
# (default: <unset>, type: string)
525525
from: ""
526526
# The intermediary SMTP host through which emails are sent.
527-
# (default: localhost:587, type: host:port)
528-
smarthost: localhost:587
527+
# (default: <unset>, type: string)
528+
smarthost: ""
529529
# The hostname identifying the SMTP server.
530530
# (default: localhost, type: string)
531531
hello: localhost
@@ -565,9 +565,6 @@ email:
565565
certKeyFile: ""
566566
# Configure how notifications are processed and delivered.
567567
notifications:
568-
# Enable or disable notifications.
569-
# (default: true, type: bool)
570-
enabled: true
571568
# Which delivery method to use (available options: 'smtp', 'webhook').
572569
# (default: smtp, type: string)
573570
method: smtp
@@ -580,8 +577,8 @@ notifications:
580577
# (default: <unset>, type: string)
581578
from: ""
582579
# The intermediary SMTP host through which emails are sent.
583-
# (default: <unset>, type: host:port)
584-
smarthost: localhost:587
580+
# (default: <unset>, type: string)
581+
smarthost: ""
585582
# The hostname identifying the SMTP server.
586583
# (default: <unset>, type: string)
587584
hello: localhost

coderd/apidoc/docs.go

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/notifications/dispatch/smtp.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ import (
3434
)
3535

3636
var (
37-
ValidationNoFromAddressErr = xerrors.New("no 'from' address defined")
38-
ValidationNoToAddressErr = xerrors.New("no 'to' address(es) defined")
39-
ValidationNoSmarthostHostErr = xerrors.New("smarthost 'host' is not defined, or is invalid")
40-
ValidationNoSmarthostPortErr = xerrors.New("smarthost 'port' is not defined, or is invalid")
41-
ValidationNoHelloErr = xerrors.New("'hello' not defined")
37+
ValidationNoFromAddressErr = xerrors.New("'from' address not defined")
38+
ValidationNoToAddressErr = xerrors.New("'to' address(es) not defined")
39+
ValidationNoSmarthostErr = xerrors.New("'smarthost' address not defined")
40+
ValidationNoHelloErr = xerrors.New("'hello' not defined")
4241

4342
//go:embed smtp/html.gotmpl
4443
htmlTemplate string
@@ -521,15 +520,14 @@ func (s *SMTPHandler) validateToAddrs(to string) ([]string, error) {
521520
// Does not allow overriding.
522521
// nolint:revive // documented.
523522
func (s *SMTPHandler) smarthost() (string, string, error) {
524-
host := s.cfg.Smarthost.Host
525-
port := s.cfg.Smarthost.Port
526-
527-
// We don't validate the contents themselves; this will be done by the underlying SMTP library.
528-
if host == "" {
529-
return "", "", ValidationNoSmarthostHostErr
523+
smarthost := strings.TrimSpace(string(s.cfg.Smarthost))
524+
if smarthost == "" {
525+
return "", "", ValidationNoSmarthostErr
530526
}
531-
if port == "" {
532-
return "", "", ValidationNoSmarthostPortErr
527+
528+
host, port, err := net.SplitHostPort(string(s.cfg.Smarthost))
529+
if err != nil {
530+
return "", "", xerrors.Errorf("split host port: %w", err)
533531
}
534532

535533
return host, port, nil

coderd/notifications/notifications_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestSMTPDispatch(t *testing.T) {
155155
cfg := defaultNotificationsConfig(method)
156156
cfg.SMTP = codersdk.NotificationsEmailConfig{
157157
From: from,
158-
Smarthost: serpent.HostPort{Host: "localhost", Port: fmt.Sprintf("%d", mockSMTPSrv.PortNumber())},
158+
Smarthost: serpent.String(fmt.Sprintf("localhost:%d", mockSMTPSrv.PortNumber())),
159159
Hello: "localhost",
160160
}
161161
handler := newDispatchInterceptor(dispatch.NewSMTPHandler(cfg.SMTP, logger.Named("smtp")))
@@ -1113,7 +1113,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
11131113

11141114
var hp serpent.HostPort
11151115
require.NoError(t, hp.Set(listen.Addr().String()))
1116-
smtpConfig.Smarthost = hp
1116+
smtpConfig.Smarthost = serpent.String(hp.String())
11171117

11181118
// Start mock SMTP server in the background.
11191119
var wg sync.WaitGroup
@@ -1524,7 +1524,7 @@ func TestCustomNotificationMethod(t *testing.T) {
15241524
cfg.SMTP = codersdk.NotificationsEmailConfig{
15251525
From: "danny@coder.com",
15261526
Hello: "localhost",
1527-
Smarthost: serpent.HostPort{Host: "localhost", Port: fmt.Sprintf("%d", mockSMTPSrv.PortNumber())},
1527+
Smarthost: serpent.String(fmt.Sprintf("localhost:%d", mockSMTPSrv.PortNumber())),
15281528
}
15291529
cfg.Webhook = codersdk.NotificationsWebhookConfig{
15301530
Endpoint: *serpent.URLOf(endpoint),

codersdk/deployment.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,6 @@ type HealthcheckConfig struct {
649649
}
650650

651651
type NotificationsConfig struct {
652-
Enabled serpent.Bool `json:"enabled" typescript:",notnull"`
653-
654652
// The upper limit of attempts to send a notification.
655653
MaxSendAttempts serpent.Int64 `json:"max_send_attempts" typescript:",notnull"`
656654
// The minimum time between retries.
@@ -688,11 +686,15 @@ type NotificationsConfig struct {
688686
Webhook NotificationsWebhookConfig `json:"webhook" typescript:",notnull"`
689687
}
690688

689+
func (n *NotificationsConfig) Enabled() bool {
690+
return n.SMTP.Smarthost != "" || n.Webhook.Endpoint != serpent.URL{}
691+
}
692+
691693
type NotificationsEmailConfig struct {
692694
// The sender's address.
693695
From serpent.String `json:"from" typescript:",notnull"`
694696
// The intermediary SMTP host through which emails are sent (host:port).
695-
Smarthost serpent.HostPort `json:"smarthost" typescript:",notnull"`
697+
Smarthost serpent.String `json:"smarthost" typescript:",notnull"`
696698
// The hostname identifying the SMTP server.
697699
Hello serpent.String `json:"hello" typescript:",notnull"`
698700

@@ -1030,7 +1032,6 @@ when required by your organization's security policy.`,
10301032
Description: "The intermediary SMTP host through which emails are sent.",
10311033
Flag: "email-smarthost",
10321034
Env: "CODER_EMAIL_SMARTHOST",
1033-
Default: "localhost:587", // To pass validation.
10341035
Value: &c.Notifications.SMTP.Smarthost,
10351036
Group: &deploymentGroupEmail,
10361037
YAML: "smarthost",
@@ -2613,16 +2614,6 @@ Write out the current server config as YAML to stdout.`,
26132614
emailTLSCertFile,
26142615
emailTLSCertKeyFile,
26152616
// Notifications Options
2616-
{
2617-
Name: "Notifications: Enabled",
2618-
Description: "Enable or disable notifications.",
2619-
Flag: "notifications-enabled",
2620-
Env: "CODER_NOTIFICATIONS_ENABLED",
2621-
Default: "true",
2622-
Value: &c.Notifications.Enabled,
2623-
Group: &deploymentGroupNotifications,
2624-
YAML: "enabled",
2625-
},
26262617
{
26272618
Name: "Notifications: Method",
26282619
Description: "Which delivery method to use (available options: 'smtp', 'webhook').",

docs/reference/api/general.md

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/api/schemas.md

Lines changed: 5 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/cli/server.md

Lines changed: 2 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)