winrm 2.2.3 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/bin/rwinrm +90 -97
  4. data/lib/winrm/connection.rb +84 -86
  5. data/lib/winrm/connection_opts.rb +90 -91
  6. data/lib/winrm/exceptions.rb +14 -2
  7. data/lib/winrm/http/response_handler.rb +127 -96
  8. data/lib/winrm/http/transport.rb +462 -427
  9. data/lib/winrm/http/transport_factory.rb +1 -5
  10. data/lib/winrm/output.rb +1 -2
  11. data/lib/winrm/psrp/fragment.rb +0 -2
  12. data/lib/winrm/psrp/message.rb +128 -130
  13. data/lib/winrm/psrp/message_data/base.rb +0 -2
  14. data/lib/winrm/psrp/message_data/error_record.rb +2 -2
  15. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
  16. data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
  17. data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
  18. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
  19. data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
  20. data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
  21. data/lib/winrm/psrp/message_data.rb +0 -2
  22. data/lib/winrm/psrp/message_defragmenter.rb +2 -2
  23. data/lib/winrm/psrp/message_factory.rb +16 -5
  24. data/lib/winrm/psrp/message_fragmenter.rb +1 -3
  25. data/lib/winrm/psrp/powershell_output_decoder.rb +142 -144
  26. data/lib/winrm/psrp/receive_response_reader.rb +3 -5
  27. data/lib/winrm/psrp/uuid.rb +1 -2
  28. data/lib/winrm/shells/base.rb +7 -4
  29. data/lib/winrm/shells/cmd.rb +63 -65
  30. data/lib/winrm/shells/power_shell.rb +207 -202
  31. data/lib/winrm/shells/retryable.rb +44 -45
  32. data/lib/winrm/shells/shell_factory.rb +0 -2
  33. data/lib/winrm/version.rb +1 -3
  34. data/lib/winrm/wsmv/base.rb +0 -2
  35. data/lib/winrm/wsmv/cleanup_command.rb +1 -2
  36. data/lib/winrm/wsmv/close_shell.rb +1 -2
  37. data/lib/winrm/wsmv/command.rb +2 -3
  38. data/lib/winrm/wsmv/command_output.rb +2 -3
  39. data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
  40. data/lib/winrm/wsmv/configuration.rb +0 -2
  41. data/lib/winrm/wsmv/create_pipeline.rb +0 -2
  42. data/lib/winrm/wsmv/create_shell.rb +2 -6
  43. data/lib/winrm/wsmv/header.rb +213 -215
  44. data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
  45. data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
  46. data/lib/winrm/wsmv/keep_alive.rb +0 -2
  47. data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
  48. data/lib/winrm/wsmv/send_data.rb +0 -2
  49. data/lib/winrm/wsmv/soap.rb +0 -2
  50. data/lib/winrm/wsmv/wql_pull.rb +54 -56
  51. data/lib/winrm/wsmv/wql_query.rb +98 -99
  52. data/lib/winrm/wsmv/write_stdin.rb +0 -2
  53. data/lib/winrm.rb +3 -5
  54. metadata +81 -135
  55. data/.gitignore +0 -10
  56. data/.rubocop.yml +0 -26
  57. data/.travis.yml +0 -11
  58. data/Gemfile +0 -3
  59. data/Rakefile +0 -34
  60. data/Vagrantfile +0 -6
  61. data/WinrmAppveyor.psm1 +0 -32
  62. data/appveyor.yml +0 -51
  63. data/changelog.md +0 -128
  64. data/preamble +0 -17
  65. data/tests/integration/auth_timeout_spec.rb +0 -18
  66. data/tests/integration/cmd_spec.rb +0 -131
  67. data/tests/integration/config-example.yml +0 -16
  68. data/tests/integration/issue_59_spec.rb +0 -26
  69. data/tests/integration/powershell_spec.rb +0 -165
  70. data/tests/integration/spec_helper.rb +0 -65
  71. data/tests/integration/transport_spec.rb +0 -99
  72. data/tests/integration/wql_spec.rb +0 -34
  73. data/tests/matchers.rb +0 -60
  74. data/tests/spec/configuration_spec.rb +0 -184
  75. data/tests/spec/connection_spec.rb +0 -39
  76. data/tests/spec/exception_spec.rb +0 -50
  77. data/tests/spec/http/transport_factory_spec.rb +0 -68
  78. data/tests/spec/http/transport_spec.rb +0 -44
  79. data/tests/spec/output_spec.rb +0 -127
  80. data/tests/spec/psrp/fragment_spec.rb +0 -62
  81. data/tests/spec/psrp/message_data/base_spec.rb +0 -13
  82. data/tests/spec/psrp/message_data/error_record_spec.rb +0 -41
  83. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -25
  84. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -32
  85. data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -40
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -25
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -16
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -30
  89. data/tests/spec/psrp/message_data_spec.rb +0 -35
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +0 -47
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +0 -105
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -100
  93. data/tests/spec/psrp/psrp_message_spec.rb +0 -70
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -172
  95. data/tests/spec/psrp/uuid_spec.rb +0 -28
  96. data/tests/spec/response_handler_spec.rb +0 -61
  97. data/tests/spec/shells/base_spec.rb +0 -225
  98. data/tests/spec/shells/cmd_spec.rb +0 -75
  99. data/tests/spec/shells/powershell_spec.rb +0 -175
  100. data/tests/spec/spec_helper.rb +0 -47
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
  102. data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
  103. data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
  104. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
  105. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
  106. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
  107. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
  108. data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
  109. data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
  110. data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
  111. data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
  112. data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
  113. data/tests/spec/wsmv/cleanup_command_spec.rb +0 -22
  114. data/tests/spec/wsmv/close_shell_spec.rb +0 -17
  115. data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -37
  116. data/tests/spec/wsmv/command_output_spec.rb +0 -45
  117. data/tests/spec/wsmv/command_spec.rb +0 -19
  118. data/tests/spec/wsmv/configuration_spec.rb +0 -17
  119. data/tests/spec/wsmv/create_pipeline_spec.rb +0 -31
  120. data/tests/spec/wsmv/create_shell_spec.rb +0 -38
  121. data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -36
  122. data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
  123. data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -123
  124. data/tests/spec/wsmv/send_data_spec.rb +0 -30
  125. data/tests/spec/wsmv/wql_query_spec.rb +0 -13
  126. data/tests/spec/wsmv/write_stdin_spec.rb +0 -22
  127. data/winrm.gemspec +0 -47
@@ -1,144 +1,142 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Copyright 2016 Matt Wrock <matt@mattwrock.com>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require 'base64'
18
- require_relative 'message'
19
- require_relative 'message_data/pipeline_state'
20
-
21
- module WinRM
22
- module PSRP
23
- # Handles decoding a raw powershell output response
24
- class PowershellOutputDecoder
25
- # rubocop:disable Metrics/CyclomaticComplexity
26
- # Decode the raw SOAP output into decoded PSRP message,
27
- # Removes BOM and replaces encoded line endings
28
- # @param raw_output [String] The raw encoded output
29
- # @return [String] The decoded output
30
- def decode(message)
31
- case message.type
32
- when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output]
33
- decode_pipeline_output(message)
34
- when WinRM::PSRP::Message::MESSAGE_TYPES[:runspacepool_host_call]
35
- decode_host_call(message)
36
- when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call]
37
- decode_host_call(message)
38
- when WinRM::PSRP::Message::MESSAGE_TYPES[:error_record]
39
- decode_error_record(message)
40
- when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
41
- if message.parsed_data.pipeline_state == WinRM::PSRP::MessageData::PipelineState::FAILED
42
- decode_error_record(message)
43
- end
44
- end
45
- end
46
- # rubocop:enable Metrics/CyclomaticComplexity
47
-
48
- protected
49
-
50
- def decode_pipeline_output(message)
51
- message.parsed_data.output
52
- end
53
-
54
- def decode_host_call(message)
55
- text = begin
56
- case message.parsed_data.method_identifier
57
- when /WriteLine/, 'WriteErrorLine'
58
- "#{message.parsed_data.method_parameters[:s]}\r\n"
59
- when 'WriteDebugLine'
60
- "Debug: #{message.parsed_data.method_parameters[:s]}\r\n"
61
- when 'WriteWarningLine'
62
- "Warning: #{message.parsed_data.method_parameters[:s]}\r\n"
63
- when 'WriteVerboseLine'
64
- "Verbose: #{message.parsed_data.method_parameters[:s]}\r\n"
65
- when /Write[1-2]/
66
- message.parsed_data.method_parameters[:s]
67
- end
68
- end
69
-
70
- hex_decode(text)
71
- end
72
-
73
- def decode_error_record(message)
74
- parsed = message.parsed_data
75
- text = begin
76
- if message.type == WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
77
- render_exception_as_error_record(parsed.exception_as_error_record)
78
- else
79
- case parsed.fully_qualified_error_id
80
- when 'Microsoft.PowerShell.Commands.WriteErrorException'
81
- render_write_error_exception(parsed)
82
- when 'NativeCommandError'
83
- render_native_command_error(parsed)
84
- when 'NativeCommandErrorMessage'
85
- parsed.exception[:message]
86
- else
87
- render_exception(parsed)
88
- end
89
- end
90
- end
91
-
92
- hex_decode(text)
93
- end
94
-
95
- def render_write_error_exception(parsed)
96
- <<EOH
97
- #{parsed.invocation_info[:line]} : #{parsed.exception[:message]}
98
- + CategoryInfo : #{parsed.error_category_message}
99
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
100
- EOH
101
- end
102
-
103
- def render_exception(parsed)
104
- <<EOH
105
- #{parsed.exception[:message]}
106
- #{parsed.invocation_info[:position_message]}
107
- + CategoryInfo : #{parsed.error_category_message}
108
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
109
- EOH
110
- end
111
-
112
- def render_native_command_error(parsed)
113
- <<EOH
114
- #{parsed.invocation_info[:my_command]} : #{parsed.exception[:message]}
115
- + CategoryInfo : #{parsed.error_category_message}
116
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
117
- EOH
118
- end
119
-
120
- def render_exception_as_error_record(parsed)
121
- <<EOH
122
- #{parsed.exception[:message]}
123
- + CategoryInfo : #{parsed.error_category_message}
124
- + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
125
- EOH
126
- end
127
-
128
- private
129
-
130
- def hex_decode(text)
131
- return unless text
132
-
133
- text.gsub(/_x(\h\h\h\h)_/) do
134
- decoded_text = Regexp.last_match[1].hex.chr.force_encoding('utf-8')
135
- if decoded_text.respond_to?(:scrub)
136
- decoded_text.scrub
137
- else
138
- decoded_text.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8')
139
- end
140
- end
141
- end
142
- end
143
- end
144
- end
1
+ # Copyright 2016 Matt Wrock <matt@mattwrock.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'base64' unless defined?(Base64)
16
+ require_relative 'message'
17
+ require_relative 'message_data/pipeline_state'
18
+
19
+ module WinRM
20
+ module PSRP
21
+ # Handles decoding a raw powershell output response
22
+ class PowershellOutputDecoder
23
+ # rubocop:disable Metrics/CyclomaticComplexity
24
+ # Decode the raw SOAP output into decoded PSRP message,
25
+ # Removes BOM and replaces encoded line endings
26
+ # @param raw_output [String] The raw encoded output
27
+ # @return [String] The decoded output
28
+ def decode(message)
29
+ case message.type
30
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output]
31
+ decode_pipeline_output(message)
32
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:runspacepool_host_call]
33
+ decode_host_call(message)
34
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call]
35
+ decode_host_call(message)
36
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:error_record]
37
+ decode_error_record(message)
38
+ when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
39
+ if message.parsed_data.pipeline_state == WinRM::PSRP::MessageData::PipelineState::FAILED
40
+ decode_error_record(message)
41
+ end
42
+ end
43
+ end
44
+ # rubocop:enable Metrics/CyclomaticComplexity
45
+
46
+ protected
47
+
48
+ def decode_pipeline_output(message)
49
+ message.parsed_data.output
50
+ end
51
+
52
+ def decode_host_call(message)
53
+ text = begin
54
+ case message.parsed_data.method_identifier
55
+ when /WriteLine/, 'WriteErrorLine'
56
+ "#{message.parsed_data.method_parameters[:s]}\r\n"
57
+ when 'WriteDebugLine'
58
+ "Debug: #{message.parsed_data.method_parameters[:s]}\r\n"
59
+ when 'WriteWarningLine'
60
+ "Warning: #{message.parsed_data.method_parameters[:s]}\r\n"
61
+ when 'WriteVerboseLine'
62
+ "Verbose: #{message.parsed_data.method_parameters[:s]}\r\n"
63
+ when /Write[1-2]/
64
+ message.parsed_data.method_parameters[:s]
65
+ end
66
+ end
67
+
68
+ hex_decode(text)
69
+ end
70
+
71
+ def decode_error_record(message)
72
+ parsed = message.parsed_data
73
+ text = begin
74
+ if message.type == WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
75
+ render_exception_as_error_record(parsed.exception_as_error_record)
76
+ else
77
+ case parsed.fully_qualified_error_id
78
+ when 'Microsoft.PowerShell.Commands.WriteErrorException'
79
+ render_write_error_exception(parsed)
80
+ when 'NativeCommandError'
81
+ render_native_command_error(parsed)
82
+ when 'NativeCommandErrorMessage'
83
+ parsed.exception[:message]
84
+ else
85
+ render_exception(parsed)
86
+ end
87
+ end
88
+ end
89
+
90
+ hex_decode(text)
91
+ end
92
+
93
+ def render_write_error_exception(parsed)
94
+ <<EOH
95
+ #{parsed.invocation_info[:line]} : #{parsed.exception[:message]}
96
+ + CategoryInfo : #{parsed.error_category_message}
97
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
98
+ EOH
99
+ end
100
+
101
+ def render_exception(parsed)
102
+ <<EOH
103
+ #{parsed.exception[:message]}
104
+ #{parsed.invocation_info[:position_message]}
105
+ + CategoryInfo : #{parsed.error_category_message}
106
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
107
+ EOH
108
+ end
109
+
110
+ def render_native_command_error(parsed)
111
+ <<EOH
112
+ #{parsed.invocation_info[:my_command]} : #{parsed.exception[:message]}
113
+ + CategoryInfo : #{parsed.error_category_message}
114
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
115
+ EOH
116
+ end
117
+
118
+ def render_exception_as_error_record(parsed)
119
+ <<EOH
120
+ #{parsed.exception[:message]}
121
+ + CategoryInfo : #{parsed.error_category_message}
122
+ + FullyQualifiedErrorId : #{parsed.fully_qualified_error_id}
123
+ EOH
124
+ end
125
+
126
+ private
127
+
128
+ def hex_decode(text)
129
+ return unless text
130
+
131
+ text.gsub(/_x(\h\h\h\h)_/) do
132
+ decoded_text = Regexp.last_match[1].hex.chr.force_encoding('utf-8')
133
+ if decoded_text.respond_to?(:scrub)
134
+ decoded_text.scrub
135
+ else
136
+ decoded_text.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8')
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
1
  # Copyright 2016 Matt Wrock <matt@mattwrock.com>
4
2
  #
5
3
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,6 +39,7 @@ module WinRM
41
39
  read_response(wsmv_message, wait_for_done_state) do |stream|
42
40
  message = defragmenter.defragment(stream[:text])
43
41
  next unless message
42
+
44
43
  if block_given?
45
44
  yield message
46
45
  else
@@ -62,6 +61,7 @@ module WinRM
62
61
  output.exitcode = exit_code if exit_code
63
62
  decoded_text = @output_decoder.decode(message)
64
63
  next unless decoded_text
64
+
65
65
  out = { stream_type(message) => decoded_text }
66
66
  output << out
67
67
  yield [out[:stdout], out[:stderr]] if block_given?
@@ -79,9 +79,7 @@ module WinRM
79
79
  when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_host_call]
80
80
  type = :stderr if message.data.include?('WriteError')
81
81
  when WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state]
82
- if message.parsed_data.pipeline_state == WinRM::PSRP::MessageData::PipelineState::FAILED
83
- type = :stderr
84
- end
82
+ type = :stderr if message.parsed_data.pipeline_state == WinRM::PSRP::MessageData::PipelineState::FAILED
85
83
  end
86
84
  type
87
85
  end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
- #
3
1
  # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
2
  #
5
3
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,6 +30,7 @@ module WinRM
32
30
  # @return [Array<byte>] UUID in a Windows GUID compatible byte array layout.
33
31
  def uuid_to_windows_guid_bytes(uuid)
34
32
  return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] unless uuid
33
+
35
34
  b = uuid.scan(/[0-9a-fA-F]{2}/).map { |x| x.to_i(16) }
36
35
  b[0..3].reverse + b[4..5].reverse + b[6..7].reverse + b[8..15]
37
36
  end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
1
  # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
2
  #
5
3
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -86,6 +84,7 @@ module WinRM
86
84
  # Closes the shell if one is open
87
85
  def close
88
86
  return unless shell_id
87
+
89
88
  begin
90
89
  self.class.close_shell(connection_opts, transport, shell_id)
91
90
  rescue WinRMWSManFault => e
@@ -132,6 +131,7 @@ module WinRM
132
131
  yield shell_id, command_id
133
132
  rescue WinRMWSManFault => e
134
133
  raise unless FAULTS_FOR_RESET.include?(e.fault_code) && (tries -= 1) > 0
134
+
135
135
  reset_on_error(e)
136
136
  retry
137
137
  ensure
@@ -147,12 +147,14 @@ module WinRM
147
147
  end
148
148
 
149
149
  def cleanup_command(command_id)
150
+ return unless shell_id
150
151
  logger.debug("[WinRM] cleaning up command_id: #{command_id} on shell_id #{shell_id}")
151
152
  cleanup_msg = WinRM::WSMV::CleanupCommand.new(
152
153
  connection_opts,
153
154
  shell_uri: shell_uri,
154
155
  shell_id: shell_id,
155
- command_id: command_id)
156
+ command_id: command_id
157
+ )
156
158
  transport.send_request(cleanup_msg.build)
157
159
  rescue WinRMWSManFault => e
158
160
  raise unless [ERROR_OPERATION_ABORTED, SHELL_NOT_FOUND].include?(e.fault_code)
@@ -174,7 +176,8 @@ module WinRM
174
176
  def add_finalizer
175
177
  ObjectSpace.define_finalizer(
176
178
  self,
177
- self.class.finalize(connection_opts, transport, shell_id))
179
+ self.class.finalize(connection_opts, transport, shell_id)
180
+ )
178
181
  end
179
182
 
180
183
  def remove_finalizer
@@ -1,65 +1,63 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Copyright 2016 Shawn Neal <sneal@sneal.net>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require_relative 'base'
18
-
19
- module WinRM
20
- module Shells
21
- # Proxy to a remote cmd.exe shell
22
- class Cmd < Base
23
- include WinRM::WSMV::SOAP
24
- class << self
25
- def finalize(connection_opts, transport, shell_id)
26
- proc { Cmd.close_shell(connection_opts, transport, shell_id) }
27
- end
28
-
29
- def close_shell(connection_opts, transport, shell_id)
30
- msg = WinRM::WSMV::CloseShell.new(connection_opts, shell_id: shell_id)
31
- transport.send_request(msg.build)
32
- end
33
- end
34
-
35
- protected
36
-
37
- def send_command(command, arguments)
38
- cmd_msg = WinRM::WSMV::Command.new(
39
- connection_opts,
40
- shell_id: shell_id,
41
- command: command,
42
- arguments: arguments
43
- )
44
- resp_doc = transport.send_request(cmd_msg.build)
45
- command_id = REXML::XPath.first(resp_doc, "//#{NS_WIN_SHELL}:CommandId").text
46
- logger.debug("[WinRM] Command created for #{command} with id: #{command_id}")
47
- command_id
48
- end
49
-
50
- def response_reader
51
- @response_reader ||= WinRM::WSMV::ReceiveResponseReader.new(transport, logger)
52
- end
53
-
54
- def open_shell
55
- msg = WinRM::WSMV::CreateShell.new(connection_opts, shell_opts)
56
- resp_doc = transport.send_request(msg.build)
57
- REXML::XPath.first(resp_doc, "//*[@Name='ShellId']").text
58
- end
59
-
60
- def out_streams
61
- %w(stdout stderr)
62
- end
63
- end
64
- end
65
- end
1
+ # Copyright 2016 Shawn Neal <sneal@sneal.net>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'base'
16
+
17
+ module WinRM
18
+ module Shells
19
+ # Proxy to a remote cmd.exe shell
20
+ class Cmd < Base
21
+ include WinRM::WSMV::SOAP
22
+ class << self
23
+ def finalize(connection_opts, transport, shell_id)
24
+ proc { Cmd.close_shell(connection_opts, transport, shell_id) }
25
+ end
26
+
27
+ def close_shell(connection_opts, transport, shell_id)
28
+ msg = WinRM::WSMV::CloseShell.new(connection_opts, shell_id: shell_id)
29
+ transport.send_request(msg.build)
30
+ end
31
+ end
32
+
33
+ protected
34
+
35
+ def send_command(command, arguments)
36
+ cmd_msg = WinRM::WSMV::Command.new(
37
+ connection_opts,
38
+ shell_id: shell_id,
39
+ command: command,
40
+ arguments: arguments
41
+ )
42
+ resp_doc = transport.send_request(cmd_msg.build)
43
+ command_id = REXML::XPath.first(resp_doc, "//*[local-name() = 'CommandId']").text
44
+ logger.debug("[WinRM] Command created for #{command} with id: #{command_id}")
45
+ command_id
46
+ end
47
+
48
+ def response_reader
49
+ @response_reader ||= WinRM::WSMV::ReceiveResponseReader.new(transport, logger)
50
+ end
51
+
52
+ def open_shell
53
+ msg = WinRM::WSMV::CreateShell.new(connection_opts, shell_opts)
54
+ resp_doc = transport.send_request(msg.build)
55
+ REXML::XPath.first(resp_doc, "//*[@Name='ShellId']").text
56
+ end
57
+
58
+ def out_streams
59
+ %w[stdout stderr]
60
+ end
61
+ end
62
+ end
63
+ end