Skip to content

Commit 3cba391

Browse files
committed
pass: add IsInitialized helper
This will be useful for the cli where they check initialization: https://github.com/docker/cli/blob/be8dab26a3ab589b96788fdb95f3d07378e57b9b/cli/config/credentials/default_store_linux.go#L8-L10 Signed-off-by: Euan Kemp <[email protected]> Signed-off-by: Vincent Demeester <[email protected]>
1 parent 5da09fd commit 3cba391

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pass/pass_linux.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package pass
66

77
import (
8+
"bytes"
89
"encoding/base64"
910
"errors"
1011
"fmt"
@@ -32,6 +33,13 @@ type Pass struct{}
3233
var initializationMutex sync.Mutex
3334
var passInitialized bool
3435

36+
// CheckInitialized checks whether the password helper can be used. It
37+
// internally caches and so may be safely called multiple times with no impact
38+
// on performance, though the first call may take longer.
39+
func (p Pass) CheckInitialized() bool {
40+
return p.checkInitialized() == nil
41+
}
42+
3543
func (p Pass) checkInitialized() error {
3644
initializationMutex.Lock()
3745
defer initializationMutex.Unlock()
@@ -70,8 +78,9 @@ func (p Pass) runPass(stdinContent string, args ...string) (string, error) {
7078
}
7179

7280
func (p Pass) runPassHelper(stdinContent string, args ...string) (string, error) {
81+
var stdout, stderr bytes.Buffer
7382
cmd := exec.Command("pass", args...)
74-
cmd.Stdin = strings.NewReader(stdin)
83+
cmd.Stdin = strings.NewReader(stdinContent)
7584
cmd.Stdout = &stdout
7685
cmd.Stderr = &stderr
7786

0 commit comments

Comments
 (0)