2013-12-22 19:01:28 -05:00
|
|
|
package fix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FixerVirtualBoxRename changes "virtualbox" builders to "virtualbox-iso"
|
|
|
|
type FixerVirtualBoxRename struct{}
|
|
|
|
|
2020-10-09 20:01:55 -04:00
|
|
|
func (FixerVirtualBoxRename) DeprecatedOptions() map[string][]string {
|
|
|
|
return map[string][]string{}
|
2020-05-28 17:37:29 -04:00
|
|
|
}
|
|
|
|
|
2013-12-22 19:01:28 -05:00
|
|
|
func (FixerVirtualBoxRename) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
|
|
|
type template struct {
|
2015-06-13 16:39:12 -04:00
|
|
|
Builders []map[string]interface{}
|
|
|
|
Provisioners []interface{}
|
2013-12-22 19:01:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the input into our structure, if we can
|
|
|
|
var tpl template
|
2015-06-13 16:39:12 -04:00
|
|
|
if err := mapstructure.WeakDecode(input, &tpl); err != nil {
|
2013-12-22 19:01:28 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, builder := range tpl.Builders {
|
|
|
|
builderTypeRaw, ok := builder["type"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
builderType, ok := builderTypeRaw.(string)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if builderType != "virtualbox" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
builder["type"] = "virtualbox-iso"
|
|
|
|
}
|
|
|
|
|
2015-06-13 16:39:12 -04:00
|
|
|
for i, raw := range tpl.Provisioners {
|
|
|
|
var m map[string]interface{}
|
|
|
|
if err := mapstructure.WeakDecode(raw, &m); err != nil {
|
|
|
|
// Ignore errors, could be a non-map
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
raw, ok := m["override"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var override map[string]interface{}
|
|
|
|
if err := mapstructure.WeakDecode(raw, &override); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if raw, ok := override["virtualbox"]; ok {
|
|
|
|
override["virtualbox-iso"] = raw
|
|
|
|
delete(override, "virtualbox")
|
|
|
|
|
|
|
|
// Set the change
|
|
|
|
m["override"] = override
|
|
|
|
tpl.Provisioners[i] = m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tpl.Builders) > 0 {
|
|
|
|
input["builders"] = tpl.Builders
|
|
|
|
}
|
|
|
|
if len(tpl.Provisioners) > 0 {
|
|
|
|
input["provisioners"] = tpl.Provisioners
|
|
|
|
}
|
2013-12-22 19:01:28 -05:00
|
|
|
return input, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (FixerVirtualBoxRename) Synopsis() string {
|
|
|
|
return `Updates "virtualbox" builders to "virtualbox-iso"`
|
|
|
|
}
|