github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/command/fix/fixer_iso_md5.go (about) 1 package fix 2 3 import ( 4 "github.com/mitchellh/mapstructure" 5 ) 6 7 // FixerISOMD5 is a Fixer that replaces the "iso_md5" configuration key 8 // with the newer "iso_checksum" and "iso_checksum_type" within builders. 9 type FixerISOMD5 struct{} 10 11 func (FixerISOMD5) Fix(input map[string]interface{}) (map[string]interface{}, error) { 12 // Our template type we'll use for this fixer only 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 // Go through each builder and replace the iso_md5 if we can 24 for _, builder := range tpl.Builders { 25 md5raw, ok := builder["iso_md5"] 26 if !ok { 27 continue 28 } 29 30 md5, ok := md5raw.(string) 31 if !ok { 32 // TODO: error? 33 continue 34 } 35 36 delete(builder, "iso_md5") 37 builder["iso_checksum"] = md5 38 builder["iso_checksum_type"] = "md5" 39 } 40 41 input["builders"] = tpl.Builders 42 return input, nil 43 } 44 45 func (FixerISOMD5) Synopsis() string { 46 return `Replaces "iso_md5" in builders with "iso_checksum"` 47 }