winrm 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  pkg/*
4
4
  .rvmrc
5
5
  test/spec/creds*.json
6
- traces/
6
+ test/config.yml
7
+ traces/
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Windows Remote Management (WinRM) for Ruby
2
+
3
+ This is a SOAP library that uses the functionality in Windows Remote
4
+ Management(WinRM) to call native object in Windows. This includes, but is
5
+ not limitted to, running batch scripts, powershell scripts and fetching WMI
6
+ variables. For more information on WinRM, please visit Microsoft's WinRM
7
+ site: http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx
8
+
9
+ ## My Info
10
+ * Twitter: [@zentourist](https://twitter.com/zentourist)
11
+ * BLOG: [http://distributed-frostbite.blogspot.com/](http://distributed-frostbite.blogspot.com/)
12
+ * Add me in LinkedIn: [http://www.linkedin.com/in/danwanek](http://www.linkedin.com/in/danwanek)
13
+ * Find me on irc.freenode.net in #ruby-lang (zenChild)
14
+
15
+ ## Current features
16
+
17
+ 1. GSSAPI support: This is the default way that Windows authenticates and
18
+ secures WinRM messages. In order for this to work the computer you are
19
+ connecting to must be a part of an Active Directory domain and you must
20
+ have local credentials via kinit. GSSAPI support is dependent on the
21
+ gssapi gem which only supports the MIT Kerberos libraries at this time.
22
+
23
+ If you are using this method there is no longer a need to change the
24
+ WinRM service authentication settings. You can simply do a
25
+ 'winrm quickconfig' on your server or enable WinRM via group policy and
26
+ everything should be working.
27
+
28
+ 2. Multi-Instance support: The SOAP back-end has been completely gutted
29
+ and is now using some of the Savon core libraries for parsing and
30
+ building packets. Moving away from Handsoap allows multiple instances
31
+ to be created because the SOAP backend is no longer a Singleton type
32
+ class.
33
+
34
+
35
+ ## !!!SHOUTS OUT!!!
36
+ Many thanks to the following for their many patches....
37
+ * Seth Chisamore (https://github.com/schisamo)
38
+ * Paul Morton (https://github.com/pmorton)
39
+
40
+
41
+
42
+ ## INSTALL:
43
+ `gem install -r winrm` then on the server `winrm quickconfig` as admin
44
+
45
+ ## USE:
46
+ `require 'winrm'`
47
+
48
+ ## EXAMPLE:
49
+ ```ruby
50
+ require 'winrm'
51
+ endpoint = http://mywinrmhost:5985/wsman
52
+ krb5_realm = 'EXAMPLE.COM'
53
+ winrm = WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => krb5_realm)
54
+ winrm.cmd('ipconfig /all') do |stdout, stderr|
55
+ STDOUT.print stdout
56
+ STDERR.print stderr
57
+ end
58
+ ```
59
+
60
+ There are various connection types you can specify upon initialization:
61
+
62
+ #### PLAINTEXT
63
+ ```ruby
64
+ WinRM::WinRMWebService.new(endpoint, :plaintext, :user => myuser, :pass => mypass)
65
+
66
+ # Same but force basic authentication:
67
+ WinRM::WinRMWebService.new(endpoint, :plaintext, :user => myuser, :pass => mypass, :basic_auth_only => true)
68
+ ```
69
+
70
+ #### SSL
71
+ ```ruby
72
+ WinRM::WinRMWebService.new(endpoint, :ssl, :user => myuser, :pass => mypass)
73
+
74
+ # Same but force basic authentication:
75
+ WinRM::WinRMWebService.new(endpoint, :ssl, :user => myuser, :pass => mypass, :basic_auth_only => true)
76
+ ```
77
+
78
+ #### KERBEROS
79
+ ```ruby
80
+ WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => 'MYREALM.COM')
81
+ ```
82
+
83
+ ## DISCLAIMER
84
+ If you see something that could be done better or would like to help out in the development of this code please feel free to clone the repository and send me patches.
85
+
86
+ `git clone git://github.com/zenchild/WinRM.git` or add an [issue](https://github.com/zenchild/WinRM/issues) on GitHub:
87
+
88
+ - - -
89
+
90
+ Cheers!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -289,7 +289,9 @@ module WinRM
289
289
  }
290
290
 
291
291
  resp = send_message(s.to_xml)
292
+ toggle_nori_type_casting :off
292
293
  hresp = Nori.parse(resp.to_xml)[:envelope][:body]
294
+ toggle_nori_type_casting :original
293
295
  # Normalize items so the type always has an array even if it's just a single item.
294
296
  items = {}
295
297
  hresp[:enumerate_response][:items].each_pair do |k,v|
@@ -303,6 +305,20 @@ module WinRM
303
305
  end
304
306
  alias :wql :run_wql
305
307
 
308
+ def toggle_nori_type_casting(to)
309
+ @nori_type_casting ||= Nori.advanced_typecasting?
310
+ case to.to_sym
311
+ when :original
312
+ Nori.advanced_typecasting = @nori_type_casting
313
+ when :on
314
+ Nori.advanced_typecasting = true
315
+ when :off
316
+ Nori.advanced_typecasting = false
317
+ else
318
+ raise ArgumentError, "Cannot toggle type casting to '#{to}', it is not a valid argument"
319
+ end
320
+
321
+ end
306
322
 
307
323
  private
308
324
 
@@ -0,0 +1,12 @@
1
+ ## Kerberos
2
+ #auth_type: plaintest
3
+ #endpoint: "http://<yourserver>:5985/wsman"
4
+ #options:
5
+ # realm: "your.realm"
6
+
7
+ ## Plain Text
8
+ #auth_type: plaintext
9
+ #endpoint: "http://localhost:5985/wsman"
10
+ #options:
11
+ # user: vagrant
12
+ # pass: vagrant
@@ -0,0 +1,30 @@
1
+ $: << File.dirname(__FILE__)
2
+ require 'spec_helper'
3
+ require 'Nori'
4
+
5
+ describe "Test Nori Type Cast Toggler" do
6
+ before(:all) do
7
+ @winrm = winrm_connection
8
+ end
9
+
10
+ it 'should have nori advanced type casting on' do
11
+ Nori.advanced_typecasting?.should == true
12
+ end
13
+
14
+ it 'should turn off nori advanced type casting' do
15
+ @winrm.toggle_nori_type_casting :off
16
+ Nori.advanced_typecasting?.should == false
17
+ end
18
+
19
+ it 'should return nori advanced type casting to the original state' do
20
+ @winrm.toggle_nori_type_casting :original
21
+ Nori.advanced_typecasting?.should == true
22
+ end
23
+
24
+ it 'should turn on nori advanced type casting' do
25
+ @winrm.toggle_nori_type_casting :off
26
+ @winrm.toggle_nori_type_casting :on
27
+ Nori.advanced_typecasting?.should == true
28
+ end
29
+
30
+ end
@@ -5,15 +5,30 @@ require 'json'
5
5
  module ConnectionHelper
6
6
  # To run this test put a file called 'creds.json' in this directory with the following format:
7
7
  # {"user":"myuser","pass":"mypass","endpoint":"http://mysys.com/wsman","realm":"MY.REALM"}
8
- CREDS_FILE=File.dirname(__FILE__) + '/creds.json'
8
+ WINRM_CONFIG = File.expand_path("#{File.dirname(__FILE__)}/../config.yml")
9
9
 
10
10
  def winrm_connection
11
- creds = JSON.load(File.open(CREDS_FILE,'r'))
12
- winrm = WinRM::WinRMWebService.new(creds['endpoint'], :kerberos, :realm => creds['realm'])
13
- #winrm = WinRM::WinRMWebService.new(creds['endpoint'], :plaintext, :user => creds['user'], :pass => creds['pass'])
14
- #winrm = WinRM::WinRMWebService.new(creds['endpoint'], :plaintext, :user => creds['user'], :pass => creds['pass'], :basic_auth_only => true)
11
+ config = symbolize_keys(YAML.load(File.read(WINRM_CONFIG)))
12
+ config[:options].merge!( :basic_auth_only => true ) unless config[:auth_type].eql? :kerberos
13
+ winrm = WinRM::WinRMWebService.new(config[:endpoint], config[:auth_type].to_sym, config[:options])
15
14
  winrm
16
15
  end
16
+
17
+ def symbolize_keys(hash)
18
+ hash.inject({}){|result, (key, value)|
19
+ new_key = case key
20
+ when String then key.to_sym
21
+ else key
22
+ end
23
+ new_value = case value
24
+ when Hash then symbolize_keys(value)
25
+ else value
26
+ end
27
+ result[new_key] = new_value
28
+ result
29
+ }
30
+ end
31
+
17
32
  end
18
33
 
19
34
  RSpec.configure do |config|
data/winrm.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.files = `git ls-files`.split(/\n/)
22
22
  s.require_path = "lib"
23
23
  s.rdoc_options = %w(-x test/ -x examples/)
24
- s.extra_rdoc_files = %w(README LICENSE)
24
+ s.extra_rdoc_files = %w(README.md LICENSE)
25
25
 
26
26
  s.required_ruby_version = '>= 1.9.0'
27
27
  s.add_runtime_dependency 'gssapi', '~> 1.0.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-31 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gssapi
16
- requirement: &17923760 !ruby/object:Gem::Requirement
16
+ requirement: &9359240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *17923760
24
+ version_requirements: *9359240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &17922480 !ruby/object:Gem::Requirement
27
+ requirement: &9358240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *17922480
35
+ version_requirements: *9358240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: httpclient
38
- requirement: &17921240 !ruby/object:Gem::Requirement
38
+ requirement: &9356700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.2.0.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *17921240
46
+ version_requirements: *9356700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rubyntlm
49
- requirement: &17920200 !ruby/object:Gem::Requirement
49
+ requirement: &9355960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.1.1
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *17920200
57
+ version_requirements: *9355960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uuidtools
60
- requirement: &17919160 !ruby/object:Gem::Requirement
60
+ requirement: &9354860 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.1.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *17919160
68
+ version_requirements: *9354860
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: savon
71
- requirement: &17918380 !ruby/object:Gem::Requirement
71
+ requirement: &9354080 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - =
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.5
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *17918380
79
+ version_requirements: *9354080
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: logging
82
- requirement: &17917680 !ruby/object:Gem::Requirement
82
+ requirement: &9353360 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 1.6.1
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *17917680
90
+ version_requirements: *9353360
91
91
  description: ! ' Ruby library for Windows Remote Management
92
92
 
93
93
  '
@@ -95,12 +95,12 @@ email: dan.wanek@gmail.com
95
95
  executables: []
96
96
  extensions: []
97
97
  extra_rdoc_files:
98
- - README
98
+ - README.md
99
99
  - LICENSE
100
100
  files:
101
101
  - .gitignore
102
102
  - LICENSE
103
- - README
103
+ - README.md
104
104
  - Rakefile
105
105
  - VERSION
106
106
  - lib/winrm.rb
@@ -111,7 +111,9 @@ files:
111
111
  - lib/winrm/winrm_service.rb
112
112
  - preamble
113
113
  - test/.rspec
114
+ - test/config-example.yml
114
115
  - test/spec/cmd_spec.rb
116
+ - test/spec/nori_type_casting_spec.rb
115
117
  - test/spec/powershell_spec.rb
116
118
  - test/spec/spec_helper.rb
117
119
  - test/spec/test.ps1
data/README DELETED
@@ -1,90 +0,0 @@
1
- --------------------------------------------------------------------------
2
- Windows Remote Management (WinRM) for Ruby
3
- --------------------------------------------------------------------------
4
- This is a SOAP library that uses the functionality in Windows Remote
5
- Management(WinRM) to call native object in Windows. This includes, but is
6
- not limitted to, running batch scripts, powershell scripts and fetching WMI
7
- variables. For more information on WinRM, please visit Microsoft's WinRM
8
- site: http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx
9
-
10
- My Info:
11
- BLOG: http://distributed-frostbite.blogspot.com/
12
- Add me in LinkedIn: http://www.linkedin.com/in/danwanek
13
- Find me on irc.freenode.net in #ruby-lang (zenChild)
14
-
15
- --------------------------------------------------------------------------
16
- Version 1.0.0rc1
17
-
18
- This is a release candidate of the new version 1 code for Ruby WinRM. It
19
- is almost a complete re-write from the previous version to support some
20
- of the following major feature additions:
21
-
22
- 1. GSSAPI support: This is the default way that Windows authenticates and
23
- secures WinRM messages. In order for this to work the computer you are
24
- connecting to must be a part of an Active Directory domain and you must
25
- have local credentials via kinit. GSSAPI support is dependent on the
26
- gssapi gem which only supports the MIT Kerberos libraries at this time.
27
-
28
- If you are using this method there is no longer a need to change the
29
- WinRM service authentication settings. You can simply do a
30
- 'winrm quickconfig' on your server or enable WinRM via group policy and
31
- everything should be working.
32
-
33
- 2. Multi-Instance support: The SOAP back-end has been completely gutted
34
- and is now using some of the Savon core libraries for parsing and
35
- building packets. Moving away from Handsoap allows multiple instances
36
- to be created because the SOAP backend is no longer a Singleton type
37
- class.
38
-
39
- --------------------------------------------------------------------------
40
- !!!SHOUTS OUT!!!
41
- --------------------------------------------------------------------------
42
- Thanks to Seth Chisamore (https://github.com/schisamo) of Opscode for his input and patches.
43
- --------------------------------------------------------------------------
44
-
45
-
46
- INSTALL:
47
- gem install -r winrm
48
- .. on the server 'winrm quickconfig' as admin
49
-
50
- USE:
51
- require 'winrm'
52
-
53
- EXAMPLE:
54
- require 'winrm'
55
- endpoint = http://mywinrmhost:5985/wsman
56
- krb5_realm = 'EXAMPLE.COM'
57
- winrm = WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => krb5_realm)
58
- winrm.cmd('ipconfig /all') do |stdout, stderr|
59
- STDOUT.print stdout
60
- STDERR.print stderr
61
- end
62
-
63
-
64
- CONNECTION TYPES:
65
-
66
- PLAINTEXT:
67
- WinRM::WinRMWebService.new(endpoint, :plaintext, :user => myuser, :pass => mypass)
68
- # Same but force basic authentication
69
- WinRM::WinRMWebService.new(endpoint, :plaintext, :user => myuser, :pass => mypass, :basic_auth_only => true)
70
- SSL:
71
- WinRM::WinRMWebService.new(endpoint, :ssl, :user => myuser, :pass => mypass)
72
- # Same but force basic authentication
73
- WinRM::WinRMWebService.new(endpoint, :ssl, :user => myuser, :pass => mypass, :basic_auth_only => true)
74
- KERBEROS:
75
- WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => 'MYREALM.COM')
76
-
77
- --------------------------------------------------------------------------
78
- DISCLAIMER: If you see something that could be done better or would like
79
- to help out in the development of this code please feel free to clone the
80
- 'git' repository and send me patches:
81
- git clone git://github.com/zenchild/WinRM.git
82
- or add an issue on GitHub:
83
- http://github.com/zenchild/WinRM/issues
84
-
85
- Cheers!
86
- --------------------------------------------------------------------------
87
-
88
-
89
- Thurs : #9 5:30-6:30
90
-