builder/vmware-esxi: hide password in ovftool command
This commit is contained in:
parent
9d0c443ca2
commit
0d2fa223f2
|
@ -17,6 +17,20 @@ type StepExport struct {
|
||||||
Format string
|
Format string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StepExport) generateArgs(c *Config, outputPath string, hidePassword bool) []string {
|
||||||
|
password := url.QueryEscape(c.RemotePassword)
|
||||||
|
if hidePassword {
|
||||||
|
password = "****"
|
||||||
|
}
|
||||||
|
return []string{
|
||||||
|
"--noSSLVerify=true",
|
||||||
|
"--skipManifestCheck",
|
||||||
|
"-tt=" + s.Format,
|
||||||
|
"vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + c.VMName,
|
||||||
|
outputPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
c := state.Get("config").(*Config)
|
c := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
@ -44,18 +58,10 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
os.MkdirAll(outputPath, 0755)
|
os.MkdirAll(outputPath, 0755)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
|
||||||
"--noSSLVerify=true",
|
|
||||||
"--skipManifestCheck",
|
|
||||||
"-tt=" + s.Format,
|
|
||||||
"vi://" + c.RemoteUser + ":" + url.QueryEscape(c.RemotePassword) + "@" + c.RemoteHost + "/" + c.VMName,
|
|
||||||
outputPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.Say("Exporting virtual machine...")
|
ui.Say("Exporting virtual machine...")
|
||||||
ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(args, " ")))
|
ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(s.generateArgs(c, outputPath, true), " ")))
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd := exec.Command(ovftool, args...)
|
cmd := exec.Command(ovftool, s.generateArgs(c, outputPath, false)...)
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
err := fmt.Errorf("Error exporting virtual machine: %s\n%s\n", err, out.String())
|
err := fmt.Errorf("Error exporting virtual machine: %s\n%s\n", err, out.String())
|
||||||
|
|
Loading…
Reference in New Issue