github.com/hashicorp/packer@v1.14.3/fix/fixer_iso_md5.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fix 5 6 import ( 7 "github.com/mitchellh/mapstructure" 8 ) 9 10 // FixerISOMD5 is a Fixer that replaces the "iso_md5" configuration key 11 // with the newer "iso_checksum" and "iso_checksum_type" within builders. 12 type FixerISOMD5 struct{} 13 14 func (FixerISOMD5) DeprecatedOptions() map[string][]string { 15 return map[string][]string{ 16 "*": []string{"iso_md5"}, 17 } 18 } 19 20 func (FixerISOMD5) Fix(input map[string]interface{}) (map[string]interface{}, error) { 21 // Our template type we'll use for this fixer only 22 type template struct { 23 Builders []map[string]interface{} 24 } 25 26 // Decode the input into our structure, if we can 27 var tpl template 28 if err := mapstructure.Decode(input, &tpl); err != nil { 29 return nil, err 30 } 31 32 // Go through each builder and replace the iso_md5 if we can 33 for _, builder := range tpl.Builders { 34 md5raw, ok := builder["iso_md5"] 35 if !ok { 36 continue 37 } 38 39 md5, ok := md5raw.(string) 40 if !ok { 41 // TODO: error? 42 continue 43 } 44 45 delete(builder, "iso_md5") 46 builder["iso_checksum"] = md5 47 builder["iso_checksum_type"] = "md5" 48 } 49 50 input["builders"] = tpl.Builders 51 return input, nil 52 } 53 54 func (FixerISOMD5) Synopsis() string { 55 return `Replaces "iso_md5" in builders with "iso_checksum"` 56 }