2012-11-07 05:28:44 +00:00
|
|
|
require "vagrant"
|
|
|
|
|
2013-04-09 03:50:15 +00:00
|
|
|
require_relative "ssh_connect"
|
|
|
|
|
2012-11-07 05:28:44 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Kernel_V2
|
2013-04-09 03:50:15 +00:00
|
|
|
class SSHConfig < SSHConnectConfig
|
2013-04-09 04:03:51 +00:00
|
|
|
attr_accessor :forward_agent
|
|
|
|
attr_accessor :forward_x11
|
2014-06-30 23:41:31 +00:00
|
|
|
attr_accessor :forward_env
|
2012-11-07 05:28:44 +00:00
|
|
|
attr_accessor :guest_port
|
2013-04-08 04:51:14 +00:00
|
|
|
attr_accessor :keep_alive
|
2012-11-07 05:28:44 +00:00
|
|
|
attr_accessor :shell
|
2013-04-03 20:54:21 +00:00
|
|
|
attr_accessor :proxy_command
|
2015-07-02 06:33:13 +00:00
|
|
|
attr_accessor :ssh_command
|
2013-11-25 00:48:07 +00:00
|
|
|
attr_accessor :pty
|
2015-07-09 15:30:47 +00:00
|
|
|
attr_accessor :sudo_command
|
2016-11-08 17:50:39 +00:00
|
|
|
attr_accessor :export_command_template
|
2013-04-09 03:50:15 +00:00
|
|
|
|
|
|
|
attr_reader :default
|
2013-04-03 19:49:59 +00:00
|
|
|
|
|
|
|
def initialize
|
2013-04-09 03:50:15 +00:00
|
|
|
super
|
|
|
|
|
2016-11-08 17:50:39 +00:00
|
|
|
@forward_agent = UNSET_VALUE
|
|
|
|
@forward_x11 = UNSET_VALUE
|
|
|
|
@forward_env = UNSET_VALUE
|
|
|
|
@guest_port = UNSET_VALUE
|
|
|
|
@keep_alive = UNSET_VALUE
|
|
|
|
@proxy_command = UNSET_VALUE
|
|
|
|
@ssh_command = UNSET_VALUE
|
|
|
|
@pty = UNSET_VALUE
|
|
|
|
@shell = UNSET_VALUE
|
|
|
|
@sudo_command = UNSET_VALUE
|
|
|
|
@export_command_template = UNSET_VALUE
|
|
|
|
@default = SSHConnectConfig.new
|
2013-04-09 03:50:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge(other)
|
|
|
|
super.tap do |result|
|
|
|
|
merged_defaults = @default.merge(other.default)
|
|
|
|
result.instance_variable_set(:@default, merged_defaults)
|
|
|
|
end
|
2013-04-03 19:49:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2013-04-09 03:50:15 +00:00
|
|
|
super
|
|
|
|
|
2013-04-09 04:03:51 +00:00
|
|
|
@forward_agent = false if @forward_agent == UNSET_VALUE
|
|
|
|
@forward_x11 = false if @forward_x11 == UNSET_VALUE
|
2014-06-30 23:41:31 +00:00
|
|
|
@forward_env = false if @forward_env == UNSET_VALUE
|
2014-02-05 23:35:37 +00:00
|
|
|
@guest_port = 22 if @guest_port == UNSET_VALUE
|
|
|
|
@keep_alive = true if @keep_alive == UNSET_VALUE
|
2013-09-05 00:23:43 +00:00
|
|
|
@proxy_command = nil if @proxy_command == UNSET_VALUE
|
2015-07-02 06:33:13 +00:00
|
|
|
@ssh_command = nil if @ssh_command == UNSET_VALUE
|
2013-11-25 00:48:07 +00:00
|
|
|
@pty = false if @pty == UNSET_VALUE
|
2014-02-05 23:35:37 +00:00
|
|
|
@shell = "bash -l" if @shell == UNSET_VALUE
|
2013-04-09 03:50:15 +00:00
|
|
|
|
2016-11-08 17:50:39 +00:00
|
|
|
if @export_command_template == UNSET_VALUE
|
|
|
|
@export_command_template = 'export %ENV_KEY%="%ENV_VALUE%"'
|
|
|
|
end
|
|
|
|
|
2015-07-09 15:30:47 +00:00
|
|
|
if @sudo_command == UNSET_VALUE
|
|
|
|
@sudo_command = "sudo -E -H %c"
|
|
|
|
end
|
|
|
|
|
2014-02-05 23:35:37 +00:00
|
|
|
@default.username = "vagrant" if @default.username == UNSET_VALUE
|
2014-05-21 03:31:53 +00:00
|
|
|
@default.port = @guest_port if @default.port == UNSET_VALUE
|
2013-04-09 03:50:15 +00:00
|
|
|
@default.finalize!
|
2013-04-03 19:49:59 +00:00
|
|
|
end
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2013-04-03 23:18:37 +00:00
|
|
|
def to_s
|
|
|
|
"SSH"
|
|
|
|
end
|
|
|
|
|
2013-01-18 20:42:49 +00:00
|
|
|
def validate(machine)
|
2013-04-09 03:50:15 +00:00
|
|
|
errors = super
|
2013-01-18 20:33:37 +00:00
|
|
|
|
|
|
|
# Return the errors
|
2013-04-09 03:50:15 +00:00
|
|
|
result = { to_s => errors }
|
|
|
|
|
|
|
|
# Figure out the errors for the defaults
|
|
|
|
default_errors = @default.validate(machine)
|
|
|
|
result["SSH Defaults"] = default_errors if !default_errors.empty?
|
|
|
|
|
|
|
|
result
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|