post-processor/vagrant: fix output ConfigTemplate validation [GH-324]

-apply same output validation steps found in builder specific Configure
functions
This commit is contained in:
Jason A. Beranek 2013-08-22 20:19:03 -05:00
parent 251abc3496
commit 0e3365782a
1 changed files with 20 additions and 9 deletions

View File

@ -6,9 +6,9 @@ package vagrant
import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
"text/template"
)
var builtins = map[string]string{
@ -18,6 +18,8 @@ var builtins = map[string]string{
}
type Config struct {
common.PackerConfig `mapstructure:",squash"`
OutputPath string `mapstructure:"output"`
}
@ -31,22 +33,31 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
// Store the raw configs for usage later
p.rawConfigs = raws
for _, raw := range raws {
err := mapstructure.Decode(raw, &p.config)
if err != nil {
return err
}
md, err := common.DecodeConfig(&p.config, raws...)
if err != nil {
return err
}
tpl, err := packer.NewConfigTemplate()
if err != nil {
return err
}
tpl.UserVars = p.config.PackerUserVars
// Accumulate any errors
errs := common.CheckUnusedConfig(md)
ppExtraConfig := make(map[string]interface{})
if p.config.OutputPath == "" {
p.config.OutputPath = "packer_{{ .BuildName }}_{{.Provider}}.box"
ppExtraConfig["output"] = p.config.OutputPath
}
_, err := template.New("output").Parse(p.config.OutputPath)
if err != nil {
return fmt.Errorf("output invalid template: %s", err)
// _, err := template.New("output").Parse(p.config.OutputPath)
if err := tpl.Validate(p.config.OutputPath); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing output template: %s", err))
return errs
}
// Store the extra configuration for post-processors