From 0d2fa223f2315ce80d2f841f25a67cd24971ab0b Mon Sep 17 00:00:00 2001 From: Mark Peek Date: Fri, 23 Oct 2015 16:51:03 -0700 Subject: [PATCH] builder/vmware-esxi: hide password in ovftool command --- builder/vmware/iso/step_export.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index 8c1ed1b93..ed4db4896 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -17,6 +17,20 @@ type StepExport struct { 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 { c := state.Get("config").(*Config) ui := state.Get("ui").(packer.Ui) @@ -44,18 +58,10 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { 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.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 - cmd := exec.Command(ovftool, args...) + cmd := exec.Command(ovftool, s.generateArgs(c, outputPath, false)...) cmd.Stdout = &out if err := cmd.Run(); err != nil { err := fmt.Errorf("Error exporting virtual machine: %s\n%s\n", err, out.String())