-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gopass.go
59 lines (45 loc) · 1.07 KB
/
gopass.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"io"
"log"
"os/exec"
)
var defaultGopassGet = func(itemName string) (string, error) {
out, err := exec.Command("gopass", "show", "--password", itemName).Output()
return string(out), err
}
func gopassGetter(itemName string) (string, error) {
return defaultGopassGet(itemName)
}
var gopassWriteCmd = func(itemName string) *exec.Cmd {
return exec.Command("gopass", "insert", "--force", itemName)
}
var defaultGopassSet = func(itemName, secret string) error {
var stdin io.WriteCloser
var err error
var out []byte
cmd := gopassWriteCmd(itemName)
stdin, err = cmd.StdinPipe()
if err != nil {
log.Fatal(err)
return err
}
err = gopassWriteSecret(stdin, secret)
if err != nil {
return err
}
out, err = cmd.CombinedOutput()
if err != nil {
return err
}
log.Print(string(out))
return nil
}
var gopassWriteSecret = func(stdin io.WriteCloser, secret string) error {
defer stdin.Close()
_, err := io.WriteString(stdin, secret)
return err
}
func gopassSetter(itemName, secret string) error {
return defaultGopassSet(itemName, secret)
}