core: accept passwords in ssh_info

This commit is contained in:
Mitchell Hashimoto 2014-01-03 09:48:35 -08:00
parent 32d8b507c1
commit e115322e78
3 changed files with 16 additions and 2 deletions

View File

@ -280,6 +280,7 @@ module Vagrant
info[:host] = @config.ssh.host if @config.ssh.host
info[:port] = @config.ssh.port if @config.ssh.port
info[:username] = @config.ssh.username if @config.ssh.username
info[:password] = @config.ssh.password if @config.ssh.password
# We also set some fields that are purely controlled by Varant
info[:forward_agent] = @config.ssh.forward_agent
@ -291,7 +292,7 @@ module Vagrant
# Set the private key path. If a specific private key is given in
# the Vagrantfile we set that. Otherwise, we use the default (insecure)
# private key, but only if the provider didn't give us one.
if !info[:private_key_path]
if !info[:private_key_path] && !info[:password]
if @config.ssh.private_key_path
info[:private_key_path] = @config.ssh.private_key_path
else
@ -300,6 +301,7 @@ module Vagrant
end
# Setup the keys
info[:private_key_path] ||= []
if !info[:private_key_path].is_a?(Array)
info[:private_key_path] = [info[:private_key_path]]
end

View File

@ -5,12 +5,14 @@ module VagrantPlugins
attr_accessor :port
attr_accessor :private_key_path
attr_accessor :username
attr_accessor :password
def initialize
@host = UNSET_VALUE
@port = UNSET_VALUE
@private_key_path = UNSET_VALUE
@username = UNSET_VALUE
@password = UNSET_VALUE
end
def finalize!
@ -18,6 +20,7 @@ module VagrantPlugins
@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
if @private_key_path && !@private_key_path.is_a?(Array)
@private_key_path = [@private_key_path]

View File

@ -279,7 +279,7 @@ describe Vagrant::Machine do
let(:provider_ssh_info) { {} }
before(:each) do
provider.should_receive(:ssh_info).and_return(provider_ssh_info)
provider.stub(:ssh_info).and_return(provider_ssh_info)
end
[:host, :port, :username].each do |type|
@ -373,6 +373,15 @@ describe Vagrant::Machine do
instance.ssh_info[:private_key_path].should ==
[instance.env.default_private_key_path.to_s]
end
it "should not set any default private keys if a password is specified" do
provider_ssh_info[:private_key_path] = nil
instance.config.ssh.private_key_path = nil
instance.config.ssh.password = ""
expect(instance.ssh_info[:private_key_path]).to be_empty
expect(instance.ssh_info[:password]).to eql("")
end
end
end