Skip to content
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

feat: add password_file option #83

Merged
merged 1 commit into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
sweenu marked this conversation as resolved.
Show resolved Hide resolved
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(".", "_")
sweenu marked this conversation as resolved.
Show resolved Hide resolved
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()

// global defaults
Expand Down