Skip to content

Commit

Permalink
feat: add password_file option
Browse files Browse the repository at this point in the history
  • Loading branch information
sweenu committed Nov 5, 2022
1 parent fa44112 commit e9b3322
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ If you are interested in another platform supported, please open a PR or submit
## Usage

On first run, if it doesn't exist yet, goeland will create a `config.toml` with the default values. You need to adjust the `[email]` section with your SMTP server details.
The config values can also be set with environment variables (e.g. `GOELAND_EMAIL_PASSWORD_FILE=/path/to/pass`).

### Sources

Expand Down Expand Up @@ -172,6 +173,7 @@ host = "smtp.example.com"
port = 25
username = "default"
password = "p4ssw0rd"
# password_file = /run/password/goeland_smtp_pass
encryption = "tls"
allow-insecure = false
authentication = "plain"
Expand Down
11 changes: 11 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ func createEmailPool(config config.Provider) (*email.SMTPClient, error) {
}
user := config.GetString("email.username")
pass := config.GetString("email.password")
passFile := config.GetString("email.password_file")
if len(passFile) > 0 {
if len(pass) > 0 {
log.Warn("Both password and password_file are set. Using password_file.")
}
passFileContent, err := ioutil.ReadFile(passFile)
if err != nil {
return nil, fmt.Errorf("error while reading password file: %v", err)
}
pass = string(passFileContent)
}
//auth := smtp.PlainAuth("", user, pass, host)
server := email.NewSMTPClient()
authentications := map[string]email.AuthType{"none": email.AuthNone, "plain": email.AuthPlain, "login": email.AuthLogin, "crammd5": email.AuthCRAMMD5}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"time"
"strings"

"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -35,6 +36,8 @@ type Provider interface {
// ReadDefaultConfig reads the configuration file
func ReadDefaultConfig(appName string, configName string) {
viper.SetEnvPrefix(appName)
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()

// global defaults
Expand Down

0 comments on commit e9b3322

Please # to comment.