Skip to content

Commit 3e7ea27

Browse files
fix: remove defaults for CODER_EMAIL_ options
1 parent 6117f46 commit 3e7ea27

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

cli/testdata/coder_server_--help.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ Use a YAML configuration file when your server launch become unwieldy.
109109
EMAIL OPTIONS:
110110
Configure how emails are sent.
111111

112-
--email-force-tls bool, $CODER_EMAIL_FORCE_TLS (default: false)
112+
--email-force-tls bool, $CODER_EMAIL_FORCE_TLS
113113
Force a TLS connection to the configured SMTP smarthost.
114114

115115
--email-from string, $CODER_EMAIL_FROM
116116
The sender's address to use.
117117

118-
--email-hello string, $CODER_EMAIL_HELLO (default: localhost)
118+
--email-hello string, $CODER_EMAIL_HELLO
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:
@@ -413,7 +413,7 @@ Configure how email notifications are sent.
413413
The hostname identifying the SMTP server.
414414
DEPRECATED: Use --email-hello instead.
415415

416-
--notifications-email-smarthost host:port, $CODER_NOTIFICATIONS_EMAIL_SMARTHOST
416+
--notifications-email-smarthost string, $CODER_NOTIFICATIONS_EMAIL_SMARTHOST
417417
The intermediary SMTP host through which emails are sent.
418418
DEPRECATED: Use --email-smarthost instead.
419419

cli/testdata/server-config.yaml.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,13 @@ 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.
530-
# (default: localhost, type: string)
531-
hello: localhost
530+
# (default: <unset>, type: string)
531+
hello: ""
532532
# Force a TLS connection to the configured SMTP smarthost.
533-
# (default: false, type: bool)
533+
# (default: <unset>, type: bool)
534534
forceTLS: false
535535
# Configure SMTP authentication options.
536536
emailAuth:
@@ -577,11 +577,11 @@ notifications:
577577
# (default: <unset>, type: string)
578578
from: ""
579579
# The intermediary SMTP host through which emails are sent.
580-
# (default: <unset>, type: host:port)
581-
smarthost: localhost:587
580+
# (default: <unset>, type: string)
581+
smarthost: ""
582582
# The hostname identifying the SMTP server.
583583
# (default: <unset>, type: string)
584-
hello: localhost
584+
hello: ""
585585
# Force a TLS connection to the configured SMTP smarthost.
586586
# (default: <unset>, type: bool)
587587
forceTLS: false

coderd/notifications/dispatch/smtp.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,9 @@ func (s *SMTPHandler) validateToAddrs(to string) ([]string, error) {
521521
// Does not allow overriding.
522522
// nolint:revive // documented.
523523
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
530-
}
531-
if port == "" {
532-
return "", "", ValidationNoSmarthostPortErr
524+
host, port, err := net.SplitHostPort(s.cfg.Smarthost.String())
525+
if err != nil {
526+
return "", "", fmt.Errorf("split host port: %w", err)
533527
}
534528

535529
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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ type NotificationsEmailConfig struct {
690690
// The sender's address.
691691
From serpent.String `json:"from" typescript:",notnull"`
692692
// The intermediary SMTP host through which emails are sent (host:port).
693-
Smarthost serpent.HostPort `json:"smarthost" typescript:",notnull"`
693+
Smarthost serpent.String `json:"smarthost" typescript:",notnull"`
694694
// The hostname identifying the SMTP server.
695695
Hello serpent.String `json:"hello" typescript:",notnull"`
696696

@@ -1028,7 +1028,6 @@ when required by your organization's security policy.`,
10281028
Description: "The intermediary SMTP host through which emails are sent.",
10291029
Flag: "email-smarthost",
10301030
Env: "CODER_EMAIL_SMARTHOST",
1031-
Default: "localhost:587", // To pass validation.
10321031
Value: &c.Notifications.SMTP.Smarthost,
10331032
Group: &deploymentGroupEmail,
10341033
YAML: "smarthost",
@@ -1038,7 +1037,6 @@ when required by your organization's security policy.`,
10381037
Description: "The hostname identifying the SMTP server.",
10391038
Flag: "email-hello",
10401039
Env: "CODER_EMAIL_HELLO",
1041-
Default: "localhost",
10421040
Value: &c.Notifications.SMTP.Hello,
10431041
Group: &deploymentGroupEmail,
10441042
YAML: "hello",
@@ -1048,7 +1046,6 @@ when required by your organization's security policy.`,
10481046
Description: "Force a TLS connection to the configured SMTP smarthost.",
10491047
Flag: "email-force-tls",
10501048
Env: "CODER_EMAIL_FORCE_TLS",
1051-
Default: "false",
10521049
Value: &c.Notifications.SMTP.ForceTLS,
10531050
Group: &deploymentGroupEmail,
10541051
YAML: "forceTLS",

enterprise/cli/testdata/coder_server_--help.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ Use a YAML configuration file when your server launch become unwieldy.
110110
EMAIL OPTIONS:
111111
Configure how emails are sent.
112112

113-
--email-force-tls bool, $CODER_EMAIL_FORCE_TLS (default: false)
113+
--email-force-tls bool, $CODER_EMAIL_FORCE_TLS
114114
Force a TLS connection to the configured SMTP smarthost.
115115

116116
--email-from string, $CODER_EMAIL_FROM
117117
The sender's address to use.
118118

119-
--email-hello string, $CODER_EMAIL_HELLO (default: localhost)
119+
--email-hello string, $CODER_EMAIL_HELLO
120120
The hostname identifying the SMTP server.
121121

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

125125
EMAIL / EMAIL AUTHENTICATION OPTIONS:
@@ -414,7 +414,7 @@ Configure how email notifications are sent.
414414
The hostname identifying the SMTP server.
415415
DEPRECATED: Use --email-hello instead.
416416

417-
--notifications-email-smarthost host:port, $CODER_NOTIFICATIONS_EMAIL_SMARTHOST
417+
--notifications-email-smarthost string, $CODER_NOTIFICATIONS_EMAIL_SMARTHOST
418418
The intermediary SMTP host through which emails are sent.
419419
DEPRECATED: Use --email-smarthost instead.
420420

0 commit comments

Comments
 (0)