mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 12:27:31 +00:00
fix: always execute cmd in subshell
This commit is contained in:
+24
-12
@@ -161,11 +161,14 @@ func init() {
|
|||||||
|
|
||||||
// Will execute a single command and pass in the given secrets into the process
|
// Will execute a single command and pass in the given secrets into the process
|
||||||
func executeSingleCommandWithEnvs(args []string, secretsCount int, env []string) error {
|
func executeSingleCommandWithEnvs(args []string, secretsCount int, env []string) error {
|
||||||
command := args[0]
|
shell := subShellCmd()
|
||||||
argsForCommand := args[1:]
|
|
||||||
color.Green("Injecting %v Infisical secrets into your application process", secretsCount)
|
color.Green("Injecting %v Infisical secrets into your application process", secretsCount)
|
||||||
|
|
||||||
cmd := exec.Command(command, argsForCommand...)
|
args = append(args[:1], args[0:]...) // shift args to the right
|
||||||
|
args[0] = shell[1]
|
||||||
|
|
||||||
|
cmd := exec.Command(shell[0], args...)
|
||||||
|
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@@ -175,15 +178,7 @@ func executeSingleCommandWithEnvs(args []string, secretsCount int, env []string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func executeMultipleCommandWithEnvs(fullCommand string, secretsCount int, env []string) error {
|
func executeMultipleCommandWithEnvs(fullCommand string, secretsCount int, env []string) error {
|
||||||
shell := [2]string{"sh", "-c"}
|
shell := subShellCmd()
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
shell = [2]string{"cmd", "/C"}
|
|
||||||
} else {
|
|
||||||
currentShell := os.Getenv("SHELL")
|
|
||||||
if currentShell != "" {
|
|
||||||
shell[0] = currentShell
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(shell[0], shell[1], fullCommand)
|
cmd := exec.Command(shell[0], shell[1], fullCommand)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
@@ -197,6 +192,23 @@ func executeMultipleCommandWithEnvs(fullCommand string, secretsCount int, env []
|
|||||||
return execCmd(cmd)
|
return execCmd(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func subShellCmd() [2]string {
|
||||||
|
// default to sh -c
|
||||||
|
shell := [...]string{"sh", "-c"}
|
||||||
|
|
||||||
|
currentShell := os.Getenv("SHELL")
|
||||||
|
if currentShell != "" {
|
||||||
|
shell[0] = currentShell
|
||||||
|
} else if runtime.GOOS == "windows" {
|
||||||
|
// if the SHELL env var is not set and we're on Windows, use cmd.exe
|
||||||
|
// The SHELL var should always be checked first, in case the user executes
|
||||||
|
// infisical from something like Git Bash.
|
||||||
|
return [...]string{"cmd", "/C"}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shell
|
||||||
|
}
|
||||||
|
|
||||||
// Credit: inspired by AWS Valut
|
// Credit: inspired by AWS Valut
|
||||||
func execCmd(cmd *exec.Cmd) error {
|
func execCmd(cmd *exec.Cmd) error {
|
||||||
sigChannel := make(chan os.Signal, 1)
|
sigChannel := make(chan os.Signal, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user