2013-11-09 01:00:57 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-11-12 17:44:02 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/shell-local/localexec"
|
2013-11-09 01:00:57 -05:00
|
|
|
)
|
|
|
|
|
2020-11-19 14:54:31 -05:00
|
|
|
func runAndStream(cmd *exec.Cmd, ui packersdk.Ui) error {
|
2013-11-09 01:00:57 -05:00
|
|
|
|
2017-12-04 08:27:56 -05:00
|
|
|
args := make([]string, len(cmd.Args)-1)
|
|
|
|
copy(args, cmd.Args[1:])
|
|
|
|
|
|
|
|
// Scrub password from the log output.
|
2020-08-27 19:26:42 -04:00
|
|
|
capturedPassword := ""
|
2017-12-04 08:27:56 -05:00
|
|
|
for i, v := range args {
|
|
|
|
if v == "-p" || v == "--password" {
|
2020-08-27 19:26:42 -04:00
|
|
|
capturedPassword = args[i+1]
|
2017-12-04 08:27:56 -05:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 19:26:42 -04:00
|
|
|
// run local command and stream output to UI.
|
|
|
|
return localexec.RunAndStream(cmd, ui, []string{capturedPassword})
|
2013-11-09 01:00:57 -05:00
|
|
|
}
|