1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
module VagrantPlugins
module Kernel_V2
class SSHConnectConfig < Vagrant.plugin("2", :config)
attr_accessor :host
attr_accessor :port
attr_accessor :config
attr_accessor :private_key_path
attr_accessor :username
attr_accessor :password
attr_accessor :insert_key
attr_accessor :keys_only
attr_accessor :paranoid
attr_accessor :verify_host_key
attr_accessor :compression
attr_accessor :dsa_authentication
attr_accessor :extra_args
attr_accessor :remote_user
def initialize
@host = UNSET_VALUE
@port = UNSET_VALUE
@config = UNSET_VALUE
@private_key_path = UNSET_VALUE
@username = UNSET_VALUE
@password = UNSET_VALUE
@insert_key = UNSET_VALUE
@keys_only = UNSET_VALUE
@paranoid = UNSET_VALUE
@verify_host_key = UNSET_VALUE
@compression = UNSET_VALUE
@dsa_authentication = UNSET_VALUE
@extra_args = UNSET_VALUE
@remote_user = UNSET_VALUE
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
@password = nil if @password == UNSET_VALUE
@insert_key = true if @insert_key == UNSET_VALUE
@keys_only = true if @keys_only == UNSET_VALUE
@paranoid = false if @paranoid == UNSET_VALUE
@verify_host_key = :never if @verify_host_key == UNSET_VALUE
@compression = true if @compression == UNSET_VALUE
@dsa_authentication = true if @dsa_authentication == UNSET_VALUE
@extra_args = nil if @extra_args == UNSET_VALUE
@config = nil if @config == UNSET_VALUE
if @private_key_path && !@private_key_path.is_a?(Array)
@private_key_path = [@private_key_path]
end
if @remote_user == UNSET_VALUE
if @username
@remote_user = @username
else
@remote_user = nil
end
end
if @paranoid
@verify_host_key = @paranoid
end
# 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
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
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
end
if @config
config_path = File.expand_path(@config, machine.env.root_path)
if !File.file?(config_path)
errors << I18n.t(
"vagrant.config.ssh.ssh_config_missing",
path: @config)
end
end
if @paranoid
machine.env.ui.warn(I18n.t("vagrant.config.ssh.paranoid_deprecated"))
end
errors
end
end
end
end
|