Change @ssl to @transport
This commit is contained in:
parent
b3480049ad
commit
072bb26a30
|
@ -8,7 +8,7 @@ module VagrantPlugins
|
||||||
attr_accessor :guest_port
|
attr_accessor :guest_port
|
||||||
attr_accessor :max_tries
|
attr_accessor :max_tries
|
||||||
attr_accessor :timeout
|
attr_accessor :timeout
|
||||||
attr_accessor :ssl
|
attr_accessor :transport
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@username = UNSET_VALUE
|
@username = UNSET_VALUE
|
||||||
|
@ -18,19 +18,20 @@ module VagrantPlugins
|
||||||
@guest_port = UNSET_VALUE
|
@guest_port = UNSET_VALUE
|
||||||
@max_tries = UNSET_VALUE
|
@max_tries = UNSET_VALUE
|
||||||
@timeout = UNSET_VALUE
|
@timeout = UNSET_VALUE
|
||||||
@ssl = UNSET_VALUE
|
@transport = UNSET_VALUE
|
||||||
@ssl_peer_verification = UNSET_VALUE
|
@ssl_peer_verification = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
@username = "vagrant" if @username == UNSET_VALUE
|
@username = "vagrant" if @username == UNSET_VALUE
|
||||||
@password = "vagrant" if @password == UNSET_VALUE
|
@password = "vagrant" if @password == UNSET_VALUE
|
||||||
|
@transport = :ssl if @transport == UNSET_VALUE
|
||||||
@host = nil if @host == UNSET_VALUE
|
@host = nil if @host == UNSET_VALUE
|
||||||
@port = (@ssl ? 5986 : 5985) if @port == UNSET_VALUE
|
is_ssl = @transport == :ssl
|
||||||
@guest_port = (@ssl ? 5986 : 5985) if @guest_port == UNSET_VALUE
|
@port = (is_ssl ? 5986 : 5985) if @port == UNSET_VALUE
|
||||||
|
@guest_port = (is_ssl ? 5986 : 5985) if @guest_port == UNSET_VALUE
|
||||||
@max_tries = 20 if @max_tries == UNSET_VALUE
|
@max_tries = 20 if @max_tries == UNSET_VALUE
|
||||||
@timeout = 60 if @timeout == UNSET_VALUE
|
@timeout = 60 if @timeout == UNSET_VALUE
|
||||||
@ssl = false if @ssl == UNSET_VALUE
|
|
||||||
@ssl_peer_verification = true if @ssl_peer_verification == UNSET_VALUE
|
@ssl_peer_verification = true if @ssl_peer_verification == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ module VagrantPlugins
|
||||||
class WinRMFileTransferError < WinRMError
|
class WinRMFileTransferError < WinRMError
|
||||||
error_key(:winrm_file_transfer_error)
|
error_key(:winrm_file_transfer_error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class WinRMInvalidTransport < WinRMError
|
||||||
|
error_key(:invalid_transport)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,7 +115,7 @@ module VagrantPlugins
|
||||||
@logger.info(" - Username: #{@config.username}")
|
@logger.info(" - Username: #{@config.username}")
|
||||||
@logger.info(" - Transport: #{@config.transport}")
|
@logger.info(" - Transport: #{@config.transport}")
|
||||||
|
|
||||||
client = ::WinRM::WinRMWebService.new(endpoint, transport.to_sym, endpoint_options)
|
client = ::WinRM::WinRMWebService.new(endpoint, @config.transport.to_sym, endpoint_options)
|
||||||
client.set_timeout(@config.timeout)
|
client.set_timeout(@config.timeout)
|
||||||
client.toggle_nori_type_casting(:off) #we don't want coersion of types
|
client.toggle_nori_type_casting(:off) #we don't want coersion of types
|
||||||
client
|
client
|
||||||
|
@ -126,7 +126,14 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def endpoint
|
def endpoint
|
||||||
"http#{@ssl ? 's' : ''}://#{@host}:#{@port}/wsman"
|
case @config.transport
|
||||||
|
when :ssl
|
||||||
|
"https://#{@host}:#{@port}/wsman"
|
||||||
|
when :plaintext
|
||||||
|
"http://#{@host}:#{@port}/wsman"
|
||||||
|
else
|
||||||
|
raise Errors::WinRMInvalidTransport, transport: @config.transport
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def endpoint_options
|
def endpoint_options
|
||||||
|
|
|
@ -29,6 +29,8 @@ en:
|
||||||
Message: %{message}
|
Message: %{message}
|
||||||
invalid_shell: |-
|
invalid_shell: |-
|
||||||
%{shell} is not a supported type of Windows shell.
|
%{shell} is not a supported type of Windows shell.
|
||||||
|
invalid_transport: |-
|
||||||
|
%{transport} is not a supported WinRM transport.
|
||||||
winrm_not_ready: |-
|
winrm_not_ready: |-
|
||||||
The box is not able to report an address for WinRM to connect to yet.
|
The box is not able to report an address for WinRM to connect to yet.
|
||||||
WinRM cannot access this Vagrant environment. Please wait for the
|
WinRM cannot access this Vagrant environment. Please wait for the
|
||||||
|
|
|
@ -7,6 +7,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
|
||||||
include_context "unit"
|
include_context "unit"
|
||||||
|
|
||||||
let(:session) { double("winrm_session") }
|
let(:session) { double("winrm_session") }
|
||||||
|
let(:port) { config.transport == :ssl ? 5986 : 5985 }
|
||||||
let(:config) {
|
let(:config) {
|
||||||
VagrantPlugins::CommunicatorWinRM::Config.new.tap do |c|
|
VagrantPlugins::CommunicatorWinRM::Config.new.tap do |c|
|
||||||
c.username = 'username'
|
c.username = 'username'
|
||||||
|
@ -16,7 +17,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
|
||||||
}
|
}
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
described_class.new('localhost', 5985, config).tap do |comm|
|
described_class.new('localhost', port, config).tap do |comm|
|
||||||
allow(comm).to receive(:new_session).and_return(session)
|
allow(comm).to receive(:new_session).and_return(session)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -50,15 +51,29 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".endpoint" do
|
describe ".endpoint" do
|
||||||
it "should create winrm endpoint address" do
|
context 'when transport is :ssl' do
|
||||||
expect(subject.send(:endpoint)).to eq("http://localhost:5985/wsman")
|
it "should create winrm endpoint address using https" do
|
||||||
|
expect(subject.send(:endpoint)).to eq("https://localhost:5986/wsman")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when transport is :plaintext" do
|
||||||
|
let(:config) {
|
||||||
|
VagrantPlugins::CommunicatorWinRM::Config.new.tap do |c|
|
||||||
|
c.transport = :plaintext
|
||||||
|
c.finalize!
|
||||||
|
end
|
||||||
|
}
|
||||||
|
it "should create winrm endpoint address using http" do
|
||||||
|
expect(subject.send(:endpoint)).to eq("http://localhost:5985/wsman")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".endpoint_options" do
|
describe ".endpoint_options" do
|
||||||
it "should create endpoint options" do
|
it "should create endpoint options" do
|
||||||
expect(subject.send(:endpoint_options)).to eq(
|
expect(subject.send(:endpoint_options)).to eq(
|
||||||
{ user: "username", pass: "password", host: "localhost", port: 5985,
|
{ user: "username", pass: "password", host: "localhost", port: 5986,
|
||||||
basic_auth_only: true, no_ssl_peer_verification: false })
|
basic_auth_only: true, no_ssl_peer_verification: false })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue