Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
simplify options
Browse files Browse the repository at this point in the history
  • Loading branch information
zenchild committed Mar 3, 2011
1 parent 3b121e5 commit aee02a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
4 changes: 1 addition & 3 deletions lib/capistrano_winrm/configuration/connections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def initialize(options)
end

def connect_to(server)
winrm = WINRM.new(@options[:winrm_user], @options[:winrm_password], @options[:winrm_ssl_ca_store], @options[:winrm_krb5_realm])
winrm.setup_connection(server, @options)
winrm
WINRM.new(server, @options)
end
end

Expand Down
52 changes: 26 additions & 26 deletions lib/winrm_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ class WINRM
attr_reader :server
alias :xserver :server

def initialize(user = nil, pass = nil, ssl_ca_store = nil, krb5_realm = nil)
@user = user
@pass = pass
@ssl_ca_store = ssl_ca_store
@krb5_realm = krb5_realm
@int_hash = {}
@server = nil
def initialize(server, opts)
@server = server
@int_hash = {:options => opts, :server => server}
@winrm = establish_winrm(opts)
end

def [](key)
Expand All @@ -22,30 +19,12 @@ def []=(key, value)
@int_hash[key.to_sym] = value
end

def setup_connection(server, options)
puts "........ #{self.class.name}#winrm_run, #{server}"
@server = server
#@int_hash[:options] = options
#@int_hash[:server] = server
http_method = ( server.port.to_s=~/(443|5986)/ ? 'https' : 'http' )
endpoint = "#{http_method}://#{server}/wsman"
unless(@krb5_realm.nil?)
@inst = WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => @krb5_realm)
else
if @ssl_ca_store.nil?
@inst = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => @user, :pass => @pass)
else
@inst = WinRM::WinRMWebService.new(endpoint, :ssl, :user => @user, :pass => @pass, :ca_trust_path => @ssl_ca_store)
end
end
end

def open_channel
yield self
end

def exec(cmd)
@ios = @inst.cmd(cmd)
@ios = @winrm.cmd(cmd)
end

def process_data
Expand All @@ -62,4 +41,25 @@ def on_extended_data; self; end
def on_request(req_type); self; end
def on_close; self; end


private

# Create a new WinRM instance
# @param [Hash] opts the option hash that was passed to initialize
# @return [WinRM] a new WinRM connection for a particular endpoint
def establish_winrm(opts)
http_method = ( server.port.to_s=~/(443|5986)/ ? 'https' : 'http' )
endpoint = "#{http_method}://#{server}/wsman"
if opts[:winrm_krb5_realm]
inst = WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => opts[:winrm_krb5_realm])
else
unless opts[:winrm_ssl_ca_store]
inst = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => opts[:winrm_user], :pass => opts[:winrm_password])
else
inst = WinRM::WinRMWebService.new(endpoint, :ssl, :user => opts[:winrm_user], :pass => opts[:winrm_password], :ca_trust_path => opts[:winrm_ssl_ca_store])
end
end
inst
end

end

0 comments on commit aee02a5

Please sign in to comment.