forked from teamhanko/hanko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] disable email delivery (teamhanko#1419)
* feat: add config to disable email delivery * chore: update config schema * docs: add new config parameter * test: fix test * fix: rename email webhook event * docs: Update backend/docs/Config.md Co-authored-by: Lennart Fleischmann <[email protected]> --------- Co-authored-by: Lennart Fleischmann <[email protected]>
- Loading branch information
1 parent
7276db1
commit def7ad3
Showing
13 changed files
with
162 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,23 +20,24 @@ import ( | |
|
||
// Config is the central configuration type | ||
type Config struct { | ||
Server Server `yaml:"server" json:"server,omitempty" koanf:"server"` | ||
Webauthn WebauthnSettings `yaml:"webauthn" json:"webauthn,omitempty" koanf:"webauthn"` | ||
Smtp SMTP `yaml:"smtp" json:"smtp,omitempty" koanf:"smtp"` | ||
Passcode Passcode `yaml:"passcode" json:"passcode" koanf:"passcode"` | ||
Password Password `yaml:"password" json:"password,omitempty" koanf:"password"` | ||
Database Database `yaml:"database" json:"database" koanf:"database"` | ||
Secrets Secrets `yaml:"secrets" json:"secrets" koanf:"secrets"` | ||
Service Service `yaml:"service" json:"service" koanf:"service"` | ||
Session Session `yaml:"session" json:"session,omitempty" koanf:"session"` | ||
AuditLog AuditLog `yaml:"audit_log" json:"audit_log,omitempty" koanf:"audit_log" split_words:"true"` | ||
Emails Emails `yaml:"emails" json:"emails,omitempty" koanf:"emails"` | ||
RateLimiter RateLimiter `yaml:"rate_limiter" json:"rate_limiter,omitempty" koanf:"rate_limiter" split_words:"true"` | ||
ThirdParty ThirdParty `yaml:"third_party" json:"third_party,omitempty" koanf:"third_party" split_words:"true"` | ||
Log LoggerConfig `yaml:"log" json:"log,omitempty" koanf:"log"` | ||
Account Account `yaml:"account" json:"account,omitempty" koanf:"account"` | ||
Saml config.Saml `yaml:"saml" json:"saml,omitempty" koanf:"saml"` | ||
Webhooks WebhookSettings `yaml:"webhooks" json:"webhooks,omitempty" koanf:"webhooks"` | ||
Server Server `yaml:"server" json:"server,omitempty" koanf:"server"` | ||
Webauthn WebauthnSettings `yaml:"webauthn" json:"webauthn,omitempty" koanf:"webauthn"` | ||
Smtp SMTP `yaml:"smtp" json:"smtp,omitempty" koanf:"smtp"` | ||
EmailDelivery EmailDelivery `yaml:"email_delivery" json:"email_delivery,omitempty" koanf:"email_delivery" split_words:"true"` | ||
Passcode Passcode `yaml:"passcode" json:"passcode" koanf:"passcode"` | ||
Password Password `yaml:"password" json:"password,omitempty" koanf:"password"` | ||
Database Database `yaml:"database" json:"database" koanf:"database"` | ||
Secrets Secrets `yaml:"secrets" json:"secrets" koanf:"secrets"` | ||
Service Service `yaml:"service" json:"service" koanf:"service"` | ||
Session Session `yaml:"session" json:"session,omitempty" koanf:"session"` | ||
AuditLog AuditLog `yaml:"audit_log" json:"audit_log,omitempty" koanf:"audit_log" split_words:"true"` | ||
Emails Emails `yaml:"emails" json:"emails,omitempty" koanf:"emails"` | ||
RateLimiter RateLimiter `yaml:"rate_limiter" json:"rate_limiter,omitempty" koanf:"rate_limiter" split_words:"true"` | ||
ThirdParty ThirdParty `yaml:"third_party" json:"third_party,omitempty" koanf:"third_party" split_words:"true"` | ||
Log LoggerConfig `yaml:"log" json:"log,omitempty" koanf:"log"` | ||
Account Account `yaml:"account" json:"account,omitempty" koanf:"account"` | ||
Saml config.Saml `yaml:"saml" json:"saml,omitempty" koanf:"saml"` | ||
Webhooks WebhookSettings `yaml:"webhooks" json:"webhooks,omitempty" koanf:"webhooks"` | ||
} | ||
|
||
var ( | ||
|
@@ -118,6 +119,9 @@ func DefaultConfig() *Config { | |
Smtp: SMTP{ | ||
Port: "465", | ||
}, | ||
EmailDelivery: EmailDelivery{ | ||
Enabled: true, | ||
}, | ||
Passcode: Passcode{ | ||
TTL: 300, | ||
Email: Email{ | ||
|
@@ -203,9 +207,11 @@ func (c *Config) Validate() error { | |
if err != nil { | ||
return fmt.Errorf("failed to validate webauthn settings: %w", err) | ||
} | ||
err = c.Smtp.Validate() | ||
if err != nil { | ||
return fmt.Errorf("failed to validate smtp settings: %w", err) | ||
if c.EmailDelivery.Enabled { | ||
err = c.Smtp.Validate() | ||
if err != nil { | ||
return fmt.Errorf("failed to validate smtp settings: %w", err) | ||
} | ||
} | ||
err = c.Passcode.Validate() | ||
if err != nil { | ||
|
@@ -382,6 +388,10 @@ func (s *SMTP) Validate() error { | |
return nil | ||
} | ||
|
||
type EmailDelivery struct { | ||
Enabled bool `yaml:"enabled" json:"enabled" koanf:"enabled" jsonschema:"default=true"` | ||
} | ||
|
||
type Email struct { | ||
FromAddress string `yaml:"from_address" json:"from_address,omitempty" koanf:"from_address" split_words:"true" jsonschema:"[email protected]"` | ||
FromName string `yaml:"from_name" json:"from_name,omitempty" koanf:"from_name" split_words:"true" jsonschema:"default=Hanko"` | ||
|
@@ -688,6 +698,9 @@ func (c *Config) PostProcess() error { | |
} | ||
|
||
func (c *Config) arrangeSmtpSettings() { | ||
if !c.EmailDelivery.Enabled { | ||
return | ||
} | ||
if c.Passcode.Smtp.Validate() == nil { | ||
if c.Smtp.Validate() == nil { | ||
zeroLogger.Warn().Msg("Both root smtp and passcode.smtp are set. Using smtp settings from root configuration") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package webhook | ||
|
||
type EmailSend struct { | ||
Subject string `json:"subject"` // subject | ||
BodyPlain string `json:"body_plain"` // used for string templates | ||
Body string `json:"body,omitempty"` // used for html templates | ||
ToEmailAddress string `json:"to_email_address"` | ||
DeliveredByHanko bool `json:"delivered_by_hanko"` | ||
AcceptLanguage string `json:"accept_language"` // accept_language header from http request | ||
Type EmailType `json:"type"` // type of the email, currently only "passcode", but other could be added later | ||
|
||
Data interface{} `json:"data"` | ||
} | ||
|
||
type PasscodeData struct { | ||
ServiceName string `json:"service_name"` | ||
OtpCode string `json:"otp_code"` | ||
TTL int `json:"ttl"` | ||
ValidUntil int64 `json:"valid_until"` // UnixTimestamp | ||
} | ||
|
||
type EmailType string | ||
|
||
var ( | ||
EmailTypePasscode EmailType = "passcode" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ var DefaultConfig = config.Config{ | |
Host: "localhost", | ||
Port: "2500", | ||
}, | ||
EmailDelivery: config.EmailDelivery{ | ||
Enabled: true, | ||
}, | ||
Passcode: config.Passcode{ | ||
Email: config.Email{ | ||
FromAddress: "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.