Permalink
Browse files

Make null builder actually have the ability to do nothing

  • Loading branch information...
anish authored and mwhooker committed Mar 5, 2017
1 parent a583b18 commit ff3982773334241e4beff7633b248ce185b0d796
Showing with 39 additions and 28 deletions.
  1. +18 −11 builder/null/builder.go
  2. +21 −17 builder/null/config.go
@@ -27,19 +27,26 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
steps := []multistep.Step{
&communicator.StepConnect{
Config: &b.config.CommConfig,
Host: CommHost(b.config.CommConfig.Host()),
SSHConfig: SSHConfig(
b.config.CommConfig.SSHAgentAuth,
b.config.CommConfig.SSHUsername,
b.config.CommConfig.SSHPassword,
b.config.CommConfig.SSHPrivateKey),
},
&common.StepProvision{},
steps := []multistep.Step{}
if b.config.CommConfig.Type != "none" {
steps = append(steps,
&communicator.StepConnect{
Config: &b.config.CommConfig,
Host: CommHost(b.config.CommConfig.Host()),
SSHConfig: SSHConfig(
b.config.CommConfig.SSHAgentAuth,
b.config.CommConfig.SSHUsername,
b.config.CommConfig.SSHPassword,
b.config.CommConfig.SSHPrivateKey),
},
)
}
steps = append(steps,
new(common.StepProvision),
)
// Setup the state bag and initial state for the steps
state := new(multistep.BasicStateBag)
state.Put("config", b.config)
@@ -31,26 +31,30 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
if es := c.CommConfig.Prepare(nil); len(es) > 0 {
errs = packer.MultiErrorAppend(errs, es...)
}
if c.CommConfig.Host() == "" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("a Host must be specified, please reference your communicator documentation"))
}
if c.CommConfig.User() == "" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("a Username must be specified, please reference your communicator documentation"))
}
if c.CommConfig.Type != "none" {
if c.CommConfig.Host() == "" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("a Host must be specified, please reference your communicator documentation"))
}
if !c.CommConfig.SSHAgentAuth && c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKey == "" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("one authentication method must be specified, please reference your communicator documentation"))
}
if c.CommConfig.User() == "" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("a Username must be specified, please reference your communicator documentation"))
}
if !c.CommConfig.SSHAgentAuth && c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKey == "" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("one authentication method must be specified, please reference your communicator documentation"))
}
if (c.CommConfig.SSHAgentAuth &&
(c.CommConfig.SSHPassword != "" || c.CommConfig.SSHPrivateKey != "")) ||
(c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "") {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("only one of ssh_agent_auth, ssh_password, and ssh_private_key_file must be specified"))
if (c.CommConfig.SSHAgentAuth &&
(c.CommConfig.SSHPassword != "" || c.CommConfig.SSHPrivateKey != "")) ||
(c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "") {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("only one of ssh_agent_auth, ssh_password, and ssh_private_key_file must be specified"))
}
}
if errs != nil && len(errs.Errors) > 0 {

0 comments on commit ff39827

Please sign in to comment.