github.com/hashicorp/packer@v1.14.3/fix/fixer_sshdisableagent.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  // FixerSSHDisableAgent changes the "ssh_disable_agent" of a template
    11  // to "ssh_disable_agent_forwarding".
    12  type FixerSSHDisableAgent struct{}
    13  
    14  func (FixerSSHDisableAgent) DeprecatedOptions() map[string][]string {
    15  	return map[string][]string{
    16  		"*": []string{"ssh_disable_agent"},
    17  	}
    18  }
    19  
    20  func (FixerSSHDisableAgent) Fix(input map[string]interface{}) (map[string]interface{}, error) {
    21  	// The type we'll decode into; we only care about builders
    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  	for _, builder := range tpl.Builders {
    33  		sshDisableAgentRaw, ok := builder["ssh_disable_agent"]
    34  		if !ok {
    35  			continue
    36  		}
    37  
    38  		sshDisableAgent, ok := sshDisableAgentRaw.(bool)
    39  		if !ok {
    40  			continue
    41  		}
    42  
    43  		// only assign to ssh_disable_agent_forwarding if it doesn't
    44  		// already exist; otherwise we'll just ignore ssh_disable_agent
    45  		_, sshDisableAgentIncluded := builder["ssh_disable_agent_forwarding"]
    46  		if !sshDisableAgentIncluded {
    47  			builder["ssh_disable_agent_forwarding"] = sshDisableAgent
    48  		}
    49  
    50  		delete(builder, "ssh_disable_agent")
    51  	}
    52  
    53  	input["builders"] = tpl.Builders
    54  	return input, nil
    55  }
    56  
    57  func (FixerSSHDisableAgent) Synopsis() string {
    58  	return `Updates builders using "ssh_disable_agent" to use "ssh_disable_agent_forwarding"`
    59  }