From 3cba3913eada215d452d2eb2e11b82c3f8006aae Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Wed, 27 Jun 2018 14:28:47 +0200 Subject: [PATCH] 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 Signed-off-by: Vincent Demeester --- pass/pass_linux.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pass/pass_linux.go b/pass/pass_linux.go index 3ab6081..d9bace9 100644 --- a/pass/pass_linux.go +++ b/pass/pass_linux.go @@ -5,6 +5,7 @@ package pass import ( + "bytes" "encoding/base64" "errors" "fmt" @@ -32,6 +33,13 @@ type Pass struct{} var initializationMutex sync.Mutex var passInitialized bool +// CheckInitialized checks whether the password helper can be used. It +// internally caches and so may be safely called multiple times with no impact +// on performance, though the first call may take longer. +func (p Pass) CheckInitialized() bool { + return p.checkInitialized() == nil +} + func (p Pass) checkInitialized() error { initializationMutex.Lock() defer initializationMutex.Unlock() @@ -70,8 +78,9 @@ func (p Pass) runPass(stdinContent string, args ...string) (string, error) { } func (p Pass) runPassHelper(stdinContent string, args ...string) (string, error) { + var stdout, stderr bytes.Buffer cmd := exec.Command("pass", args...) - cmd.Stdin = strings.NewReader(stdin) + cmd.Stdin = strings.NewReader(stdinContent) cmd.Stdout = &stdout cmd.Stderr = &stderr