forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixer_iso_md5.go
47 lines (38 loc) · 1.06 KB
/
fixer_iso_md5.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package fix
import (
"github.com/mitchellh/mapstructure"
)
// FixerISOMD5 is a Fixer that replaces the "iso_md5" configuration key
// with the newer "iso_checksum" and "iso_checksum_type" within builders.
type FixerISOMD5 struct{}
func (FixerISOMD5) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {
Builders []map[string]interface{}
}
// Decode the input into our structure, if we can
var tpl template
if err := mapstructure.Decode(input, &tpl); err != nil {
return nil, err
}
// Go through each builder and replace the iso_md5 if we can
for _, builder := range tpl.Builders {
md5raw, ok := builder["iso_md5"]
if !ok {
continue
}
md5, ok := md5raw.(string)
if !ok {
// TODO: error?
continue
}
delete(builder, "iso_md5")
builder["iso_checksum"] = md5
builder["iso_checksum_type"] = "md5"
}
input["builders"] = tpl.Builders
return input, nil
}
func (FixerISOMD5) Synopsis() string {
return `Replaces "iso_md5" in builders with "iso_checksum"`
}