github.com/hashicorp/packer@v1.14.3/fix/fixer_docker_email.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fix 5 6 import "github.com/mitchellh/mapstructure" 7 8 type FixerDockerEmail struct{} 9 10 func (FixerDockerEmail) DeprecatedOptions() map[string][]string { 11 return map[string][]string{ 12 "packer.docker": []string{"login_email"}, 13 "packer.post-processor.docker-import": []string{"login_email"}, 14 } 15 16 } 17 18 func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{}, error) { 19 if input["post-processors"] == nil { 20 return input, nil 21 } 22 23 // Our template type we'll use for this fixer only 24 type template struct { 25 Builders []map[string]interface{} 26 PP `mapstructure:",squash"` 27 } 28 29 // Decode the input into our structure, if we can 30 var tpl template 31 if err := mapstructure.Decode(input, &tpl); err != nil { 32 return nil, err 33 } 34 35 // Go through each builder and delete `docker_login` if present 36 for _, builder := range tpl.Builders { 37 _, ok := builder["login_email"] 38 if !ok { 39 continue 40 } 41 delete(builder, "login_email") 42 } 43 44 // Go through each post-processor and delete `docker_login` if present 45 pps := tpl.ppList() 46 47 for _, pp := range pps { 48 _, ok := pp["login_email"] 49 if !ok { 50 continue 51 } 52 delete(pp, "login_email") 53 } 54 55 input["builders"] = tpl.Builders 56 input["post-processors"] = tpl.PostProcessors 57 return input, nil 58 } 59 60 func (FixerDockerEmail) Synopsis() string { 61 return `Removes "login_email" from the Docker builder.` 62 }