mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-14 00:11:28 +05:30
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 <euank@euank.com> Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
+10
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user