fix docker email fixer
Fixing post-processors requires some smart parsing of the template. Let's turn that logic into a helper and use it everywhere.
This commit is contained in:
parent
cc5c2fb100
commit
42910a5f8c
@ -7,8 +7,8 @@ type FixerDockerEmail struct{}
|
|||||||
func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
||||||
// Our template type we'll use for this fixer only
|
// Our template type we'll use for this fixer only
|
||||||
type template struct {
|
type template struct {
|
||||||
Builders []map[string]interface{}
|
Builders []map[string]interface{}
|
||||||
PostProcessors []map[string]interface{} `mapstructure:"post-processors"`
|
PP `mapstructure:",squash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the input into our structure, if we can
|
// Decode the input into our structure, if we can
|
||||||
@ -27,7 +27,9 @@ func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go through each post-processor and delete `docker_login` if present
|
// Go through each post-processor and delete `docker_login` if present
|
||||||
for _, pp := range tpl.PostProcessors {
|
pps := tpl.postProcessors()
|
||||||
|
|
||||||
|
for _, pp := range pps {
|
||||||
_, ok := pp["login_email"]
|
_, ok := pp["login_email"]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
@ -36,7 +38,7 @@ func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
input["builders"] = tpl.Builders
|
input["builders"] = tpl.Builders
|
||||||
input["post-processors"] = tpl.PostProcessors
|
input["post-processors"] = pps
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]inter
|
|||||||
|
|
||||||
// Our template type we'll use for this fixer only
|
// Our template type we'll use for this fixer only
|
||||||
type template struct {
|
type template struct {
|
||||||
PostProcessors []interface{} `mapstructure:"post-processors"`
|
PP `mapstructure:",squash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the input into our structure, if we can
|
// Decode the input into our structure, if we can
|
||||||
@ -21,20 +21,7 @@ func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go through each post-processor and get out all the complex configs
|
// Go through each post-processor and get out all the complex configs
|
||||||
pps := make([]map[string]interface{}, 0, len(tpl.PostProcessors))
|
pps := tpl.postProcessors()
|
||||||
for _, rawPP := range tpl.PostProcessors {
|
|
||||||
switch pp := rawPP.(type) {
|
|
||||||
case string:
|
|
||||||
case map[string]interface{}:
|
|
||||||
pps = append(pps, pp)
|
|
||||||
case []interface{}:
|
|
||||||
for _, innerRawPP := range pp {
|
|
||||||
if innerPP, ok := innerRawPP.(map[string]interface{}); ok {
|
|
||||||
pps = append(pps, innerPP)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, pp := range pps {
|
for _, pp := range pps {
|
||||||
ppTypeRaw, ok := pp["type"]
|
ppTypeRaw, ok := pp["type"]
|
||||||
@ -60,7 +47,7 @@ func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]inter
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input["post-processors"] = tpl.PostProcessors
|
input["post-processors"] = pps
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ type FixerVagrantPPOverride struct{}
|
|||||||
func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
||||||
// Our template type we'll use for this fixer only
|
// Our template type we'll use for this fixer only
|
||||||
type template struct {
|
type template struct {
|
||||||
PostProcessors []interface{} `mapstructure:"post-processors"`
|
PP `mapstructure:",squash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the input into our structure, if we can
|
// Decode the input into our structure, if we can
|
||||||
@ -21,21 +21,7 @@ func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]inte
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go through each post-processor and get out all the complex configs
|
pps := tpl.postProcessors()
|
||||||
pps := make([]map[string]interface{}, 0, len(tpl.PostProcessors))
|
|
||||||
for _, rawPP := range tpl.PostProcessors {
|
|
||||||
switch pp := rawPP.(type) {
|
|
||||||
case string:
|
|
||||||
case map[string]interface{}:
|
|
||||||
pps = append(pps, pp)
|
|
||||||
case []interface{}:
|
|
||||||
for _, innerRawPP := range pp {
|
|
||||||
if innerPP, ok := innerRawPP.(map[string]interface{}); ok {
|
|
||||||
pps = append(pps, innerPP)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go through each post-processor and make the fix if necessary
|
// Go through each post-processor and make the fix if necessary
|
||||||
possible := []string{"aws", "digitalocean", "virtualbox", "vmware"}
|
possible := []string{"aws", "digitalocean", "virtualbox", "vmware"}
|
||||||
@ -66,7 +52,7 @@ func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]inte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input["post-processors"] = tpl.PostProcessors
|
input["post-processors"] = pps
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
fix/helpers.go
Normal file
25
fix/helpers.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package fix
|
||||||
|
|
||||||
|
// PP is a convenient way to interact with the post-processors within a fixer
|
||||||
|
type PP struct {
|
||||||
|
PostProcessors []interface{} `mapstructure:"post-processors"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// postProcessors converts the variable structure of the template to a list
|
||||||
|
func (pp *PP) postProcessors() []map[string]interface{} {
|
||||||
|
pps := make([]map[string]interface{}, 0, len(pp.PostProcessors))
|
||||||
|
for _, rawPP := range pp.PostProcessors {
|
||||||
|
switch pp := rawPP.(type) {
|
||||||
|
case string:
|
||||||
|
case map[string]interface{}:
|
||||||
|
pps = append(pps, pp)
|
||||||
|
case []interface{}:
|
||||||
|
for _, innerRawPP := range pp {
|
||||||
|
if innerPP, ok := innerRawPP.(map[string]interface{}); ok {
|
||||||
|
pps = append(pps, innerPP)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pps
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user