diff options
author | Kalyan Sriram <kalyan@coderkalyan.com> | 2021-10-22 18:30:50 +0000 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-10-22 20:55:45 +0200 |
commit | 36a7d1eead5e8c731dad4d2053595ca8bfcd509a (patch) | |
tree | a6f0568cd4ef2e8e8e3e9cc419d381beea1ff28b /config.go | |
parent | Rework vertical lists (diff) |
config: allow specifying an external password cmd
Storing passwords in plaintext in your configuration file is dangerous!
This patch adds support for fetching a password from an external
command (i.e. `gpg`, `pass`, `gopass`).
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/ioutil" + "os/exec" "strconv" "strings" @@ -47,13 +48,14 @@ func (c *Color) UnmarshalText(data []byte) error { } type Config struct { - Addr string - Nick string - Real string - User string - Password *string - NoTLS bool `yaml:"no-tls"` - Channels []string + Addr string + Nick string + Real string + User string + Password *string + PasswordCmd string `yaml:"password-cmd"` + NoTLS bool `yaml:"no-tls"` + Channels []string NoTypings bool `yaml:"no-typings"` Mouse *bool @@ -88,6 +90,13 @@ func ParseConfig(buf []byte) (cfg Config, err error) { if cfg.Real == "" { cfg.Real = cfg.Nick } + if cfg.PasswordCmd != "" { + password, err := runPasswordCmd(cfg.PasswordCmd) + if err != nil { + return cfg, err + } + cfg.Password = &password + } if cfg.NickColWidth <= 0 { cfg.NickColWidth = 16 } @@ -114,3 +123,13 @@ func LoadConfigFile(filename string) (cfg Config, err error) { } return } + +func runPasswordCmd(command string) (password string, err error) { + cmd := exec.Command("sh", "-c", command) + stdout, err := cmd.Output() + if err == nil { + password = strings.TrimSuffix(string(stdout), "\n") + } + + return +} |