-
Notifications
You must be signed in to change notification settings - Fork 941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1030 - Refactor SMTP settings to be outside of passcode config #1121
Merged
FreddyDevelop
merged 7 commits into
teamhanko:main
from
irby:feat/1030/refactor-smtp-settings
Jan 30, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3a5b253
1030 - Refactor SMTP settings to be outside of passcode config
irby 0aad362
Merge branch 'main' into feat/1030/refactor-smtp-settings
irby e18598c
Backwards compatibility of SMTP settings
irby 83dfa59
Merge branch 'main' into feat/1030/refactor-smtp-settings
irby 149ff41
Merge branch 'main' into feat/1030/refactor-smtp-settings
irby 0821451
Do not error if root smtp and passcode smtp are defined. Log warning …
irby 92d2522
Update warning message
irby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/knadh/koanf/providers/file" | ||
"github.com/teamhanko/hanko/backend/ee/saml/config" | ||
"golang.org/x/exp/slices" | ||
zeroLogger "github.com/rs/zerolog/log" | ||
"log" | ||
"strings" | ||
"time" | ||
|
@@ -20,6 +21,7 @@ import ( | |
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"` | ||
|
@@ -70,6 +72,8 @@ func Load(cfgFile *string) (*Config, error) { | |
return nil, fmt.Errorf("failed to post process config: %w", err) | ||
} | ||
|
||
c.arrangeSmtpSettings() | ||
|
||
if err = c.Validate(); err != nil { | ||
return nil, fmt.Errorf("failed to validate config: %s", err) | ||
} | ||
|
@@ -96,15 +100,18 @@ func DefaultConfig() *Config { | |
UserVerification: "preferred", | ||
Timeout: 60000, | ||
}, | ||
Smtp: SMTP{ | ||
Port: "465", | ||
}, | ||
Passcode: Passcode{ | ||
Smtp: SMTP{ | ||
Port: "465", | ||
}, | ||
TTL: 300, | ||
Email: Email{ | ||
FromAddress: "[email protected]", | ||
FromName: "Hanko", | ||
}, | ||
Smtp: SMTP{ | ||
Port: "465", | ||
}, | ||
}, | ||
Password: Password{ | ||
MinPasswordLength: 8, | ||
|
@@ -162,6 +169,10 @@ 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) | ||
} | ||
err = c.Passcode.Validate() | ||
if err != nil { | ||
return fmt.Errorf("failed to validate passcode settings: %w", err) | ||
|
@@ -347,19 +358,16 @@ func (e *Email) Validate() error { | |
|
||
type Passcode struct { | ||
Email Email `yaml:"email" json:"email,omitempty" koanf:"email"` | ||
Smtp SMTP `yaml:"smtp" json:"smtp" koanf:"smtp"` | ||
TTL int `yaml:"ttl" json:"ttl,omitempty" koanf:"ttl" jsonschema:"default=300"` | ||
//Deprecated: Use root level Smtp instead | ||
Smtp SMTP `yaml:"smtp" json:"smtp,omitempty" koanf:"smtp,omitempty" required:"false" envconfig:"smtp,omitempty"` | ||
} | ||
|
||
func (p *Passcode) Validate() error { | ||
err := p.Email.Validate() | ||
if err != nil { | ||
return fmt.Errorf("failed to validate email settings: %w", err) | ||
} | ||
err = p.Smtp.Validate() | ||
if err != nil { | ||
return fmt.Errorf("failed to validate smtp settings: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -638,6 +646,17 @@ func (c *Config) PostProcess() error { | |
|
||
} | ||
|
||
func (c *Config) arrangeSmtpSettings() { | ||
if c.Passcode.Smtp.Validate() == nil { | ||
if c.Smtp.Validate() == nil { | ||
zeroLogger.Warn().Msg("Both smtp and passcode.smtp are set. Using smtp settings from passcode.smtp") | ||
return | ||
} | ||
|
||
c.Smtp = c.Passcode.Smtp | ||
} | ||
} | ||
|
||
type LoggerConfig struct { | ||
LogHealthAndMetrics bool `yaml:"log_health_and_metrics,omitempty" json:"log_health_and_metrics" koanf:"log_health_and_metrics" jsonschema:"default=true"` | ||
} | ||
|
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 |
---|---|---|
|
@@ -4,13 +4,13 @@ database: | |
host: localhost | ||
port: 5432 | ||
dialect: postgres | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
smtp: | ||
host: smtp.example.com | ||
user: example | ||
password: example | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
passcode: | ||
smtp: | ||
smtp: | ||
host: smtp.example.com | ||
user: example | ||
password: example | ||
|
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,18 @@ | ||
database: | ||
user: hanko | ||
password: hanko | ||
host: localhost | ||
port: 5432 | ||
dialect: postgres | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
host: smtp.example.com | ||
user: example | ||
password: example | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
service: | ||
name: Hanko Authentication Service |
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,22 @@ | ||
database: | ||
user: hanko | ||
password: hanko | ||
host: localhost | ||
port: 5432 | ||
dialect: postgres | ||
smtp: | ||
host: smtp1.example.com | ||
user: example1 | ||
password: example1 | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
host: smtp2.example.com | ||
user: example2 | ||
password: example2 | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
service: | ||
name: Hanko Authentication Service |
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 |
---|---|---|
|
@@ -16,11 +16,11 @@ var DefaultConfig = config.Config{ | |
Secrets: config.Secrets{ | ||
Keys: []string{"abcdefghijklmnop"}, | ||
}, | ||
Smtp: config.SMTP{ | ||
Host: "localhost", | ||
Port: "2500", | ||
}, | ||
Passcode: config.Passcode{ | ||
Smtp: config.SMTP{ | ||
Host: "localhost", | ||
Port: "2500", | ||
}, | ||
Email: config.Email{ | ||
FromAddress: "[email protected]", | ||
FromName: "Hanko Test", | ||
|
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 |
---|---|---|
|
@@ -4,12 +4,12 @@ database: | |
host: postgresd | ||
port: 5432 | ||
dialect: postgres | ||
smtp: | ||
host: "mailslurper" | ||
port: "2500" | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
host: "mailslurper" | ||
port: "2500" | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
|
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 |
---|---|---|
|
@@ -4,12 +4,12 @@ database: | |
host: postgresd | ||
port: 5432 | ||
dialect: postgres | ||
smtp: | ||
host: "mailslurper" | ||
port: "2500" | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
host: "mailslurper" | ||
port: "2500" | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
|
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 |
---|---|---|
|
@@ -4,12 +4,12 @@ database: | |
host: postgresd | ||
port: 5432 | ||
dialect: postgres | ||
smtp: | ||
host: "mailslurper" | ||
port: "2500" | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
host: "mailslurper" | ||
port: "2500" | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
|
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 |
---|---|---|
|
@@ -4,12 +4,12 @@ database: | |
host: postgres | ||
port: 5432 | ||
dialect: postgres | ||
smtp: | ||
host: "mailhog" | ||
port: "2500" | ||
passcode: | ||
email: | ||
from_address: [email protected] | ||
smtp: | ||
host: "mailhog" | ||
port: "2500" | ||
secrets: | ||
keys: | ||
- abcedfghijklmnopqrstuvwxyz | ||
|
@@ -40,4 +40,4 @@ third_party: | |
github: | ||
enabled: true | ||
apple: | ||
enabled: true | ||
enabled: true |
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 |
---|---|---|
@@ -1 +1 @@ | ||
v16.15.1 | ||
v18.6.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning message is wrong, the root smtp settings will be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you. Updated.