From abcc02dc6415e115dc8901f72e501052a538ed25 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 24 Oct 2017 11:38:56 -0700 Subject: [PATCH] filter password from logs --- post-processor/vsphere/post-processor.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index 2f3dc6c731c..c028cd0870b 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -129,25 +129,25 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ui.Message(fmt.Sprintf("Uploading %s to vSphere", source)) - log.Printf("Starting ovftool with parameters: %s", - strings.Replace( - strings.Join(args, " "), - password, - "", - -1)) + log.Printf("Starting ovftool with parameters: %s", p.filterLog(strings.Join(args, " "))) var out bytes.Buffer cmd := exec.Command("ovftool", args...) cmd.Stdout = &out if err := cmd.Run(); err != nil { - return nil, false, fmt.Errorf("Failed: %s\n%s\n", err, out.String()) + return nil, false, fmt.Errorf("Failed: %s\n%s\n", err, p.filterLog(out.String())) } - ui.Message(out.String()) + ui.Message(p.filterLog(out.String())) return artifact, false, nil } +func (p *PostProcessor) filterLog(s string) string { + password := url.QueryEscape(p.config.Password) + return strings.Replace(s, password, "", -1) +} + func (p *PostProcessor) BuildArgs(source, ovftool_uri string) ([]string, error) { args := []string{ "--acceptAllEulas",