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,55 @@
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 'base64'
18
+
19
+ module WinRM
20
+ module WSMV
21
+ # Handles decoding a raw output response
22
+ class CommandOutputDecoder
23
+ # Decode the raw SOAP output into decoded and human consumable text,
24
+ # Decodes and replaces invalid unicode characters.
25
+ # @param raw_output [String] The raw encoded output
26
+ # @return [String] The decoded output
27
+ def decode(raw_output)
28
+ decoded_text = decode_raw_output(raw_output)
29
+ decoded_text = handle_invalid_encoding(decoded_text)
30
+ decoded_text = remove_bom(decoded_text)
31
+ decoded_text
32
+ end
33
+
34
+ private
35
+
36
+ def decode_raw_output(raw_output)
37
+ Base64.decode64(raw_output).force_encoding('utf-8')
38
+ end
39
+
40
+ def handle_invalid_encoding(decoded_text)
41
+ return decoded_text if decoded_text.valid_encoding?
42
+ if decoded_text.respond_to?(:scrub)
43
+ decoded_text.scrub
44
+ else
45
+ decoded_text.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8')
46
+ end
47
+ end
48
+
49
+ def remove_bom(decoded_text)
50
+ # remove BOM which 2008R2 applies
51
+ decoded_text.sub("\xEF\xBB\xBF", '')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,46 @@
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 Configuration < Base
23
+ def initialize(session_opts)
24
+ @session_opts = session_opts
25
+ end
26
+
27
+ protected
28
+
29
+ def create_header(header)
30
+ header << Gyoku.xml(configuration_headers)
31
+ end
32
+
33
+ def create_body(_body)
34
+ # no body
35
+ end
36
+
37
+ private
38
+
39
+ def configuration_headers
40
+ merge_headers(shared_headers(@session_opts),
41
+ resource_uri_shell('http://schemas.microsoft.com/wbem/wsman/1/config'),
42
+ action_get)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
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
+ require_relative '../psrp/message_factory'
19
+
20
+ module WinRM
21
+ module WSMV
22
+ # WSMV message to execute a command via psrp
23
+ class CreatePipeline < Base
24
+ attr_accessor :shell_id, :command_id, :fragment
25
+
26
+ def initialize(session_opts, shell_id, command_id, fragment = nil)
27
+ @command_id = command_id
28
+ @session_opts = session_opts
29
+ @shell_id = shell_id
30
+ @fragment = fragment
31
+ end
32
+
33
+ protected
34
+
35
+ def create_header(header)
36
+ header << Gyoku.xml(command_headers)
37
+ end
38
+
39
+ def create_body(body)
40
+ body.tag!("#{NS_WIN_SHELL}:CommandLine", 'CommandId' => command_id) do |cl|
41
+ cl << Gyoku.xml(command_body)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def command_body
48
+ {
49
+ "#{NS_WIN_SHELL}:Command" => 'Invoke-Expression',
50
+ "#{NS_WIN_SHELL}:Arguments" => arguments
51
+ }
52
+ end
53
+
54
+ def command_headers
55
+ merge_headers(shared_headers(@session_opts),
56
+ resource_uri_shell(RESOURCE_URI_POWERSHELL),
57
+ action_command,
58
+ selector_shell_id(shell_id))
59
+ end
60
+
61
+ def arguments
62
+ encode_bytes(fragment.bytes) if fragment
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,119 @@
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
+ require_relative 'iso8601_duration'
19
+
20
+ module WinRM
21
+ module WSMV
22
+ # WSMV message to create a remote shell
23
+ class CreateShell < Base
24
+ # utf8 as default codepage
25
+ # https://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx
26
+ UTF8_CODE_PAGE = 65001
27
+
28
+ attr_accessor :i_stream, :o_stream, :codepage, :noprofile
29
+ attr_accessor :working_directory, :idle_timeout, :env_vars
30
+
31
+ def initialize(session_opts, shell_opts = {})
32
+ @session_opts = session_opts
33
+ @shell_uri = opt_or_default(shell_opts, :shell_uri, RESOURCE_URI_CMD)
34
+ @i_stream = opt_or_default(shell_opts, :i_stream, 'stdin')
35
+ @o_stream = opt_or_default(shell_opts, :o_stream, 'stdout stderr')
36
+ @codepage = opt_or_default(shell_opts, :codepage, UTF8_CODE_PAGE)
37
+ @noprofile = opt_or_default(shell_opts, :noprofile, 'FALSE')
38
+ @working_directory = opt_or_default(shell_opts, :working_directory)
39
+ @idle_timeout = opt_or_default(shell_opts, :idle_timeout)
40
+ @env_vars = opt_or_default(shell_opts, :env_vars)
41
+ end
42
+
43
+ protected
44
+
45
+ def create_header(header)
46
+ header << Gyoku.xml(shell_headers)
47
+ end
48
+
49
+ def create_body(body)
50
+ body.tag!("#{NS_WIN_SHELL}:Shell") { |s| s << Gyoku.xml(shell_body) }
51
+ end
52
+
53
+ private
54
+
55
+ def opt_or_default(shell_opts, key, default_value = nil)
56
+ shell_opts.key?(key) ? shell_opts[key] : default_value
57
+ end
58
+
59
+ def shell_body
60
+ body = {
61
+ "#{NS_WIN_SHELL}:InputStreams" => @i_stream,
62
+ "#{NS_WIN_SHELL}:OutputStreams" => @o_stream
63
+ }
64
+ body["#{NS_WIN_SHELL}:WorkingDirectory"] = @working_directory if @working_directory
65
+ if @idle_timeout
66
+ body["#{NS_WIN_SHELL}:IdleTimeOut"] = format_idle_timeout(@idle_timeout)
67
+ end
68
+ body["#{NS_WIN_SHELL}:Environment"] = environment_vars_body if @env_vars
69
+ body
70
+ end
71
+
72
+ # backwards compat - idle_timeout as an Iso8601Duration string
73
+ def format_idle_timeout(timeout)
74
+ timeout.is_a?(String) ? timeout : Iso8601Duration.sec_to_dur(timeout)
75
+ end
76
+
77
+ def environment_vars_body
78
+ {
79
+ "#{NS_WIN_SHELL}:Variable" => @env_vars.values,
80
+ :attributes! => {
81
+ "#{NS_WIN_SHELL}:Variable" => {
82
+ 'Name' => @env_vars.keys
83
+ }
84
+ }
85
+ }
86
+ end
87
+
88
+ def shell_headers
89
+ merge_headers(shared_headers(@session_opts),
90
+ resource_uri_shell(@shell_uri),
91
+ action_create,
92
+ header_opts)
93
+ end
94
+
95
+ def action_create
96
+ {
97
+ "#{NS_ADDRESSING}:Action" => 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Create',
98
+ :attributes! => {
99
+ "#{NS_ADDRESSING}:Action" => {
100
+ 'mustUnderstand' => true
101
+ }
102
+ }
103
+ }
104
+ end
105
+
106
+ def header_opts
107
+ {
108
+ "#{NS_WSMAN_DMTF}:OptionSet" => {
109
+ "#{NS_WSMAN_DMTF}:Option" => [@noprofile, @codepage], :attributes! => {
110
+ "#{NS_WSMAN_DMTF}:Option" => {
111
+ 'Name' => %w(WINRS_NOPROFILE WINRS_CODEPAGE)
112
+ }
113
+ }
114
+ }
115
+ }
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,203 @@
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
+ # rubocop:disable Metrics/MethodLength
18
+
19
+ require_relative 'soap'
20
+ require_relative 'iso8601_duration'
21
+
22
+ module WinRM
23
+ module WSMV
24
+ # SOAP header utility mixin
25
+ module Header
26
+ # WSMan URI of the regular Windows cmd shell
27
+ RESOURCE_URI_CMD = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd'.freeze
28
+
29
+ # WSMan URI for PowerShell
30
+ RESOURCE_URI_POWERSHELL = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'.freeze
31
+
32
+ # Merge the various header hashes and make sure we carry all of the attributes
33
+ # through instead of overwriting them.
34
+ def merge_headers(*headers)
35
+ hdr = {}
36
+ headers.each do |h|
37
+ hdr.merge!(h) do |k, v1, v2|
38
+ v1.merge!(v2) if k == :attributes!
39
+ end
40
+ end
41
+ hdr
42
+ end
43
+
44
+ def shared_headers(session_opts)
45
+ {
46
+ "#{SOAP::NS_ADDRESSING}:To" => session_opts[:endpoint],
47
+ "#{SOAP::NS_ADDRESSING}:ReplyTo" => {
48
+ "#{SOAP::NS_ADDRESSING}:Address" =>
49
+ 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous',
50
+ :attributes! => {
51
+ "#{SOAP::NS_ADDRESSING}:Address" => {
52
+ 'mustUnderstand' => true
53
+ }
54
+ }
55
+ },
56
+ "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => session_opts[:max_envelope_size],
57
+ "#{SOAP::NS_ADDRESSING}:MessageID" => "uuid:#{SecureRandom.uuid.to_s.upcase}",
58
+ "#{SOAP::NS_WSMAN_MSFT}:SessionId" => "uuid:#{session_opts[:session_id]}",
59
+ "#{SOAP::NS_WSMAN_DMTF}:Locale/" => '',
60
+ "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => '',
61
+ "#{SOAP::NS_WSMAN_DMTF}:OperationTimeout" =>
62
+ Iso8601Duration.sec_to_dur(session_opts[:operation_timeout]),
63
+ :attributes! => {
64
+ "#{SOAP::NS_WSMAN_DMTF}:MaxEnvelopeSize" => { 'mustUnderstand' => true },
65
+ "#{SOAP::NS_WSMAN_DMTF}:Locale/" => {
66
+ 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
67
+ },
68
+ "#{SOAP::NS_WSMAN_MSFT}:DataLocale/" => {
69
+ 'xml:lang' => session_opts[:locale], 'mustUnderstand' => false
70
+ },
71
+ "#{SOAP::NS_WSMAN_MSFT}:SessionId" => { 'mustUnderstand' => false }
72
+ }
73
+ }
74
+ end
75
+
76
+ # Helper methods for SOAP Headers
77
+
78
+ def resource_uri_shell(shell_uri)
79
+ {
80
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => shell_uri, :attributes! => {
81
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
82
+ 'mustUnderstand' => true
83
+ }
84
+ }
85
+ }
86
+ end
87
+
88
+ def resource_uri_cmd
89
+ resource_uri_shell(RESOURCE_URI_CMD)
90
+ end
91
+
92
+ def resource_uri_wmi(namespace = 'root/cimv2/*')
93
+ {
94
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" =>
95
+ "http://schemas.microsoft.com/wbem/wsman/1/wmi/#{namespace}",
96
+ :attributes! => {
97
+ "#{SOAP::NS_WSMAN_DMTF}:ResourceURI" => {
98
+ 'mustUnderstand' => true
99
+ }
100
+ }
101
+ }
102
+ end
103
+
104
+ def action_get
105
+ {
106
+ "#{SOAP::NS_ADDRESSING}:Action" =>
107
+ 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get',
108
+ :attributes! => {
109
+ "#{SOAP::NS_ADDRESSING}:Action" => {
110
+ 'mustUnderstand' => true
111
+ }
112
+ }
113
+ }
114
+ end
115
+
116
+ def action_delete
117
+ {
118
+ "#{SOAP::NS_ADDRESSING}:Action" =>
119
+ 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete',
120
+ :attributes! => {
121
+ "#{SOAP::NS_ADDRESSING}:Action" => {
122
+ 'mustUnderstand' => true
123
+ }
124
+ }
125
+ }
126
+ end
127
+
128
+ def action_command
129
+ {
130
+ "#{SOAP::NS_ADDRESSING}:Action" =>
131
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command',
132
+ :attributes! => {
133
+ "#{SOAP::NS_ADDRESSING}:Action" => {
134
+ 'mustUnderstand' => true
135
+ }
136
+ }
137
+ }
138
+ end
139
+
140
+ def action_receive
141
+ {
142
+ "#{SOAP::NS_ADDRESSING}:Action" =>
143
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive',
144
+ :attributes! => {
145
+ "#{SOAP::NS_ADDRESSING}:Action" => {
146
+ 'mustUnderstand' => true
147
+ }
148
+ }
149
+ }
150
+ end
151
+
152
+ def action_send
153
+ {
154
+ "#{SOAP::NS_ADDRESSING}:Action" =>
155
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
156
+ :attributes! => {
157
+ "#{SOAP::NS_ADDRESSING}:Action" => {
158
+ 'mustUnderstand' => true
159
+ }
160
+ }
161
+ }
162
+ end
163
+
164
+ def action_signal
165
+ {
166
+ "#{SOAP::NS_ADDRESSING}:Action" =>
167
+ 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal',
168
+ :attributes! => {
169
+ "#{SOAP::NS_ADDRESSING}:Action" => {
170
+ 'mustUnderstand' => true
171
+ }
172
+ }
173
+ }
174
+ end
175
+
176
+ def action_enumerate
177
+ {
178
+ "#{SOAP::NS_ADDRESSING}:Action" =>
179
+ 'http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate',
180
+ :attributes! => {
181
+ "#{SOAP::NS_ADDRESSING}:Action" => {
182
+ 'mustUnderstand' => true
183
+ }
184
+ }
185
+ }
186
+ end
187
+
188
+ def selector_shell_id(shell_id)
189
+ {
190
+ "#{SOAP::NS_WSMAN_DMTF}:SelectorSet" => {
191
+ "#{SOAP::NS_WSMAN_DMTF}:Selector" => shell_id, :attributes! => {
192
+ "#{SOAP::NS_WSMAN_DMTF}:Selector" => {
193
+ 'Name' => 'ShellId'
194
+ }
195
+ }
196
+ }
197
+ }
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ # rubocop:enable Metrics/MethodLength