github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/fix/fixer_sshdisableagent.go (about) 1 package fix 2 3 import ( 4 "github.com/mitchellh/mapstructure" 5 ) 6 7 // FixerSSHDisableAgent changes the "ssh_disable_agent" of a template 8 // to "ssh_disable_agent_forwarding". 9 type FixerSSHDisableAgent struct{} 10 11 func (FixerSSHDisableAgent) Fix(input map[string]interface{}) (map[string]interface{}, error) { 12 // The type we'll decode into; we only care about builders 13 type template struct { 14 Builders []map[string]interface{} 15 } 16 17 // Decode the input into our structure, if we can 18 var tpl template 19 if err := mapstructure.Decode(input, &tpl); err != nil { 20 return nil, err 21 } 22 23 for _, builder := range tpl.Builders { 24 sshDisableAgentRaw, ok := builder["ssh_disable_agent"] 25 if !ok { 26 continue 27 } 28 29 sshDisableAgent, ok := sshDisableAgentRaw.(bool) 30 if !ok { 31 continue 32 } 33 34 // only assign to ssh_disable_agent_forwarding if it doesn't 35 // already exist; otherwise we'll just ignore ssh_disable_agent 36 _, sshDisableAgentIncluded := builder["ssh_disable_agent_forwarding"] 37 if !sshDisableAgentIncluded { 38 builder["ssh_disable_agent_forwarding"] = sshDisableAgent 39 } 40 41 delete(builder, "ssh_disable_agent") 42 } 43 44 input["builders"] = tpl.Builders 45 return input, nil 46 } 47 48 func (FixerSSHDisableAgent) Synopsis() string { 49 return `Updates builders using "ssh_disable_agent" to use "ssh_disable_agent_forwarding"` 50 }