From 5ca1e2a23fae99f76b95e236527ac1cc36b6cffa Mon Sep 17 00:00:00 2001 From: Felix Frank Date: Mon, 25 Dec 2017 23:37:18 +0100 Subject: [PATCH] puppet: Avoid empty parameters to puppet mgmtgraph This solves an issue first observed with golang 1.8. Creating an exec.Command with an empty string parameter (when no puppet.conf file is specified) would lead to an error from Puppet, stating that an unexpected argument was passed to "puppet mgmtgraph print". The workaround is to not include *any* positional argument (not even the empty string) when --puppet-conf is not used. --- puppet/puppet.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/puppet/puppet.go b/puppet/puppet.go index c3eb5fde..7bdfe76c 100644 --- a/puppet/puppet.go +++ b/puppet/puppet.go @@ -89,20 +89,21 @@ func runPuppetCommand(cmd *exec.Cmd) ([]byte, error) { // ParseConfigFromPuppet takes a special puppet param string and config and // returns the graph configuration structure. func ParseConfigFromPuppet(puppetParam, puppetConf string) *yamlgraph.GraphConfig { - var puppetConfArg string - if puppetConf != "" { - puppetConfArg = "--config=" + puppetConf + var args []string + if puppetParam == "agent" { + args = []string{"mgmtgraph", "print"} + } else if strings.HasSuffix(puppetParam, ".pp") { + args = []string{"mgmtgraph", "print", "--manifest", puppetParam} + } else { + args = []string{"mgmtgraph", "print", "--code", puppetParam} } - var cmd *exec.Cmd - if puppetParam == "agent" { - cmd = exec.Command("puppet", "mgmtgraph", "print", puppetConfArg) - } else if strings.HasSuffix(puppetParam, ".pp") { - cmd = exec.Command("puppet", "mgmtgraph", "print", puppetConfArg, "--manifest", puppetParam) - } else { - cmd = exec.Command("puppet", "mgmtgraph", "print", puppetConfArg, "--code", puppetParam) + if puppetConf != "" { + args = append(args, "--config="+puppetConf) } + cmd := exec.Command("puppet", args...) + log.Println("Puppet: launching translator") var config yamlgraph.GraphConfig