Skip to content

Commit

Permalink
Make null builder actually have the ability to do nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
anish authored and mwhooker committed Jun 8, 2017
1 parent a583b18 commit ff39827
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
29 changes: 18 additions & 11 deletions builder/null/builder.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
steps := []multistep.Step{ steps := []multistep.Step{}
&communicator.StepConnect{
Config: &b.config.CommConfig, if b.config.CommConfig.Type != "none" {
Host: CommHost(b.config.CommConfig.Host()), steps = append(steps,
SSHConfig: SSHConfig( &communicator.StepConnect{
b.config.CommConfig.SSHAgentAuth, Config: &b.config.CommConfig,
b.config.CommConfig.SSHUsername, Host: CommHost(b.config.CommConfig.Host()),
b.config.CommConfig.SSHPassword, SSHConfig: SSHConfig(
b.config.CommConfig.SSHPrivateKey), b.config.CommConfig.SSHAgentAuth,
}, b.config.CommConfig.SSHUsername,
&common.StepProvision{}, b.config.CommConfig.SSHPassword,
b.config.CommConfig.SSHPrivateKey),
},
)
} }


steps = append(steps,
new(common.StepProvision),
)

// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("config", b.config) state.Put("config", b.config)
Expand Down
38 changes: 21 additions & 17 deletions builder/null/config.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,26 +31,30 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
if es := c.CommConfig.Prepare(nil); len(es) > 0 { if es := c.CommConfig.Prepare(nil); len(es) > 0 {
errs = packer.MultiErrorAppend(errs, es...) 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() == "" { if c.CommConfig.Type != "none" {
errs = packer.MultiErrorAppend(errs, if c.CommConfig.Host() == "" {
fmt.Errorf("a Username must be specified, please reference your communicator documentation")) 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 == "" { if c.CommConfig.User() == "" {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("one authentication method must be specified, please reference your communicator documentation")) 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 { if errs != nil && len(errs.Errors) > 0 {
Expand Down

0 comments on commit ff39827

Please sign in to comment.