winrm 1.8.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -11
- data/.rubocop.yml +26 -22
- data/.travis.yml +11 -12
- data/Gemfile +3 -9
- data/LICENSE +202 -202
- data/README.md +232 -215
- data/Rakefile +34 -36
- data/Vagrantfile +6 -9
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/bin/rwinrm +97 -97
- data/changelog.md +86 -86
- data/lib/winrm.rb +39 -42
- data/lib/winrm/connection.rb +82 -0
- data/lib/winrm/connection_opts.rb +87 -0
- data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
- data/lib/winrm/http/response_handler.rb +96 -82
- data/lib/winrm/http/transport.rb +424 -435
- data/lib/winrm/http/transport_factory.rb +68 -0
- data/lib/winrm/output.rb +59 -43
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
- data/lib/winrm/psrp/fragment.rb +70 -0
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
- data/lib/winrm/psrp/message.rb +130 -0
- data/lib/winrm/psrp/message_data.rb +41 -0
- data/lib/winrm/psrp/message_data/base.rb +49 -0
- data/lib/winrm/psrp/message_data/error_record.rb +68 -0
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
- data/lib/winrm/psrp/message_defragmenter.rb +62 -0
- data/lib/winrm/psrp/message_factory.rb +75 -0
- data/lib/winrm/psrp/message_fragmenter.rb +60 -0
- data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
- data/lib/winrm/psrp/receive_response_reader.rb +93 -0
- data/lib/winrm/psrp/session_capability.xml.erb +7 -0
- data/lib/winrm/psrp/uuid.rb +40 -0
- data/lib/winrm/shells/base.rb +175 -0
- data/lib/winrm/shells/cmd.rb +65 -0
- data/lib/winrm/shells/power_shell.rb +201 -0
- data/lib/winrm/shells/retryable.rb +45 -0
- data/lib/winrm/shells/shell_factory.rb +50 -0
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -0
- data/lib/winrm/wsmv/cleanup_command.rb +61 -0
- data/lib/winrm/wsmv/close_shell.rb +50 -0
- data/lib/winrm/wsmv/command.rb +101 -0
- data/lib/winrm/wsmv/command_output.rb +76 -0
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
- data/lib/winrm/wsmv/configuration.rb +46 -0
- data/lib/winrm/wsmv/create_pipeline.rb +66 -0
- data/lib/winrm/wsmv/create_shell.rb +119 -0
- data/lib/winrm/wsmv/header.rb +203 -0
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
- data/lib/winrm/wsmv/keep_alive.rb +68 -0
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
- data/lib/winrm/wsmv/send_data.rb +68 -0
- data/lib/winrm/wsmv/soap.rb +51 -0
- data/lib/winrm/wsmv/wql_query.rb +79 -0
- data/lib/winrm/wsmv/write_stdin.rb +88 -0
- data/preamble +17 -17
- data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
- data/{spec → tests/integration}/cmd_spec.rb +104 -102
- data/{spec → tests/integration}/config-example.yml +16 -19
- data/{spec → tests/integration}/issue_59_spec.rb +26 -23
- data/tests/integration/powershell_spec.rb +154 -0
- data/{spec → tests/integration}/spec_helper.rb +65 -73
- data/{spec → tests/integration}/transport_spec.rb +99 -139
- data/{spec → tests/integration}/wql_spec.rb +16 -14
- data/{spec → tests}/matchers.rb +60 -74
- data/tests/spec/configuration_spec.rb +93 -0
- data/tests/spec/connection_spec.rb +39 -0
- data/{spec → tests/spec}/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -0
- data/tests/spec/http/transport_spec.rb +44 -0
- data/{spec → tests/spec}/output_spec.rb +127 -110
- data/tests/spec/psrp/fragment_spec.rb +62 -0
- data/tests/spec/psrp/message_data/base_spec.rb +13 -0
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
- data/tests/spec/psrp/message_data_spec.rb +35 -0
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
- data/tests/spec/psrp/psrp_message_spec.rb +70 -0
- data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
- data/tests/spec/psrp/uuid_spec.rb +28 -0
- data/{spec → tests/spec}/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -0
- data/tests/spec/shells/cmd_spec.rb +75 -0
- data/tests/spec/shells/powershell_spec.rb +175 -0
- data/tests/spec/spec_helper.rb +47 -0
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
- data/{spec → tests/spec}/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
- data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
- data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
- data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
- data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
- data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
- data/tests/spec/wsmv/close_shell_spec.rb +17 -0
- data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -0
- data/tests/spec/wsmv/command_spec.rb +19 -0
- data/tests/spec/wsmv/configuration_spec.rb +17 -0
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
- data/tests/spec/wsmv/create_shell_spec.rb +38 -0
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
- data/tests/spec/wsmv/send_data_spec.rb +30 -0
- data/tests/spec/wsmv/wql_query_spec.rb +13 -0
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
- data/winrm.gemspec +42 -40
- metadata +140 -38
- data/.rspec +0 -3
- data/lib/winrm/command_executor.rb +0 -243
- data/lib/winrm/command_output_decoder.rb +0 -53
- data/lib/winrm/helpers/iso8601_duration.rb +0 -58
- data/lib/winrm/helpers/powershell_script.rb +0 -42
- data/lib/winrm/soap_provider.rb +0 -39
- data/lib/winrm/winrm_service.rb +0 -550
- data/spec/command_executor_spec.rb +0 -475
- data/spec/issue_184_spec.rb +0 -67
- data/spec/powershell_spec.rb +0 -97
- data/spec/winrm_options_spec.rb +0 -76
- data/spec/winrm_primitives_spec.rb +0 -51
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'winrm/wsmv/send_data'
|
|
4
|
+
|
|
5
|
+
describe WinRM::WSMV::SendData do
|
|
6
|
+
context 'default session options' do
|
|
7
|
+
let(:shell_id) { 'D5A2622B-B842-4EB8-8A78-0225C8A993DF' }
|
|
8
|
+
let(:command_id) { 'D5A2622B-B842-4EB8-8A78-0225C8A993DF' }
|
|
9
|
+
let(:fragment) { WinRM::PSRP::Fragment.new(1, [1, 2, 3]) }
|
|
10
|
+
let(:pipeline) { Base64.strict_encode64(fragment.bytes.pack('C*')) }
|
|
11
|
+
|
|
12
|
+
subject do
|
|
13
|
+
described_class.new(
|
|
14
|
+
default_connection_opts,
|
|
15
|
+
shell_id,
|
|
16
|
+
command_id,
|
|
17
|
+
fragment
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
let(:xml) { subject.build }
|
|
21
|
+
it 'creates a well formed message' do
|
|
22
|
+
expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
|
|
23
|
+
expect(xml).to include(
|
|
24
|
+
'<w:SelectorSet><w:Selector Name="ShellId">' \
|
|
25
|
+
"#{shell_id}</w:Selector></w:SelectorSet>")
|
|
26
|
+
expect(xml).to include(
|
|
27
|
+
"<rsp:Stream Name=\"stdin\" CommandId=\"#{command_id}\">#{pipeline}</rsp:Stream>")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'winrm/wsmv/wql_query'
|
|
4
|
+
|
|
5
|
+
describe WinRM::WSMV::WqlQuery do
|
|
6
|
+
context 'default session options' do
|
|
7
|
+
subject { described_class.new(default_connection_opts, 'SELECT * FROM Win32') }
|
|
8
|
+
let(:xml) { subject.build }
|
|
9
|
+
it 'creates a well formed message' do
|
|
10
|
+
expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'winrm/wsmv/write_stdin'
|
|
5
|
+
|
|
6
|
+
describe WinRM::WSMV::WriteStdin do
|
|
7
|
+
context 'default session options' do
|
|
8
|
+
stdin_opts = {
|
|
9
|
+
shell_id: 'D5A2622B-B842-4EB8-8A78-0225C8A993DF',
|
|
10
|
+
command_id: 'A2A2622B-B842-4EB8-8A78-0225C8A993DF',
|
|
11
|
+
stdin: 'dir'
|
|
12
|
+
}
|
|
13
|
+
subject { described_class.new(default_connection_opts, stdin_opts) }
|
|
14
|
+
let(:xml) { subject.build }
|
|
15
|
+
it 'creates a well formed message' do
|
|
16
|
+
b64_stdin = Base64.encode64(stdin_opts[:stdin])
|
|
17
|
+
expect(xml).to include('<w:OperationTimeout>PT60S</w:OperationTimeout>')
|
|
18
|
+
expect(xml).to include('<rsp:Stream Name="stdin" ' \
|
|
19
|
+
"CommandId=\"A2A2622B-B842-4EB8-8A78-0225C8A993DF\">#{b64_stdin}</rsp:Stream>")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/winrm.gemspec
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'date'
|
|
3
|
-
require File.expand_path('../lib/winrm/version', __FILE__)
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |s|
|
|
6
|
-
s.platform = Gem::Platform::RUBY
|
|
7
|
-
s.name = 'winrm'
|
|
8
|
-
s.version = WinRM::VERSION
|
|
9
|
-
s.date = Date.today.to_s
|
|
10
|
-
|
|
11
|
-
s.author = ['Dan Wanek', 'Paul Morton']
|
|
12
|
-
s.email = ['dan.wanek@gmail.com', 'paul@themortonsonline.com']
|
|
13
|
-
s.homepage = 'https://github.com/WinRb/WinRM'
|
|
14
|
-
|
|
15
|
-
s.summary = 'Ruby library for Windows Remote Management'
|
|
16
|
-
s.description = <<-EOF
|
|
17
|
-
Ruby library for Windows Remote Management
|
|
18
|
-
EOF
|
|
19
|
-
s.license = 'Apache-2.0'
|
|
20
|
-
|
|
21
|
-
s.files = `git ls-files`.split(/\n/)
|
|
22
|
-
s.require_path = 'lib'
|
|
23
|
-
s.rdoc_options = %w(-x test/ -x examples/)
|
|
24
|
-
s.extra_rdoc_files = %w(README.md LICENSE)
|
|
25
|
-
|
|
26
|
-
s.bindir = 'bin'
|
|
27
|
-
s.executables = ['rwinrm']
|
|
28
|
-
s.required_ruby_version = '>= 1.9.0'
|
|
29
|
-
s.add_runtime_dependency 'gssapi', '~> 1.2'
|
|
30
|
-
s.add_runtime_dependency 'httpclient', '~> 2.2', '>= 2.2.0.2'
|
|
31
|
-
s.add_runtime_dependency 'rubyntlm', '~> 0.6.0'
|
|
32
|
-
s.add_runtime_dependency 'logging', ['>= 1.6.1', '< 3.0']
|
|
33
|
-
s.add_runtime_dependency 'nori', '~> 2.0'
|
|
34
|
-
s.add_runtime_dependency 'gyoku', '~> 1.0'
|
|
35
|
-
s.add_runtime_dependency 'builder', '>= 2.1.2'
|
|
36
|
-
s.
|
|
37
|
-
s.add_development_dependency '
|
|
38
|
-
s.add_development_dependency '
|
|
39
|
-
s.add_development_dependency '
|
|
40
|
-
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'date'
|
|
3
|
+
require File.expand_path('../lib/winrm/version', __FILE__)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.platform = Gem::Platform::RUBY
|
|
7
|
+
s.name = 'winrm'
|
|
8
|
+
s.version = WinRM::VERSION
|
|
9
|
+
s.date = Date.today.to_s
|
|
10
|
+
|
|
11
|
+
s.author = ['Dan Wanek', 'Paul Morton']
|
|
12
|
+
s.email = ['dan.wanek@gmail.com', 'paul@themortonsonline.com']
|
|
13
|
+
s.homepage = 'https://github.com/WinRb/WinRM'
|
|
14
|
+
|
|
15
|
+
s.summary = 'Ruby library for Windows Remote Management'
|
|
16
|
+
s.description = <<-EOF
|
|
17
|
+
Ruby library for Windows Remote Management
|
|
18
|
+
EOF
|
|
19
|
+
s.license = 'Apache-2.0'
|
|
20
|
+
|
|
21
|
+
s.files = `git ls-files`.split(/\n/)
|
|
22
|
+
s.require_path = 'lib'
|
|
23
|
+
s.rdoc_options = %w(-x test/ -x examples/)
|
|
24
|
+
s.extra_rdoc_files = %w(README.md LICENSE)
|
|
25
|
+
|
|
26
|
+
s.bindir = 'bin'
|
|
27
|
+
s.executables = ['rwinrm']
|
|
28
|
+
s.required_ruby_version = '>= 1.9.0'
|
|
29
|
+
s.add_runtime_dependency 'gssapi', '~> 1.2'
|
|
30
|
+
s.add_runtime_dependency 'httpclient', '~> 2.2', '>= 2.2.0.2'
|
|
31
|
+
s.add_runtime_dependency 'rubyntlm', '~> 0.6.0'
|
|
32
|
+
s.add_runtime_dependency 'logging', ['>= 1.6.1', '< 3.0']
|
|
33
|
+
s.add_runtime_dependency 'nori', '~> 2.0'
|
|
34
|
+
s.add_runtime_dependency 'gyoku', '~> 1.0'
|
|
35
|
+
s.add_runtime_dependency 'builder', '>= 2.1.2'
|
|
36
|
+
s.add_runtime_dependency 'erubis', '~> 2.7'
|
|
37
|
+
s.add_development_dependency 'rspec', '~> 3.2'
|
|
38
|
+
s.add_development_dependency 'rake', '~> 10.3'
|
|
39
|
+
s.add_development_dependency 'rubocop', '~> 0.39.0'
|
|
40
|
+
s.add_development_dependency 'pry'
|
|
41
|
+
s.add_development_dependency 'rb-readline'
|
|
42
|
+
end
|
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:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dan Wanek
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-
|
|
12
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: gssapi
|
|
@@ -121,6 +121,20 @@ dependencies:
|
|
|
121
121
|
- - ">="
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: 2.1.2
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: erubis
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '2.7'
|
|
131
|
+
type: :runtime
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - "~>"
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '2.7'
|
|
124
138
|
- !ruby/object:Gem::Dependency
|
|
125
139
|
name: rspec
|
|
126
140
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -155,14 +169,14 @@ dependencies:
|
|
|
155
169
|
requirements:
|
|
156
170
|
- - "~>"
|
|
157
171
|
- !ruby/object:Gem::Version
|
|
158
|
-
version:
|
|
172
|
+
version: 0.39.0
|
|
159
173
|
type: :development
|
|
160
174
|
prerelease: false
|
|
161
175
|
version_requirements: !ruby/object:Gem::Requirement
|
|
162
176
|
requirements:
|
|
163
177
|
- - "~>"
|
|
164
178
|
- !ruby/object:Gem::Version
|
|
165
|
-
version:
|
|
179
|
+
version: 0.39.0
|
|
166
180
|
- !ruby/object:Gem::Dependency
|
|
167
181
|
name: pry
|
|
168
182
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -177,8 +191,21 @@ dependencies:
|
|
|
177
191
|
- - ">="
|
|
178
192
|
- !ruby/object:Gem::Version
|
|
179
193
|
version: '0'
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
- !ruby/object:Gem::Dependency
|
|
195
|
+
name: rb-readline
|
|
196
|
+
requirement: !ruby/object:Gem::Requirement
|
|
197
|
+
requirements:
|
|
198
|
+
- - ">="
|
|
199
|
+
- !ruby/object:Gem::Version
|
|
200
|
+
version: '0'
|
|
201
|
+
type: :development
|
|
202
|
+
prerelease: false
|
|
203
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
204
|
+
requirements:
|
|
205
|
+
- - ">="
|
|
206
|
+
- !ruby/object:Gem::Version
|
|
207
|
+
version: '0'
|
|
208
|
+
description: " Ruby library for Windows Remote Management\n"
|
|
182
209
|
email:
|
|
183
210
|
- dan.wanek@gmail.com
|
|
184
211
|
- paul@themortonsonline.com
|
|
@@ -190,7 +217,6 @@ extra_rdoc_files:
|
|
|
190
217
|
- LICENSE
|
|
191
218
|
files:
|
|
192
219
|
- ".gitignore"
|
|
193
|
-
- ".rspec"
|
|
194
220
|
- ".rubocop.yml"
|
|
195
221
|
- ".travis.yml"
|
|
196
222
|
- Gemfile
|
|
@@ -203,41 +229,117 @@ files:
|
|
|
203
229
|
- bin/rwinrm
|
|
204
230
|
- changelog.md
|
|
205
231
|
- lib/winrm.rb
|
|
206
|
-
- lib/winrm/
|
|
207
|
-
- lib/winrm/
|
|
208
|
-
- lib/winrm/exceptions
|
|
209
|
-
- lib/winrm/helpers/iso8601_duration.rb
|
|
210
|
-
- lib/winrm/helpers/powershell_script.rb
|
|
232
|
+
- lib/winrm/connection.rb
|
|
233
|
+
- lib/winrm/connection_opts.rb
|
|
234
|
+
- lib/winrm/exceptions.rb
|
|
211
235
|
- lib/winrm/http/response_handler.rb
|
|
212
236
|
- lib/winrm/http/transport.rb
|
|
237
|
+
- lib/winrm/http/transport_factory.rb
|
|
213
238
|
- lib/winrm/output.rb
|
|
214
|
-
- lib/winrm/
|
|
239
|
+
- lib/winrm/psrp/create_pipeline.xml.erb
|
|
240
|
+
- lib/winrm/psrp/fragment.rb
|
|
241
|
+
- lib/winrm/psrp/init_runspace_pool.xml.erb
|
|
242
|
+
- lib/winrm/psrp/message.rb
|
|
243
|
+
- lib/winrm/psrp/message_data.rb
|
|
244
|
+
- lib/winrm/psrp/message_data/base.rb
|
|
245
|
+
- lib/winrm/psrp/message_data/error_record.rb
|
|
246
|
+
- lib/winrm/psrp/message_data/pipeline_host_call.rb
|
|
247
|
+
- lib/winrm/psrp/message_data/pipeline_output.rb
|
|
248
|
+
- lib/winrm/psrp/message_data/runspacepool_host_call.rb
|
|
249
|
+
- lib/winrm/psrp/message_data/runspacepool_state.rb
|
|
250
|
+
- lib/winrm/psrp/message_data/session_capability.rb
|
|
251
|
+
- lib/winrm/psrp/message_defragmenter.rb
|
|
252
|
+
- lib/winrm/psrp/message_factory.rb
|
|
253
|
+
- lib/winrm/psrp/message_fragmenter.rb
|
|
254
|
+
- lib/winrm/psrp/powershell_output_decoder.rb
|
|
255
|
+
- lib/winrm/psrp/receive_response_reader.rb
|
|
256
|
+
- lib/winrm/psrp/session_capability.xml.erb
|
|
257
|
+
- lib/winrm/psrp/uuid.rb
|
|
258
|
+
- lib/winrm/shells/base.rb
|
|
259
|
+
- lib/winrm/shells/cmd.rb
|
|
260
|
+
- lib/winrm/shells/power_shell.rb
|
|
261
|
+
- lib/winrm/shells/retryable.rb
|
|
262
|
+
- lib/winrm/shells/shell_factory.rb
|
|
215
263
|
- lib/winrm/version.rb
|
|
216
|
-
- lib/winrm/
|
|
264
|
+
- lib/winrm/wsmv/base.rb
|
|
265
|
+
- lib/winrm/wsmv/cleanup_command.rb
|
|
266
|
+
- lib/winrm/wsmv/close_shell.rb
|
|
267
|
+
- lib/winrm/wsmv/command.rb
|
|
268
|
+
- lib/winrm/wsmv/command_output.rb
|
|
269
|
+
- lib/winrm/wsmv/command_output_decoder.rb
|
|
270
|
+
- lib/winrm/wsmv/configuration.rb
|
|
271
|
+
- lib/winrm/wsmv/create_pipeline.rb
|
|
272
|
+
- lib/winrm/wsmv/create_shell.rb
|
|
273
|
+
- lib/winrm/wsmv/header.rb
|
|
274
|
+
- lib/winrm/wsmv/init_runspace_pool.rb
|
|
275
|
+
- lib/winrm/wsmv/iso8601_duration.rb
|
|
276
|
+
- lib/winrm/wsmv/keep_alive.rb
|
|
277
|
+
- lib/winrm/wsmv/receive_response_reader.rb
|
|
278
|
+
- lib/winrm/wsmv/send_data.rb
|
|
279
|
+
- lib/winrm/wsmv/soap.rb
|
|
280
|
+
- lib/winrm/wsmv/wql_query.rb
|
|
281
|
+
- lib/winrm/wsmv/write_stdin.rb
|
|
217
282
|
- preamble
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
224
|
-
-
|
|
225
|
-
-
|
|
226
|
-
-
|
|
227
|
-
- spec/
|
|
228
|
-
- spec/
|
|
229
|
-
- spec/
|
|
230
|
-
- spec/
|
|
231
|
-
- spec/
|
|
232
|
-
- spec/
|
|
233
|
-
- spec/
|
|
234
|
-
- spec/
|
|
235
|
-
- spec/
|
|
236
|
-
- spec/
|
|
237
|
-
- spec/
|
|
238
|
-
- spec/
|
|
239
|
-
- spec/
|
|
240
|
-
- spec/
|
|
283
|
+
- tests/integration/auth_timeout_spec.rb
|
|
284
|
+
- tests/integration/cmd_spec.rb
|
|
285
|
+
- tests/integration/config-example.yml
|
|
286
|
+
- tests/integration/issue_59_spec.rb
|
|
287
|
+
- tests/integration/powershell_spec.rb
|
|
288
|
+
- tests/integration/spec_helper.rb
|
|
289
|
+
- tests/integration/transport_spec.rb
|
|
290
|
+
- tests/integration/wql_spec.rb
|
|
291
|
+
- tests/matchers.rb
|
|
292
|
+
- tests/spec/configuration_spec.rb
|
|
293
|
+
- tests/spec/connection_spec.rb
|
|
294
|
+
- tests/spec/exception_spec.rb
|
|
295
|
+
- tests/spec/http/transport_factory_spec.rb
|
|
296
|
+
- tests/spec/http/transport_spec.rb
|
|
297
|
+
- tests/spec/output_spec.rb
|
|
298
|
+
- tests/spec/psrp/fragment_spec.rb
|
|
299
|
+
- tests/spec/psrp/message_data/base_spec.rb
|
|
300
|
+
- tests/spec/psrp/message_data/error_record_spec.rb
|
|
301
|
+
- tests/spec/psrp/message_data/pipeline_host_call_spec.rb
|
|
302
|
+
- tests/spec/psrp/message_data/pipeline_output_spec.rb
|
|
303
|
+
- tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb
|
|
304
|
+
- tests/spec/psrp/message_data/runspacepool_state_spec.rb
|
|
305
|
+
- tests/spec/psrp/message_data/session_capability_spec.rb
|
|
306
|
+
- tests/spec/psrp/message_data_spec.rb
|
|
307
|
+
- tests/spec/psrp/message_defragmenter_spec.rb
|
|
308
|
+
- tests/spec/psrp/message_fragmenter_spec.rb
|
|
309
|
+
- tests/spec/psrp/powershell_output_decoder_spec.rb
|
|
310
|
+
- tests/spec/psrp/psrp_message_spec.rb
|
|
311
|
+
- tests/spec/psrp/recieve_response_reader_spec.rb
|
|
312
|
+
- tests/spec/psrp/uuid_spec.rb
|
|
313
|
+
- tests/spec/response_handler_spec.rb
|
|
314
|
+
- tests/spec/shells/base_spec.rb
|
|
315
|
+
- tests/spec/shells/cmd_spec.rb
|
|
316
|
+
- tests/spec/shells/powershell_spec.rb
|
|
317
|
+
- tests/spec/spec_helper.rb
|
|
318
|
+
- tests/spec/stubs/clixml/error_record.xml.erb
|
|
319
|
+
- tests/spec/stubs/responses/get_command_output_response.xml.erb
|
|
320
|
+
- tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb
|
|
321
|
+
- tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb
|
|
322
|
+
- tests/spec/stubs/responses/get_powershell_output_response.xml.erb
|
|
323
|
+
- tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb
|
|
324
|
+
- tests/spec/stubs/responses/open_shell_v1.xml
|
|
325
|
+
- tests/spec/stubs/responses/open_shell_v2.xml
|
|
326
|
+
- tests/spec/stubs/responses/soap_fault_v1.xml
|
|
327
|
+
- tests/spec/stubs/responses/soap_fault_v2.xml
|
|
328
|
+
- tests/spec/stubs/responses/wmi_error_v2.xml
|
|
329
|
+
- tests/spec/wsmv/cleanup_command_spec.rb
|
|
330
|
+
- tests/spec/wsmv/close_shell_spec.rb
|
|
331
|
+
- tests/spec/wsmv/command_output_decoder_spec.rb
|
|
332
|
+
- tests/spec/wsmv/command_output_spec.rb
|
|
333
|
+
- tests/spec/wsmv/command_spec.rb
|
|
334
|
+
- tests/spec/wsmv/configuration_spec.rb
|
|
335
|
+
- tests/spec/wsmv/create_pipeline_spec.rb
|
|
336
|
+
- tests/spec/wsmv/create_shell_spec.rb
|
|
337
|
+
- tests/spec/wsmv/init_runspace_pool_spec.rb
|
|
338
|
+
- tests/spec/wsmv/keep_alive_spec.rb
|
|
339
|
+
- tests/spec/wsmv/receive_response_reader_spec.rb
|
|
340
|
+
- tests/spec/wsmv/send_data_spec.rb
|
|
341
|
+
- tests/spec/wsmv/wql_query_spec.rb
|
|
342
|
+
- tests/spec/wsmv/write_stdin_spec.rb
|
|
241
343
|
- winrm.gemspec
|
|
242
344
|
homepage: https://github.com/WinRb/WinRM
|
|
243
345
|
licenses:
|
|
@@ -263,7 +365,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
263
365
|
version: '0'
|
|
264
366
|
requirements: []
|
|
265
367
|
rubyforge_project:
|
|
266
|
-
rubygems_version: 2.6.
|
|
368
|
+
rubygems_version: 2.6.6
|
|
267
369
|
signing_key:
|
|
268
370
|
specification_version: 4
|
|
269
371
|
summary: Ruby library for Windows Remote Management
|
data/.rspec
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
#
|
|
3
|
-
# Copyright 2015 Shawn Neal <sneal@sneal.net>
|
|
4
|
-
# Copyright 2015 Matt Wrock <matt@mattwrock.com>
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
module WinRM
|
|
19
|
-
# Object which can execute multiple commands and Powershell scripts in
|
|
20
|
-
# one shared remote shell session. The maximum number of commands per
|
|
21
|
-
# shell is determined by interrogating the remote host when the session
|
|
22
|
-
# is opened and the remote shell is automatically recycled before the
|
|
23
|
-
# threshold is reached.
|
|
24
|
-
#
|
|
25
|
-
# @author Shawn Neal <sneal@sneal.net>
|
|
26
|
-
# @author Matt Wrock <matt@mattwrock.com>
|
|
27
|
-
# @author Fletcher Nichol <fnichol@nichol.ca>
|
|
28
|
-
class CommandExecutor
|
|
29
|
-
# Closes an open remote shell session left open
|
|
30
|
-
# after a command executor is garbage collecyted.
|
|
31
|
-
#
|
|
32
|
-
# @param shell_id [String] the remote shell identifier
|
|
33
|
-
# @param service [WinRM::WinRMWebService] a winrm web service object
|
|
34
|
-
def self.finalize(shell_id, service)
|
|
35
|
-
proc { service.close_shell(shell_id) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# @return [WinRM::WinRMWebService] a WinRM web service object
|
|
39
|
-
attr_reader :service
|
|
40
|
-
|
|
41
|
-
# @return [String,nil] the identifier for the current open remote
|
|
42
|
-
# shell session, or `nil` if the session is not open
|
|
43
|
-
attr_reader :shell
|
|
44
|
-
|
|
45
|
-
# Creates a CommandExecutor given a `WinRM::WinRMWebService` object.
|
|
46
|
-
#
|
|
47
|
-
# @param service [WinRM::WinRMWebService] a winrm web service object
|
|
48
|
-
# responds to `#debug` and `#info` (default: `nil`)
|
|
49
|
-
def initialize(service)
|
|
50
|
-
@service = service
|
|
51
|
-
@command_count = 0
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Closes the open remote shell session. This method can be called
|
|
55
|
-
# multiple times, even if there is no open session.
|
|
56
|
-
def close
|
|
57
|
-
return if shell.nil?
|
|
58
|
-
|
|
59
|
-
service.close_shell(shell)
|
|
60
|
-
remove_finalizer
|
|
61
|
-
@shell = nil
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Opens a remote shell session for reuse. The maxiumum
|
|
65
|
-
# command-per-shell threshold is also determined the first time this
|
|
66
|
-
# method is invoked and cached for later invocations.
|
|
67
|
-
#
|
|
68
|
-
# @return [String] the remote shell session indentifier
|
|
69
|
-
def open
|
|
70
|
-
close
|
|
71
|
-
retryable(service.retry_limit, service.retry_delay) do
|
|
72
|
-
@shell = service.open_shell(codepage: code_page)
|
|
73
|
-
end
|
|
74
|
-
add_finalizer(shell)
|
|
75
|
-
@command_count = 0
|
|
76
|
-
shell
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Runs a CMD command.
|
|
80
|
-
#
|
|
81
|
-
# @param command [String] the command to run on the remote system
|
|
82
|
-
# @param arguments [Array<String>] arguments to the command
|
|
83
|
-
# @yield [stdout, stderr] yields more live access the standard
|
|
84
|
-
# output and standard error streams as they are returns, if
|
|
85
|
-
# streaming behavior is desired
|
|
86
|
-
# @return [WinRM::Output] output object with stdout, stderr, and
|
|
87
|
-
# exit code
|
|
88
|
-
def run_cmd(command, arguments = [], &block)
|
|
89
|
-
tries ||= 2
|
|
90
|
-
|
|
91
|
-
reset if command_count > max_commands
|
|
92
|
-
ensure_open_shell!
|
|
93
|
-
|
|
94
|
-
@command_count += 1
|
|
95
|
-
result = nil
|
|
96
|
-
service.run_command(shell, command, arguments) do |command_id|
|
|
97
|
-
result = service.get_command_output(shell, command_id, &block)
|
|
98
|
-
end
|
|
99
|
-
result
|
|
100
|
-
rescue WinRMWSManFault => e
|
|
101
|
-
# Fault code 2150858843 may be raised if the shell id that the command is sent on
|
|
102
|
-
# has been closed. One might see this on a target windows machine that has just
|
|
103
|
-
# been provisioned and restarted the winrm service at the end of its provisioning
|
|
104
|
-
# routine. If this hapens, we should give the command one more try.
|
|
105
|
-
|
|
106
|
-
# Fault code 2147943418 may be raised if the shell is installing an msi and for
|
|
107
|
-
# some reason it tries to read a registry key that has been deleted. This sometimes
|
|
108
|
-
# happens for 2008r2 when installing the Chef omnibus msi.
|
|
109
|
-
if %w(2150858843 2147943418).include?(e.fault_code) && (tries -= 1) > 0
|
|
110
|
-
service.logger.debug('[WinRM] opening new shell since the current one failed')
|
|
111
|
-
@shell = nil
|
|
112
|
-
open
|
|
113
|
-
retry
|
|
114
|
-
else
|
|
115
|
-
raise
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# Run a Powershell script that resides on the local box.
|
|
120
|
-
#
|
|
121
|
-
# @param script_file [IO,String] an IO reference for reading the
|
|
122
|
-
# Powershell script or the actual file contents
|
|
123
|
-
# @yield [stdout, stderr] yields more live access the standard
|
|
124
|
-
# output and standard error streams as they are returns, if
|
|
125
|
-
# streaming behavior is desired
|
|
126
|
-
# @return [WinRM::Output] output object with stdout, stderr, and
|
|
127
|
-
# exit code
|
|
128
|
-
def run_powershell_script(script_file, &block)
|
|
129
|
-
# this code looks overly compact in an attempt to limit local
|
|
130
|
-
# variable assignments that may contain large strings and
|
|
131
|
-
# consequently bloat the Ruby VM
|
|
132
|
-
run_cmd(
|
|
133
|
-
'powershell',
|
|
134
|
-
[
|
|
135
|
-
'-encodedCommand',
|
|
136
|
-
::WinRM::PowershellScript.new(
|
|
137
|
-
script_file.is_a?(IO) ? script_file.read : script_file
|
|
138
|
-
).encoded
|
|
139
|
-
],
|
|
140
|
-
&block
|
|
141
|
-
)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# Code page appropriate to os version. utf-8 (65001) is buggy pre win7/2k8r2
|
|
145
|
-
# So send MS-DOS (437) for earlier versions
|
|
146
|
-
#
|
|
147
|
-
# @return [Integer] code page in use
|
|
148
|
-
def code_page
|
|
149
|
-
@code_page ||= os_version < Gem::Version.new('6.1') ? 437 : 65_001
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# @return [Integer] the safe maximum number of commands that can
|
|
153
|
-
# be executed in one remote shell session
|
|
154
|
-
def max_commands
|
|
155
|
-
@max_commands ||= (os_version < Gem::Version.new('6.2') ? 15 : 1500) - 2
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
private
|
|
159
|
-
|
|
160
|
-
# @return [Integer] the number of executed commands on the remote
|
|
161
|
-
# shell session
|
|
162
|
-
# @api private
|
|
163
|
-
attr_accessor :command_count
|
|
164
|
-
|
|
165
|
-
# Creates a finalizer for this connection which will close the open
|
|
166
|
-
# remote shell session when the object is garabage collected or on
|
|
167
|
-
# Ruby VM shutdown.
|
|
168
|
-
#
|
|
169
|
-
# @param shell_id [String] the remote shell identifier
|
|
170
|
-
# @api private
|
|
171
|
-
def add_finalizer(shell_id)
|
|
172
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(shell_id, service))
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# Ensures that there is an open remote shell session.
|
|
176
|
-
#
|
|
177
|
-
# @raise [WinRM::WinRMError] if there is no open shell
|
|
178
|
-
# @api private
|
|
179
|
-
def ensure_open_shell!
|
|
180
|
-
fail ::WinRM::WinRMError, "#{self.class}#open must be called " \
|
|
181
|
-
'before any run methods are invoked' if shell.nil?
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
# Fetches the OS build bersion of the remote endpoint
|
|
185
|
-
#
|
|
186
|
-
# @api private
|
|
187
|
-
def os_version
|
|
188
|
-
@os_version ||= begin
|
|
189
|
-
version = nil
|
|
190
|
-
wql = service.run_wql('select version from Win32_OperatingSystem')
|
|
191
|
-
if wql[:xml_fragment]
|
|
192
|
-
version = wql[:xml_fragment].first[:version] if wql[:xml_fragment].first[:version]
|
|
193
|
-
end
|
|
194
|
-
fail ::WinRM::WinRMError, 'Unable to determine endpoint os version' if version.nil?
|
|
195
|
-
Gem::Version.new(version)
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
# Removes any finalizers for this connection.
|
|
200
|
-
#
|
|
201
|
-
# @api private
|
|
202
|
-
def remove_finalizer
|
|
203
|
-
ObjectSpace.undefine_finalizer(self)
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
# Closes the remote shell session and opens a new one.
|
|
207
|
-
#
|
|
208
|
-
# @api private
|
|
209
|
-
def reset
|
|
210
|
-
service.logger.debug("Resetting WinRM shell (Max command limit is #{max_commands})")
|
|
211
|
-
open
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
# Yields to a block and reties the block if certain rescuable
|
|
215
|
-
# exceptions are raised.
|
|
216
|
-
#
|
|
217
|
-
# @param retries [Integer] the number of times to retry before failing
|
|
218
|
-
# @option delay [Float] the number of seconds to wait until
|
|
219
|
-
# attempting a retry
|
|
220
|
-
# @api private
|
|
221
|
-
def retryable(retries, delay)
|
|
222
|
-
yield
|
|
223
|
-
rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH.call => e
|
|
224
|
-
if (retries -= 1) > 0
|
|
225
|
-
service.logger.info("[WinRM] connection failed. retrying in #{delay} seconds: #{e.inspect}")
|
|
226
|
-
sleep(delay)
|
|
227
|
-
retry
|
|
228
|
-
else
|
|
229
|
-
service.logger.warn("[WinRM] connection failed, terminating (#{e.inspect})")
|
|
230
|
-
raise
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
RESCUE_EXCEPTIONS_ON_ESTABLISH = lambda do
|
|
235
|
-
[
|
|
236
|
-
Errno::EACCES, Errno::EADDRINUSE, Errno::ECONNREFUSED, Errno::ETIMEDOUT,
|
|
237
|
-
Errno::ECONNRESET, Errno::ENETUNREACH, Errno::EHOSTUNREACH,
|
|
238
|
-
::WinRM::WinRMHTTPTransportError, ::WinRM::WinRMAuthorizationError,
|
|
239
|
-
HTTPClient::KeepAliveDisconnected, HTTPClient::ConnectTimeoutError
|
|
240
|
-
].freeze
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
end
|