summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-10-31 15:46:23 +0100
committerLibravatar GitHub <noreply@github.com>2021-10-31 15:46:23 +0100
commit2aaec827321ec711b98e13335899cf750f270105 (patch)
treebafa15a0c2a469adf97b2c437fdc31428516424e /internal/config/config.go
parentregenerate swagger docs (#293) (diff)
downloadgotosocial-2aaec827321ec711b98e13335899cf750f270105.tar.xz
smtp + email confirmation (#285)
* add smtp configuration * add email confirm + reset templates * add email sender to testrig * flesh out the email sender interface * go fmt * golint * update from field with more clarity * tidy up the email formatting * fix tests * add email sender to processor * tidy client api processing a bit * further tidying in fromClientAPI * pin new account to user * send msg to processor on new account creation * generate confirm email uri * remove emailer from account processor again * add processCreateAccountFromClientAPI * move emailer accountprocessor => userprocessor * add email sender to user processor * SendConfirmEmail function * add noop email sender * use noop email sender in tests * only assemble message if callback is not nil * use noop email sender if no smtp host is defined * minify email html before sending * fix wrong email address * email confirm test * fmt * serve web hndler * add email confirm handler * init test log properly on testrig * log emails that *would* have been sent * go fmt ./... * unexport confirm email handler * updatedAt * test confirm email function * don't allow tokens older than 7 days * change error message a bit * add basic smtp docs * add a few more snippets * typo * add email sender to outbox tests * don't use dutch wikipedia link * don't minify email html
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index bb789b7d2..7a3a92af9 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -63,6 +63,7 @@ type Config struct {
StatusesConfig *StatusesConfig `yaml:"statuses"`
LetsEncryptConfig *LetsEncryptConfig `yaml:"letsEncrypt"`
OIDCConfig *OIDCConfig `yaml:"oidc"`
+ SMTPConfig *SMTPConfig `yaml:"smtp"`
/*
Not parsed from .yaml configuration file.
@@ -95,6 +96,7 @@ func Empty() *Config {
StatusesConfig: &StatusesConfig{},
LetsEncryptConfig: &LetsEncryptConfig{},
OIDCConfig: &OIDCConfig{},
+ SMTPConfig: &SMTPConfig{},
AccountCLIFlags: make(map[string]string),
ExportCLIFlags: make(map[string]string),
}
@@ -318,6 +320,27 @@ func (c *Config) ParseCLIFlags(f KeyedFlags, version string) error {
c.OIDCConfig.Scopes = f.StringSlice(fn.OIDCScopes)
}
+ // smtp flags
+ if c.SMTPConfig.Host == "" || f.IsSet(fn.SMTPHost) {
+ c.SMTPConfig.Host = f.String(fn.SMTPHost)
+ }
+
+ if c.SMTPConfig.Port == 0 || f.IsSet(fn.SMTPPort) {
+ c.SMTPConfig.Port = f.Int(fn.SMTPPort)
+ }
+
+ if c.SMTPConfig.Username == "" || f.IsSet(fn.SMTPUsername) {
+ c.SMTPConfig.Username = f.String(fn.SMTPUsername)
+ }
+
+ if c.SMTPConfig.Password == "" || f.IsSet(fn.SMTPPassword) {
+ c.SMTPConfig.Password = f.String(fn.SMTPPassword)
+ }
+
+ if c.SMTPConfig.From == "" || f.IsSet(fn.SMTPFrom) {
+ c.SMTPConfig.From = f.String(fn.SMTPFrom)
+ }
+
// command-specific flags
// admin account CLI flags
@@ -399,6 +422,12 @@ type Flags struct {
OIDCClientID string
OIDCClientSecret string
OIDCScopes string
+
+ SMTPHost string
+ SMTPPort string
+ SMTPUsername string
+ SMTPPassword string
+ SMTPFrom string
}
// Defaults contains all the default values for a gotosocial config
@@ -458,6 +487,12 @@ type Defaults struct {
OIDCClientID string
OIDCClientSecret string
OIDCScopes []string
+
+ SMTPHost string
+ SMTPPort int
+ SMTPUsername string
+ SMTPPassword string
+ SMTPFrom string
}
// GetFlagNames returns a struct containing the names of the various flags used for
@@ -518,6 +553,12 @@ func GetFlagNames() Flags {
OIDCClientID: "oidc-client-id",
OIDCClientSecret: "oidc-client-secret",
OIDCScopes: "oidc-scopes",
+
+ SMTPHost: "smtp-host",
+ SMTPPort: "smtp-port",
+ SMTPUsername: "smtp-username",
+ SMTPPassword: "smtp-password",
+ SMTPFrom: "smtp-from",
}
}
@@ -579,5 +620,11 @@ func GetEnvNames() Flags {
OIDCClientID: "GTS_OIDC_CLIENT_ID",
OIDCClientSecret: "GTS_OIDC_CLIENT_SECRET",
OIDCScopes: "GTS_OIDC_SCOPES",
+
+ SMTPHost: "SMTP_HOST",
+ SMTPPort: "SMTP_PORT",
+ SMTPUsername: "SMTP_USERNAME",
+ SMTPPassword: "SMTP_PASSWORD",
+ SMTPFrom: "SMTP_FROM",
}
}