github.com/tonnydourado/packer@v0.6.1-0.20140701134019-5d0cd9676a37/builder/null/config.go (about) 1 package null 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/packer/common" 6 "github.com/mitchellh/packer/packer" 7 ) 8 9 type Config struct { 10 common.PackerConfig `mapstructure:",squash"` 11 12 Host string `mapstructure:"host"` 13 Port int `mapstructure:"port"` 14 SSHUsername string `mapstructure:"ssh_username"` 15 SSHPassword string `mapstructure:"ssh_password"` 16 SSHPrivateKeyFile string `mapstructure:"ssh_private_key_file"` 17 18 tpl *packer.ConfigTemplate 19 } 20 21 func NewConfig(raws ...interface{}) (*Config, []string, error) { 22 c := new(Config) 23 md, err := common.DecodeConfig(c, raws...) 24 if err != nil { 25 return nil, nil, err 26 } 27 28 c.tpl, err = packer.NewConfigTemplate() 29 if err != nil { 30 return nil, nil, err 31 } 32 33 c.tpl.UserVars = c.PackerUserVars 34 35 // Defaults 36 if c.Port == 0 { 37 c.Port = 22 38 } 39 // (none so far) 40 41 errs := common.CheckUnusedConfig(md) 42 43 if c.Host == "" { 44 errs = packer.MultiErrorAppend(errs, 45 fmt.Errorf("host must be specified")) 46 } 47 48 if c.SSHUsername == "" { 49 errs = packer.MultiErrorAppend(errs, 50 fmt.Errorf("ssh_username must be specified")) 51 } 52 53 if c.SSHPassword == "" && c.SSHPrivateKeyFile == "" { 54 errs = packer.MultiErrorAppend(errs, 55 fmt.Errorf("one of ssh_password and ssh_private_key_file must be specified")) 56 } 57 58 if c.SSHPassword != "" && c.SSHPrivateKeyFile != "" { 59 errs = packer.MultiErrorAppend(errs, 60 fmt.Errorf("only one of ssh_password and ssh_private_key_file must be specified")) 61 } 62 63 if errs != nil && len(errs.Errors) > 0 { 64 return nil, nil, errs 65 } 66 67 return c, nil, nil 68 }