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

Merge pull request #69 from shhsu/command_env

A new entry point for calling the cred helpers that allow passing environment variables
This commit is contained in:
Nassim Eddequiouaq
2017-08-14 11:15:13 +02:00
committed by GitHub
+17 -5
View File
@@ -1,6 +1,7 @@
package client package client
import ( import (
"fmt"
"io" "io"
"os" "os"
"os/exec" "os/exec"
@@ -17,15 +18,26 @@ type ProgramFunc func(args ...string) Program
// NewShellProgramFunc creates programs that are executed in a Shell. // NewShellProgramFunc creates programs that are executed in a Shell.
func NewShellProgramFunc(name string) ProgramFunc { 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 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 { func createProgramCmdRedirectErr(commandName string, args []string, env *map[string]string) *exec.Cmd {
newCmd := exec.Command(name, args...) programCmd := exec.Command(commandName, args...)
newCmd.Stderr = os.Stderr programCmd.Env = os.Environ()
return newCmd 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. // Shell invokes shell commands to talk with a remote credentials helper.