aboutsummaryrefslogtreecommitdiffstats
path: root/config/accounts.go
diff options
context:
space:
mode:
Diffstat (limited to 'config/accounts.go')
-rw-r--r--config/accounts.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/config/accounts.go b/config/accounts.go
index 5bbae39f..35046f67 100644
--- a/config/accounts.go
+++ b/config/accounts.go
@@ -1,6 +1,7 @@
package config
import (
+ "bytes"
"errors"
"fmt"
"net/url"
@@ -18,6 +19,12 @@ import (
"github.com/go-ini/ini"
)
+var (
+ EnablePinentry func()
+ DisablePinentry func()
+ SetPinentryEnv func(*exec.Cmd)
+)
+
type RemoteConfig struct {
Value string
PasswordCmd string
@@ -52,11 +59,26 @@ func (c *RemoteConfig) ConnectionString() (string, error) {
pw := c.cache
if pw == "" {
+ usePinentry := EnablePinentry != nil &&
+ DisablePinentry != nil &&
+ SetPinentryEnv != nil
+
cmd := exec.Command("sh", "-c", c.PasswordCmd)
cmd.Stdin = os.Stdin
+
+ buf := new(bytes.Buffer)
+ cmd.Stderr = buf
+
+ if usePinentry {
+ EnablePinentry()
+ defer DisablePinentry()
+ SetPinentryEnv(cmd)
+ }
+
output, err := cmd.Output()
if err != nil {
- return "", fmt.Errorf("failed to read password: %w", err)
+ return "", fmt.Errorf("failed to read password: %v: %w",
+ buf.String(), err)
}
pw = strings.TrimSpace(string(output))
}