1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30

A new entry point for calling the cred helpers that allow passing environment variables

Signed-off-by: Peter Hsu <shhsu@microsoft.com>
This commit is contained in:
Peter Hsu
2017-05-31 12:33:29 -07:00
parent a8de4f6e8a
commit c69c0725bb
+17 -5
View File
@@ -1,6 +1,7 @@
package client
import (
"fmt"
"io"
"os"
"os/exec"
@@ -17,15 +18,26 @@ type ProgramFunc func(args ...string) Program
// NewShellProgramFunc creates programs that are executed in a Shell.
func NewShellProgramFunc(name string) ProgramFunc {
return NewShellProgramFuncWithEnv(name, nil)
}
// NewShellProgramFuncWithEnv creates programs that are executed in a Shell with environment variables
func NewShellProgramFuncWithEnv(name string, env *map[string]string) ProgramFunc {
return func(args ...string) Program {
return &Shell{cmd: newCmdRedirectErr(name, args)}
return &Shell{cmd: createProgramCmdRedirectErr(name, args, env)}
}
}
func newCmdRedirectErr(name string, args []string) *exec.Cmd {
newCmd := exec.Command(name, args...)
newCmd.Stderr = os.Stderr
return newCmd
func createProgramCmdRedirectErr(commandName string, args []string, env *map[string]string) *exec.Cmd {
programCmd := exec.Command(commandName, args...)
programCmd.Env = os.Environ()
if env != nil {
for k, v := range *env {
programCmd.Env = append(programCmd.Env, fmt.Sprintf("%s=%s", k, v))
}
}
programCmd.Stderr = os.Stderr
return programCmd
}
// Shell invokes shell commands to talk with a remote credentials helper.