2013-04-09 03:50:15 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Kernel_V2
|
|
|
|
class SSHConnectConfig < Vagrant.plugin("2", :config)
|
|
|
|
attr_accessor :host
|
|
|
|
attr_accessor :port
|
|
|
|
attr_accessor :private_key_path
|
|
|
|
attr_accessor :username
|
2014-01-03 17:48:35 +00:00
|
|
|
attr_accessor :password
|
2014-01-03 19:13:21 +00:00
|
|
|
attr_accessor :insert_key
|
2016-05-29 21:58:44 +00:00
|
|
|
attr_accessor :keys_only
|
|
|
|
attr_accessor :paranoid
|
2018-01-05 17:24:30 +00:00
|
|
|
attr_accessor :verify_host_key
|
2017-06-14 23:38:31 +00:00
|
|
|
attr_accessor :compression
|
|
|
|
attr_accessor :dsa_authentication
|
2017-08-16 23:09:28 +00:00
|
|
|
attr_accessor :extra_args
|
2013-04-09 03:50:15 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@host = UNSET_VALUE
|
|
|
|
@port = UNSET_VALUE
|
|
|
|
@private_key_path = UNSET_VALUE
|
|
|
|
@username = UNSET_VALUE
|
2014-01-03 17:48:35 +00:00
|
|
|
@password = UNSET_VALUE
|
2014-01-03 19:13:21 +00:00
|
|
|
@insert_key = UNSET_VALUE
|
2016-05-29 21:58:44 +00:00
|
|
|
@keys_only = UNSET_VALUE
|
|
|
|
@paranoid = UNSET_VALUE
|
2018-01-05 17:24:30 +00:00
|
|
|
@verify_host_key = UNSET_VALUE
|
2017-06-14 23:38:31 +00:00
|
|
|
@compression = UNSET_VALUE
|
|
|
|
@dsa_authentication = UNSET_VALUE
|
2017-08-16 23:09:28 +00:00
|
|
|
@extra_args = UNSET_VALUE
|
2013-04-09 03:50:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
@host = nil if @host == UNSET_VALUE
|
|
|
|
@port = nil if @port == UNSET_VALUE
|
|
|
|
@private_key_path = nil if @private_key_path == UNSET_VALUE
|
|
|
|
@username = nil if @username == UNSET_VALUE
|
2014-01-03 17:48:35 +00:00
|
|
|
@password = nil if @password == UNSET_VALUE
|
2014-01-03 19:13:21 +00:00
|
|
|
@insert_key = true if @insert_key == UNSET_VALUE
|
2016-05-29 21:58:44 +00:00
|
|
|
@keys_only = true if @keys_only == UNSET_VALUE
|
|
|
|
@paranoid = false if @paranoid == UNSET_VALUE
|
2018-07-27 23:28:48 +00:00
|
|
|
@verify_host_key = :never if @verify_host_key == UNSET_VALUE
|
2017-06-14 23:38:31 +00:00
|
|
|
@compression = true if @compression == UNSET_VALUE
|
|
|
|
@dsa_authentication = true if @dsa_authentication == UNSET_VALUE
|
2017-08-16 23:09:28 +00:00
|
|
|
@extra_args = nil if @extra_args == UNSET_VALUE
|
2013-11-25 23:45:39 +00:00
|
|
|
|
|
|
|
if @private_key_path && !@private_key_path.is_a?(Array)
|
|
|
|
@private_key_path = [@private_key_path]
|
|
|
|
end
|
2018-01-05 17:24:30 +00:00
|
|
|
|
|
|
|
if @paranoid
|
|
|
|
@verify_host_key = @paranoid
|
|
|
|
end
|
|
|
|
|
2018-07-27 23:28:48 +00:00
|
|
|
# Values for verify_host_key changed in 5.0.0 of net-ssh. If old value
|
|
|
|
# detected, update with new value
|
|
|
|
case @verify_host_key
|
|
|
|
when true
|
|
|
|
@verify_host_key = :accepts_new_or_local_tunnel
|
|
|
|
when false
|
|
|
|
@verify_host_key = :never
|
|
|
|
when :very
|
|
|
|
@verify_host_key = :accept_new
|
|
|
|
when :secure
|
|
|
|
@verify_host_key = :always
|
|
|
|
end
|
2013-04-09 03:50:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# NOTE: This is _not_ a valid config validation method, since it
|
|
|
|
# returns an _array_ of strings rather than a Hash. This is meant to
|
|
|
|
# be used with a subclass that handles this.
|
|
|
|
#
|
|
|
|
# @return [Array<String>]
|
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
|
|
|
|
2013-11-25 23:45:39 +00:00
|
|
|
if @private_key_path
|
|
|
|
@private_key_path.each do |raw_path|
|
|
|
|
path = File.expand_path(raw_path, machine.env.root_path)
|
|
|
|
if !File.file?(path)
|
|
|
|
errors << I18n.t(
|
|
|
|
"vagrant.config.ssh.private_key_missing",
|
|
|
|
path: raw_path)
|
|
|
|
end
|
|
|
|
end
|
2013-04-09 03:50:15 +00:00
|
|
|
end
|
|
|
|
|
2018-01-05 17:24:30 +00:00
|
|
|
if @paranoid
|
|
|
|
machine.env.ui.warn(I18n.t("vagrant.config.ssh.paranoid_deprecated"))
|
|
|
|
end
|
|
|
|
|
2013-04-09 03:50:15 +00:00
|
|
|
errors
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|