winrm 1.8.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -11
  3. data/.rubocop.yml +26 -22
  4. data/.travis.yml +11 -12
  5. data/Gemfile +3 -9
  6. data/LICENSE +202 -202
  7. data/README.md +232 -215
  8. data/Rakefile +34 -36
  9. data/Vagrantfile +6 -9
  10. data/WinrmAppveyor.psm1 +31 -31
  11. data/appveyor.yml +51 -51
  12. data/bin/rwinrm +97 -97
  13. data/changelog.md +86 -86
  14. data/lib/winrm.rb +39 -42
  15. data/lib/winrm/connection.rb +82 -0
  16. data/lib/winrm/connection_opts.rb +87 -0
  17. data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
  18. data/lib/winrm/http/response_handler.rb +96 -82
  19. data/lib/winrm/http/transport.rb +424 -435
  20. data/lib/winrm/http/transport_factory.rb +68 -0
  21. data/lib/winrm/output.rb +59 -43
  22. data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
  23. data/lib/winrm/psrp/fragment.rb +70 -0
  24. data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
  25. data/lib/winrm/psrp/message.rb +130 -0
  26. data/lib/winrm/psrp/message_data.rb +41 -0
  27. data/lib/winrm/psrp/message_data/base.rb +49 -0
  28. data/lib/winrm/psrp/message_data/error_record.rb +68 -0
  29. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
  30. data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
  31. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
  32. data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
  33. data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
  34. data/lib/winrm/psrp/message_defragmenter.rb +62 -0
  35. data/lib/winrm/psrp/message_factory.rb +75 -0
  36. data/lib/winrm/psrp/message_fragmenter.rb +60 -0
  37. data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
  38. data/lib/winrm/psrp/receive_response_reader.rb +93 -0
  39. data/lib/winrm/psrp/session_capability.xml.erb +7 -0
  40. data/lib/winrm/psrp/uuid.rb +40 -0
  41. data/lib/winrm/shells/base.rb +175 -0
  42. data/lib/winrm/shells/cmd.rb +65 -0
  43. data/lib/winrm/shells/power_shell.rb +201 -0
  44. data/lib/winrm/shells/retryable.rb +45 -0
  45. data/lib/winrm/shells/shell_factory.rb +50 -0
  46. data/lib/winrm/version.rb +7 -7
  47. data/lib/winrm/wsmv/base.rb +59 -0
  48. data/lib/winrm/wsmv/cleanup_command.rb +61 -0
  49. data/lib/winrm/wsmv/close_shell.rb +50 -0
  50. data/lib/winrm/wsmv/command.rb +101 -0
  51. data/lib/winrm/wsmv/command_output.rb +76 -0
  52. data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
  53. data/lib/winrm/wsmv/configuration.rb +46 -0
  54. data/lib/winrm/wsmv/create_pipeline.rb +66 -0
  55. data/lib/winrm/wsmv/create_shell.rb +119 -0
  56. data/lib/winrm/wsmv/header.rb +203 -0
  57. data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
  58. data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
  59. data/lib/winrm/wsmv/keep_alive.rb +68 -0
  60. data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
  61. data/lib/winrm/wsmv/send_data.rb +68 -0
  62. data/lib/winrm/wsmv/soap.rb +51 -0
  63. data/lib/winrm/wsmv/wql_query.rb +79 -0
  64. data/lib/winrm/wsmv/write_stdin.rb +88 -0
  65. data/preamble +17 -17
  66. data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
  67. data/{spec → tests/integration}/cmd_spec.rb +104 -102
  68. data/{spec → tests/integration}/config-example.yml +16 -19
  69. data/{spec → tests/integration}/issue_59_spec.rb +26 -23
  70. data/tests/integration/powershell_spec.rb +154 -0
  71. data/{spec → tests/integration}/spec_helper.rb +65 -73
  72. data/{spec → tests/integration}/transport_spec.rb +99 -139
  73. data/{spec → tests/integration}/wql_spec.rb +16 -14
  74. data/{spec → tests}/matchers.rb +60 -74
  75. data/tests/spec/configuration_spec.rb +93 -0
  76. data/tests/spec/connection_spec.rb +39 -0
  77. data/{spec → tests/spec}/exception_spec.rb +50 -50
  78. data/tests/spec/http/transport_factory_spec.rb +68 -0
  79. data/tests/spec/http/transport_spec.rb +44 -0
  80. data/{spec → tests/spec}/output_spec.rb +127 -110
  81. data/tests/spec/psrp/fragment_spec.rb +62 -0
  82. data/tests/spec/psrp/message_data/base_spec.rb +13 -0
  83. data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
  84. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
  85. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
  89. data/tests/spec/psrp/message_data_spec.rb +35 -0
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
  93. data/tests/spec/psrp/psrp_message_spec.rb +70 -0
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
  95. data/tests/spec/psrp/uuid_spec.rb +28 -0
  96. data/{spec → tests/spec}/response_handler_spec.rb +61 -61
  97. data/tests/spec/shells/base_spec.rb +202 -0
  98. data/tests/spec/shells/cmd_spec.rb +75 -0
  99. data/tests/spec/shells/powershell_spec.rb +175 -0
  100. data/tests/spec/spec_helper.rb +47 -0
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
  102. data/{spec → tests/spec}/stubs/responses/get_command_output_response.xml.erb +13 -13
  103. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -0
  104. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
  105. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
  106. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
  107. data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
  108. data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
  109. data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
  110. data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
  111. data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
  112. data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
  113. data/tests/spec/wsmv/close_shell_spec.rb +17 -0
  114. data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
  115. data/tests/spec/wsmv/command_output_spec.rb +45 -0
  116. data/tests/spec/wsmv/command_spec.rb +19 -0
  117. data/tests/spec/wsmv/configuration_spec.rb +17 -0
  118. data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
  119. data/tests/spec/wsmv/create_shell_spec.rb +38 -0
  120. data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
  121. data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
  122. data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
  123. data/tests/spec/wsmv/send_data_spec.rb +30 -0
  124. data/tests/spec/wsmv/wql_query_spec.rb +13 -0
  125. data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
  126. data/winrm.gemspec +42 -40
  127. metadata +140 -38
  128. data/.rspec +0 -3
  129. data/lib/winrm/command_executor.rb +0 -243
  130. data/lib/winrm/command_output_decoder.rb +0 -53
  131. data/lib/winrm/helpers/iso8601_duration.rb +0 -58
  132. data/lib/winrm/helpers/powershell_script.rb +0 -42
  133. data/lib/winrm/soap_provider.rb +0 -39
  134. data/lib/winrm/winrm_service.rb +0 -550
  135. data/spec/command_executor_spec.rb +0 -475
  136. data/spec/issue_184_spec.rb +0 -67
  137. data/spec/powershell_spec.rb +0 -97
  138. data/spec/winrm_options_spec.rb +0 -76
  139. data/spec/winrm_primitives_spec.rb +0 -51
@@ -0,0 +1,95 @@
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_relative 'base'
18
+
19
+ module WinRM
20
+ module WSMV
21
+ # WSMV message to create a remote shell
22
+ class InitRunspacePool < Base
23
+ attr_accessor :shell_id
24
+
25
+ def initialize(session_opts, shell_id, payload)
26
+ @session_opts = session_opts
27
+ @shell_id = shell_id
28
+ @payload = payload
29
+ end
30
+
31
+ protected
32
+
33
+ def create_header(header)
34
+ header << Gyoku.xml(shell_headers)
35
+ end
36
+
37
+ def create_body(body)
38
+ body.tag!("#{NS_WIN_SHELL}:Shell", 'ShellId' => shell_id) { |s| s << Gyoku.xml(shell_body) }
39
+ end
40
+
41
+ private
42
+
43
+ def shell_body
44
+ body = {
45
+ "#{NS_WIN_SHELL}:InputStreams" => 'stdin pr',
46
+ "#{NS_WIN_SHELL}:OutputStreams" => 'stdout'
47
+ }
48
+ body['creationXml'] = encode_bytes(@payload)
49
+ body[:attributes!] = {
50
+ 'creationXml' => {
51
+ 'xmlns' => 'http://schemas.microsoft.com/powershell'
52
+ }
53
+ }
54
+ body
55
+ end
56
+
57
+ def shell_headers
58
+ merge_headers(shared_headers(@session_opts),
59
+ resource_uri_shell(RESOURCE_URI_POWERSHELL),
60
+ action_create,
61
+ header_opts)
62
+ end
63
+
64
+ def action_create
65
+ {
66
+ "#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create',
67
+ :attributes! => {
68
+ "#{NS_ADDRESSING}:Action" => {
69
+ 'mustUnderstand' => true
70
+ }
71
+ }
72
+ }
73
+ end
74
+
75
+ def header_opts
76
+ {
77
+ "#{NS_WSMAN_DMTF}:OptionSet" => {
78
+ "#{NS_WSMAN_DMTF}:Option" => 2.3,
79
+ :attributes! => {
80
+ "#{NS_WSMAN_DMTF}:Option" => {
81
+ 'Name' => 'protocolversion',
82
+ 'MustComply' => 'true'
83
+ }
84
+ }
85
+ },
86
+ :attributes! => {
87
+ "#{NS_WSMAN_DMTF}:OptionSet" => {
88
+ 'env:mustUnderstand' => 'true'
89
+ }
90
+ }
91
+ }
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright 2010 Dan Wanek <dan.wanek@gmail.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
+ # rubocop:disable Metrics/MethodLength
18
+
19
+ # Format an ISO8601 Duration
20
+ module WinRM
21
+ module WSMV
22
+ # Converts seconds to ISO8601 duration format
23
+ module Iso8601Duration
24
+ # Convert the number of seconds to an ISO8601 duration format
25
+ # @see http://tools.ietf.org/html/rfc2445#section-4.3.6
26
+ # @param [Fixnum] seconds The amount of seconds for this duration
27
+ def self.sec_to_dur(seconds)
28
+ seconds = seconds.to_i
29
+ iso_str = 'P'
30
+ if seconds > 604_800 # more than a week
31
+ weeks = seconds / 604_800
32
+ seconds -= (604_800 * weeks)
33
+ iso_str << "#{weeks}W"
34
+ end
35
+ if seconds > 86_400 # more than a day
36
+ days = seconds / 86_400
37
+ seconds -= (86_400 * days)
38
+ iso_str << "#{days}D"
39
+ end
40
+ if seconds > 0
41
+ iso_str << 'T'
42
+ if seconds > 3600 # more than an hour
43
+ hours = seconds / 3600
44
+ seconds -= (3600 * hours)
45
+ iso_str << "#{hours}H"
46
+ end
47
+ if seconds > 60 # more than a minute
48
+ minutes = seconds / 60
49
+ seconds -= (60 * minutes)
50
+ iso_str << "#{minutes}M"
51
+ end
52
+ iso_str << "#{seconds}S"
53
+ end
54
+
55
+ iso_str
56
+ end
57
+ end
58
+ end
59
+ end
60
+ # rubocop:enable Metrics/MethodLength
@@ -0,0 +1,68 @@
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_relative 'base'
18
+
19
+ module WinRM
20
+ module WSMV
21
+ # WSMV keep alive message
22
+ class KeepAlive < Base
23
+ attr_accessor :shell_id
24
+
25
+ def initialize(session_opts, shell_id)
26
+ @session_opts = session_opts
27
+ @shell_id = shell_id
28
+ end
29
+
30
+ protected
31
+
32
+ def create_header(header)
33
+ header << Gyoku.xml(keep_alive_headers)
34
+ end
35
+
36
+ def create_body(body)
37
+ body.tag!("#{NS_WIN_SHELL}:Receive") { |s| s << Gyoku.xml(keep_alive_body) }
38
+ end
39
+
40
+ private
41
+
42
+ def keep_alive_body
43
+ { "#{NS_WIN_SHELL}:DesiredStream" => 'stdout' }
44
+ end
45
+
46
+ def keep_alive_headers
47
+ merge_headers(shared_headers(@session_opts),
48
+ resource_uri_shell(RESOURCE_URI_POWERSHELL),
49
+ action_receive,
50
+ header_opts,
51
+ selector_shell_id(shell_id))
52
+ end
53
+
54
+ def header_opts
55
+ {
56
+ "#{NS_WSMAN_DMTF}:OptionSet" => {
57
+ "#{NS_WSMAN_DMTF}:Option" => 'TRUE',
58
+ :attributes! => {
59
+ "#{NS_WSMAN_DMTF}:Option" => {
60
+ 'Name' => 'WSMAN_CMDSHELL_OPTION_KEEPALIVE'
61
+ }
62
+ }
63
+ }
64
+ }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,128 @@
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 'soap'
18
+ require_relative 'header'
19
+ require_relative 'command_output_decoder'
20
+ require_relative '../output'
21
+
22
+ module WinRM
23
+ module WSMV
24
+ # Class for reading wsmv Receive_Response messages
25
+ class ReceiveResponseReader
26
+ include WinRM::WSMV::SOAP
27
+ include WinRM::WSMV::Header
28
+
29
+ # Creates a new ReceiveResponseReader
30
+ # @param transport [HttpTransport] The WinRM SOAP transport
31
+ # @param logger [Logger] The logger to log diagnostic messages to
32
+ def initialize(transport, logger)
33
+ @transport = transport
34
+ @logger = logger
35
+ @output_decoder = CommandOutputDecoder.new
36
+ end
37
+
38
+ attr_reader :logger
39
+
40
+ # Reads streams and returns decoded output
41
+ # @param wsmv_message [WinRM::WSMV::Base] A wsmv message to send to endpoint
42
+ # @yieldparam [string] standard out response text
43
+ # @yieldparam [string] standard error response text
44
+ # @yieldreturn [WinRM::Output] The command output
45
+ def read_output(wsmv_message)
46
+ with_output do |output|
47
+ read_response(wsmv_message, true) do |stream, doc|
48
+ handled_out = handle_stream(stream, output, doc)
49
+ yield handled_out if handled_out && block_given?
50
+ end
51
+ end
52
+ end
53
+
54
+ # Reads streams sent in one or more receive response messages
55
+ # @param wsmv_message [WinRM::WSMV::Base] A wsmv message to send to endpoint
56
+ # @param wait_for_done_state whether to poll for a CommandState of Done
57
+ # @yieldparam [Hash] Hash representation of stream with type and text
58
+ # @yieldparam [REXML::Document] Complete SOAP envelope returned to wsmv_message
59
+ def read_response(wsmv_message, wait_for_done_state = false)
60
+ resp_doc = nil
61
+ until command_done?(resp_doc, wait_for_done_state)
62
+ logger.debug('[WinRM] Waiting for output...')
63
+ resp_doc = send_get_output_message(wsmv_message.build)
64
+ logger.debug('[WinRM] Processing output')
65
+ read_streams(resp_doc) do |stream|
66
+ yield stream, resp_doc
67
+ end
68
+ end
69
+ end
70
+
71
+ protected
72
+
73
+ def with_output
74
+ output = WinRM::Output.new
75
+ yield output
76
+ output.exitcode ||= 0
77
+ output
78
+ end
79
+
80
+ private
81
+
82
+ def handle_stream(stream, output, resp_doc)
83
+ decoded_text = @output_decoder.decode(stream[:text])
84
+ return unless decoded_text
85
+
86
+ out = { stream[:type] => decoded_text }
87
+ output << out
88
+ output.exitcode ||= exit_code(resp_doc)
89
+ [out[:stdout], out[:stderr]]
90
+ end
91
+
92
+ def send_get_output_message(message)
93
+ @transport.send_request(message)
94
+ rescue WinRMWSManFault => e
95
+ # If no output is available before the wsman:OperationTimeout expires,
96
+ # the server MUST return a WSManFault with the Code attribute equal to
97
+ # 2150858793. When the client receives this fault, it SHOULD issue
98
+ # another Receive request.
99
+ # http://msdn.microsoft.com/en-us/library/cc251676.aspx
100
+ raise unless e.fault_code == '2150858793'
101
+
102
+ logger.debug('[WinRM] retrying receive request after timeout')
103
+ retry
104
+ end
105
+
106
+ def exit_code(resp_doc)
107
+ REXML::XPath.first(resp_doc, "//#{NS_WIN_SHELL}:ExitCode").text.to_i
108
+ end
109
+
110
+ def command_done?(resp_doc, wait_for_done_state)
111
+ return false unless resp_doc
112
+ return true unless wait_for_done_state
113
+
114
+ REXML::XPath.match(
115
+ resp_doc,
116
+ "//*[@State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/" \
117
+ "CommandState/Done']").any?
118
+ end
119
+
120
+ def read_streams(response_document)
121
+ REXML::XPath.match(response_document, "//#{NS_WIN_SHELL}:Stream").each do |stream|
122
+ next if stream.text.nil? || stream.text.empty?
123
+ yield type: stream.attributes['Name'].to_sym, text: stream.text
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,68 @@
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_relative 'base'
18
+
19
+ module WinRM
20
+ module WSMV
21
+ # Subclasses base, sends additional data to WinRM
22
+ class SendData < Base
23
+ attr_accessor :shell_id, :command_id, :fragment
24
+
25
+ def initialize(session_opts, shell_id, command_id, fragment)
26
+ @session_opts = session_opts
27
+ @shell_id = shell_id
28
+ @command_id = command_id
29
+ @fragment = fragment
30
+ end
31
+
32
+ protected
33
+
34
+ def create_header(header)
35
+ header << Gyoku.xml(command_headers)
36
+ end
37
+
38
+ def create_body(body)
39
+ body.tag!("#{NS_WIN_SHELL}:Send") do |cl|
40
+ cl << Gyoku.xml(command_body)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def command_body
47
+ {
48
+ "#{NS_WIN_SHELL}:Stream" => encode_bytes(fragment.bytes),
49
+ :attributes! => {
50
+ "#{NS_WIN_SHELL}:Stream" => {
51
+ 'Name' => 'stdin',
52
+ 'CommandId' => command_id
53
+ }
54
+ }
55
+ }
56
+ end
57
+
58
+ def command_headers
59
+ merge_headers(
60
+ shared_headers(@session_opts),
61
+ resource_uri_shell(RESOURCE_URI_POWERSHELL),
62
+ action_send,
63
+ selector_shell_id(shell_id)
64
+ )
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
4
+ # Copyright 2016 Shawn Neal <sneal@sneal.net>
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
+ module WSMV
20
+ # WSMV SOAP namespaces mixin
21
+ module SOAP
22
+ NS_SOAP_ENV = 's'.freeze # http://www.w3.org/2003/05/soap-envelope
23
+ NS_ADDRESSING = 'a'.freeze # http://schemas.xmlsoap.org/ws/2004/08/addressing
24
+ NS_CIMBINDING = 'b'.freeze # http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd
25
+ NS_ENUM = 'n'.freeze # http://schemas.xmlsoap.org/ws/2004/09/enumeration
26
+ NS_TRANSFER = 'x'.freeze # http://schemas.xmlsoap.org/ws/2004/09/transfer
27
+ NS_WSMAN_DMTF = 'w'.freeze # http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
28
+ NS_WSMAN_MSFT = 'p'.freeze # http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd
29
+ NS_SCHEMA_INST = 'xsi'.freeze # http://www.w3.org/2001/XMLSchema-instance
30
+ NS_WIN_SHELL = 'rsp'.freeze # http://schemas.microsoft.com/wbem/wsman/1/windows/shell
31
+ NS_WSMAN_FAULT = 'f'.freeze # http://schemas.microsoft.com/wbem/wsman/1/wsmanfault
32
+ NS_WSMAN_CONF = 'cfg'.freeze # http://schemas.microsoft.com/wbem/wsman/1/config
33
+
34
+ def namespaces
35
+ @namespaces ||= {
36
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
37
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
38
+ 'xmlns:env' => 'http://www.w3.org/2003/05/soap-envelope',
39
+ "xmlns:#{NS_ADDRESSING}" => 'http://schemas.xmlsoap.org/ws/2004/08/addressing',
40
+ "xmlns:#{NS_CIMBINDING}" => 'http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd',
41
+ "xmlns:#{NS_ENUM}" => 'http://schemas.xmlsoap.org/ws/2004/09/enumeration',
42
+ "xmlns:#{NS_TRANSFER}" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer',
43
+ "xmlns:#{NS_WSMAN_DMTF}" => 'http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd',
44
+ "xmlns:#{NS_WSMAN_MSFT}" => 'http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd',
45
+ "xmlns:#{NS_WIN_SHELL}" => 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell',
46
+ "xmlns:#{NS_WSMAN_CONF}" => 'http://schemas.microsoft.com/wbem/wsman/1/config'
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end