Removed ssh_key_path
- removed backwards compatibility code - ensured key usage came from SSHPrivateKey configuration - changed tests to use private_key
This commit is contained in:
parent
51b2069af1
commit
bd8fb014c4
|
@ -32,7 +32,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*ssh.ClientConfig
|
|||
packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
|
||||
}
|
||||
|
||||
if config.SSHKeyPath != "" {
|
||||
if config.Comm.SSHPrivateKey != "" {
|
||||
signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -12,15 +12,11 @@ type SSHConfig struct {
|
|||
|
||||
// These are deprecated, but we keep them around for BC
|
||||
// TODO(@mitchellh): remove
|
||||
SSHKeyPath string `mapstructure:"ssh_key_path"`
|
||||
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
|
||||
}
|
||||
|
||||
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
// TODO: backwards compatibility, write fixer instead
|
||||
if c.SSHKeyPath != "" {
|
||||
c.Comm.SSHPrivateKey = c.SSHKeyPath
|
||||
}
|
||||
if c.SSHWaitTimeout != 0 {
|
||||
c.Comm.SSHTimeout = c.SSHWaitTimeout
|
||||
}
|
||||
|
|
|
@ -28,19 +28,19 @@ func TestSSHConfigPrepare(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
||||
func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
|
||||
var c *SSHConfig
|
||||
var errs []error
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = ""
|
||||
c.Comm.SSHPrivateKey = ""
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %#v", errs)
|
||||
}
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = "/i/dont/exist"
|
||||
c.Comm.SSHPrivateKey = "/i/dont/exist"
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("should have error")
|
||||
|
@ -59,7 +59,7 @@ func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
|||
}
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = tf.Name()
|
||||
c.Comm.SSHPrivateKey = tf.Name()
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("should have error")
|
||||
|
@ -70,7 +70,7 @@ func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
|||
tf.Truncate(0)
|
||||
tf.Write([]byte(testPem))
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = tf.Name()
|
||||
c.Comm.SSHPrivateKey = tf.Name()
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %#v", errs)
|
||||
|
|
|
@ -110,7 +110,6 @@ type Config struct {
|
|||
|
||||
// These are deprecated, but we keep them around for BC
|
||||
// TODO(@mitchellh): remove
|
||||
SSHKeyPath string `mapstructure:"ssh_key_path"`
|
||||
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
|
||||
|
||||
// TODO(mitchellh): deprecate
|
||||
|
@ -212,9 +211,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
}
|
||||
|
||||
// TODO: backwards compatibility, write fixer instead
|
||||
if b.config.SSHKeyPath != "" {
|
||||
b.config.Comm.SSHPrivateKey = b.config.SSHKeyPath
|
||||
}
|
||||
if b.config.SSHWaitTimeout != 0 {
|
||||
b.config.Comm.SSHTimeout = b.config.SSHWaitTimeout
|
||||
}
|
||||
|
|
|
@ -357,11 +357,11 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
||||
func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
||||
config["ssh_key_path"] = ""
|
||||
config["ssh_private_key_file"] = ""
|
||||
b = Builder{}
|
||||
warns, err := b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
|
@ -371,7 +371,7 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
|||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
config["ssh_key_path"] = "/i/dont/exist"
|
||||
config["ssh_private_key_file"] = "/i/dont/exist"
|
||||
b = Builder{}
|
||||
warns, err = b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
|
@ -393,7 +393,7 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
config["ssh_key_path"] = tf.Name()
|
||||
config["ssh_private_key_file"] = tf.Name()
|
||||
b = Builder{}
|
||||
warns, err = b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
|
@ -407,7 +407,7 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
|||
tf.Seek(0, 0)
|
||||
tf.Truncate(0)
|
||||
tf.Write([]byte(testPem))
|
||||
config["ssh_key_path"] = tf.Name()
|
||||
config["ssh_private_key_file"] = tf.Name()
|
||||
b = Builder{}
|
||||
warns, err = b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
|
|
|
@ -24,7 +24,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConf
|
|||
ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
|
||||
}
|
||||
|
||||
if config.SSHKeyPath != "" {
|
||||
if config.Comm.SSHPrivateKey != "" {
|
||||
signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -17,7 +17,6 @@ type SSHConfig struct {
|
|||
|
||||
// These are deprecated, but we keep them around for BC
|
||||
// TODO(@mitchellh): remove
|
||||
SSHKeyPath string `mapstructure:"ssh_key_path"`
|
||||
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
|
||||
}
|
||||
|
||||
|
@ -31,9 +30,6 @@ func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
|
|||
}
|
||||
|
||||
// TODO: backwards compatibility, write fixer instead
|
||||
if c.SSHKeyPath != "" {
|
||||
c.Comm.SSHPrivateKey = c.SSHKeyPath
|
||||
}
|
||||
if c.SSHWaitTimeout != 0 {
|
||||
c.Comm.SSHTimeout = c.SSHWaitTimeout
|
||||
}
|
||||
|
|
|
@ -59,19 +59,19 @@ func TestSSHConfigPrepare_SSHHostPort(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
||||
func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
|
||||
var c *SSHConfig
|
||||
var errs []error
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = ""
|
||||
c.Comm.SSHPrivateKey = ""
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %#v", errs)
|
||||
}
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = "/i/dont/exist"
|
||||
c.Comm.SSHPrivateKey = "/i/dont/exist"
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("should have error")
|
||||
|
@ -90,7 +90,7 @@ func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
|||
}
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = tf.Name()
|
||||
c.Comm.SSHPrivateKey = tf.Name()
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("should have error")
|
||||
|
@ -101,7 +101,7 @@ func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
|||
tf.Truncate(0)
|
||||
tf.Write([]byte(testPem))
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = tf.Name()
|
||||
c.Comm.SSHPrivateKey = tf.Name()
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %#v", errs)
|
||||
|
|
|
@ -12,16 +12,12 @@ type SSHConfig struct {
|
|||
|
||||
// These are deprecated, but we keep them around for BC
|
||||
// TODO(@mitchellh): remove
|
||||
SSHKeyPath string `mapstructure:"ssh_key_path"`
|
||||
SSHSkipRequestPty bool `mapstructure:"ssh_skip_request_pty"`
|
||||
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
|
||||
}
|
||||
|
||||
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
// TODO: backwards compatibility, write fixer instead
|
||||
if c.SSHKeyPath != "" {
|
||||
c.Comm.SSHPrivateKey = c.SSHKeyPath
|
||||
}
|
||||
if c.SSHWaitTimeout != 0 {
|
||||
c.Comm.SSHTimeout = c.SSHWaitTimeout
|
||||
}
|
||||
|
|
|
@ -28,19 +28,19 @@ func TestSSHConfigPrepare(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
||||
func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
|
||||
var c *SSHConfig
|
||||
var errs []error
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = ""
|
||||
c.Comm.SSHPrivateKey = ""
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %#v", errs)
|
||||
}
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = "/i/dont/exist"
|
||||
c.Comm.SSHPrivateKey = "/i/dont/exist"
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("should have error")
|
||||
|
@ -59,7 +59,7 @@ func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
|||
}
|
||||
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = tf.Name()
|
||||
c.Comm.SSHPrivateKey = tf.Name()
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("should have error")
|
||||
|
@ -70,7 +70,7 @@ func TestSSHConfigPrepare_SSHKeyPath(t *testing.T) {
|
|||
tf.Truncate(0)
|
||||
tf.Write([]byte(testPem))
|
||||
c = testSSHConfig()
|
||||
c.SSHKeyPath = tf.Name()
|
||||
c.Comm.SSHPrivateKey = tf.Name()
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %#v", errs)
|
||||
|
|
Loading…
Reference in New Issue