winrm 2.2.3 → 2.3.6

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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 46a0806843f652f3d0b8d8858eb87cf0365d8e4d
4
- data.tar.gz: 76f409feeda643970222972be8c571e2905a6fb9
2
+ SHA256:
3
+ metadata.gz: d70e24f7a32d8dac9c3d3a7c1675c40af3431df4e5c9a1b202cd87de21bb0a1f
4
+ data.tar.gz: 839b983ad19d3172c56cac95955efd20191a5f80880a53197366d2ef44b7dd4a
5
5
  SHA512:
6
- metadata.gz: cd17e956aa071c63ab65c0a9db69bada2a256b735ee4c9e2b63b32a16920357749bc814b32b15dd3ad61e777d77144fa73eea1e851c23347e0486ded69ffd47b
7
- data.tar.gz: 119346b0543a18a8715f90b2c318df0bf98cbdeeae16d8afd7ffd70f73c6690b620e8c94d541e4a0798dc490c395f5e4feee7d12c8e83fddf64970560781602d
6
+ metadata.gz: 20d3f20e5ddf0dc50519145c6bb13b40c1e5da21770510a50fd529bb2afb4b87ea3f55cde0a6653ccffdd1368a041c98992957800a9b45a016e8f6fd113eac61
7
+ data.tar.gz: 01ad60c5c78598ebf17434a02b0b4848eaeb605d2f5871edd11dc16be8c627d1bb8bf4390a282f80ebaaced51564858b5d2a82c552c608115054b78e4ad0e4dc
data/README.md CHANGED
@@ -72,7 +72,7 @@ The `:negotiate` transport uses the [rubyntlm gem](https://github.com/WinRb/ruby
72
72
  ### `:ssl`
73
73
  ```ruby
74
74
  WinRM::Connection.new(
75
- endpoint: 'https://myhost:59856/wsman',
75
+ endpoint: 'https://myhost:5986/wsman',
76
76
  transport: :ssl,
77
77
  user: 'administrator',
78
78
  password: 'Pass@word1'
data/bin/rwinrm CHANGED
@@ -1,97 +1,90 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # Copyright 2014 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
- # rubocop:disable all
19
-
20
- $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
21
-
22
- require 'readline'
23
- require 'io/console'
24
- require 'winrm'
25
-
26
- def help_msg
27
- puts 'Usage: rwinrm user@host'
28
- puts ''
29
- end
30
-
31
- def parse_options
32
- options = {}
33
- fail 'Missing required options' unless ARGV.length == 1
34
-
35
- m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
36
- fail "#{ARGV[0]} is an invalid host" unless m
37
- options[:user] = m[:user]
38
- options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
39
-
40
- # Get the password
41
- print 'Password: '
42
- options[:pass] = STDIN.noecho(&:gets).chomp
43
- puts
44
-
45
- # Set some defaults required by WinRM WS
46
- options[:auth_type] = :plaintext
47
- options[:basic_auth_only] = true
48
-
49
- options
50
- rescue StandardError => e
51
- puts e.message
52
- help_msg
53
- exit 1
54
- end
55
-
56
- def repl(options)
57
- client = WinRM::WinRMWebService.new(
58
- options[:endpoint],
59
- options[:auth_type].to_sym,
60
- options)
61
-
62
- client.set_timeout(3600)
63
- shell_id = client.open_shell
64
- command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
65
-
66
- read_thread = Thread.new do
67
- client.get_command_output(shell_id, command_id) do |stdout, stderr|
68
- STDOUT.write stdout
69
- STDERR.write stderr
70
- end
71
- end
72
- read_thread.abort_on_exception = true
73
-
74
- while (buf = Readline.readline('', true))
75
- if buf =~ /^exit/
76
- read_thread.exit
77
- client.cleanup_command(shell_id, command_id)
78
- client.close_shell(shell_id)
79
- exit 0
80
- else
81
- client.write_stdin(shell_id, command_id, "#{buf}\r\n")
82
- end
83
- end
84
- rescue Interrupt
85
- puts 'exiting'
86
- # ctrl-c
87
- rescue WinRM::WinRMAuthorizationError
88
- puts 'Authentication failed, bad user name or password'
89
- exit 1
90
- rescue StandardError => e
91
- puts e.message
92
- exit 1
93
- end
94
-
95
- repl(parse_options)
96
-
97
- # rubocop:enable all
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2014 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 all
18
+
19
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
20
+
21
+ require 'readline'
22
+ require 'io/console'
23
+ require 'winrm'
24
+
25
+ def help_msg
26
+ puts 'Usage: rwinrm user@host'
27
+ puts ''
28
+ end
29
+
30
+ def parse_options
31
+ options = {}
32
+ fail 'Missing required options' unless ARGV.length == 1
33
+
34
+ m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
35
+ fail "#{ARGV[0]} is an invalid host" unless m
36
+ options[:user] = m[:user]
37
+ options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
38
+
39
+ # Get the password
40
+ print 'Password: '
41
+ options[:password] = STDIN.noecho(&:gets).chomp
42
+ puts
43
+
44
+ # Set some defaults required by WinRM WS
45
+ options[:transport] = :plaintext
46
+ options[:basic_auth_only] = true
47
+ options[:operation_timeout] = 3600
48
+
49
+ options
50
+ rescue StandardError => e
51
+ puts e.message
52
+ help_msg
53
+ exit 1
54
+ end
55
+
56
+ def repl(options)
57
+ shell = nil
58
+
59
+ client = WinRM::Connection.new(options)
60
+ shell = client.shell(:powershell)
61
+ prompt = "PS #{ARGV[0]}> "
62
+
63
+ while (buf = Readline.readline(prompt, true))
64
+ if buf =~ /^exit/
65
+ shell.close
66
+ shell = nil
67
+ exit 0
68
+ else
69
+ shell.run(buf) do |stdout, stderr|
70
+ $stdout.write stdout
71
+ $stderr.write stderr
72
+ end
73
+ end
74
+ end
75
+ rescue Interrupt
76
+ puts 'exiting'
77
+ # ctrl-c
78
+ rescue WinRM::WinRMAuthorizationError
79
+ puts 'Authentication failed, bad user name or password'
80
+ exit 1
81
+ rescue StandardError => e
82
+ puts e.message
83
+ exit 1
84
+ ensure
85
+ shell.close unless shell.nil?
86
+ end
87
+
88
+ repl(parse_options)
89
+
90
+ # rubocop:enable all
@@ -1,86 +1,84 @@
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 'connection_opts'
18
- require_relative 'http/transport_factory'
19
- require_relative 'shells/shell_factory'
20
- require_relative 'wsmv/wql_query'
21
- require_relative 'wsmv/wql_pull'
22
-
23
- module WinRM
24
- # WinRM connection used to establish a session with the remote WinRM service.
25
- class Connection
26
- # Creates a new WinRM connection
27
- # See the ConnectionOpts class for connection options.
28
- def initialize(connection_opts)
29
- configure_connection_opts(connection_opts)
30
- configure_logger
31
- end
32
-
33
- attr_accessor :logger
34
-
35
- # Creates a new shell on the remote Windows server associated with
36
- # this connection.
37
- # @param shell_type [Symbol] The shell type :cmd or :powershell
38
- # @param shell_opts [Hash] Options targeted for the created shell
39
- # @return [Shell] PowerShell or Cmd shell instance.
40
- def shell(shell_type, shell_opts = {})
41
- shell = shell_factory.create_shell(shell_type, shell_opts)
42
- if block_given?
43
- begin
44
- yield shell
45
- ensure
46
- shell.close
47
- end
48
- else
49
- shell
50
- end
51
- end
52
-
53
- # Executes a WQL query against the WinRM connection
54
- # @param wql [String] The wql query
55
- # @param namespace [String] namespace for query - default is root/cimv2/*
56
- # @return [Hash] Hash representation of wql query response (Hash is empty if a block is given)
57
- # @yeild [type, item] Yields the time name and item for every item
58
- def run_wql(wql, namespace = 'root/cimv2/*', &block)
59
- query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace)
60
- query.process_response(transport.send_request(query.build), &block)
61
- end
62
-
63
- private
64
-
65
- def configure_connection_opts(connection_opts)
66
- @connection_opts = ConnectionOpts.create_with_defaults(connection_opts)
67
- end
68
-
69
- def configure_logger
70
- @logger = Logging.logger[self]
71
- logger.level = :warn
72
- logger.add_appenders(Logging.appenders.stdout)
73
- end
74
-
75
- def shell_factory
76
- @shell_factory ||= WinRM::Shells::ShellFactory.new(@connection_opts, transport, logger)
77
- end
78
-
79
- def transport
80
- @transport ||= begin
81
- transport_factory = WinRM::HTTP::TransportFactory.new
82
- transport_factory.create_transport(@connection_opts)
83
- end
84
- end
85
- end
86
- 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 'connection_opts'
16
+ require_relative 'http/transport_factory'
17
+ require_relative 'shells/shell_factory'
18
+ require_relative 'wsmv/wql_query'
19
+ require_relative 'wsmv/wql_pull'
20
+
21
+ module WinRM
22
+ # WinRM connection used to establish a session with the remote WinRM service.
23
+ class Connection
24
+ # Creates a new WinRM connection
25
+ # See the ConnectionOpts class for connection options.
26
+ def initialize(connection_opts)
27
+ configure_connection_opts(connection_opts)
28
+ configure_logger
29
+ end
30
+
31
+ attr_accessor :logger
32
+
33
+ # Creates a new shell on the remote Windows server associated with
34
+ # this connection.
35
+ # @param shell_type [Symbol] The shell type :cmd or :powershell
36
+ # @param shell_opts [Hash] Options targeted for the created shell
37
+ # @return [Shell] PowerShell or Cmd shell instance.
38
+ def shell(shell_type, shell_opts = {})
39
+ shell = shell_factory.create_shell(shell_type, shell_opts)
40
+ if block_given?
41
+ begin
42
+ yield shell
43
+ ensure
44
+ shell.close
45
+ end
46
+ else
47
+ shell
48
+ end
49
+ end
50
+
51
+ # Executes a WQL query against the WinRM connection
52
+ # @param wql [String] The wql query
53
+ # @param namespace [String] namespace for query - default is root/cimv2/*
54
+ # @return [Hash] Hash representation of wql query response (Hash is empty if a block is given)
55
+ # @yeild [type, item] Yields the time name and item for every item
56
+ def run_wql(wql, namespace = 'root/cimv2/*', &block)
57
+ query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace)
58
+ query.process_response(transport.send_request(query.build), &block)
59
+ end
60
+
61
+ private
62
+
63
+ def configure_connection_opts(connection_opts)
64
+ @connection_opts = ConnectionOpts.create_with_defaults(connection_opts)
65
+ end
66
+
67
+ def configure_logger
68
+ @logger = Logging.logger[self]
69
+ logger.level = :warn
70
+ logger.add_appenders(Logging.appenders.stdout)
71
+ end
72
+
73
+ def shell_factory
74
+ @shell_factory ||= WinRM::Shells::ShellFactory.new(@connection_opts, transport, logger)
75
+ end
76
+
77
+ def transport
78
+ @transport ||= begin
79
+ transport_factory = WinRM::HTTP::TransportFactory.new
80
+ transport_factory.create_transport(@connection_opts)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,91 +1,90 @@
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 'securerandom'
18
-
19
- module WinRM
20
- # WinRM connection options, provides defaults and validation.
21
- class ConnectionOpts < Hash
22
- DEFAULT_OPERATION_TIMEOUT = 60
23
- DEFAULT_RECEIVE_TIMEOUT = DEFAULT_OPERATION_TIMEOUT + 10
24
- DEFAULT_MAX_ENV_SIZE = 153600
25
- DEFAULT_LOCALE = 'en-US'.freeze
26
- DEFAULT_RETRY_DELAY = 10
27
- DEFAULT_RETRY_LIMIT = 3
28
-
29
- class << self
30
- def create_with_defaults(overrides)
31
- config = default.merge(overrides)
32
- config = ensure_receive_timeout_is_greater_than_operation_timeout(config)
33
- config.validate
34
- config
35
- end
36
-
37
- private
38
-
39
- def ensure_receive_timeout_is_greater_than_operation_timeout(config)
40
- if config[:receive_timeout] < config[:operation_timeout]
41
- config[:receive_timeout] = config[:operation_timeout] + 10
42
- end
43
- config
44
- end
45
-
46
- def default
47
- config = ConnectionOpts.new
48
- config[:session_id] = SecureRandom.uuid.to_s.upcase
49
- config[:transport] = :negotiate
50
- config[:locale] = DEFAULT_LOCALE
51
- config[:max_envelope_size] = DEFAULT_MAX_ENV_SIZE
52
- config[:operation_timeout] = DEFAULT_OPERATION_TIMEOUT
53
- config[:receive_timeout] = DEFAULT_RECEIVE_TIMEOUT
54
- config[:retry_delay] = DEFAULT_RETRY_DELAY
55
- config[:retry_limit] = DEFAULT_RETRY_LIMIT
56
- config
57
- end
58
- end
59
-
60
- def validate
61
- validate_required_fields
62
- validate_data_types
63
- end
64
-
65
- private
66
-
67
- def validate_required_fields
68
- raise 'endpoint is a required option' unless self[:endpoint]
69
- if self[:client_cert]
70
- raise 'path to client key is required' unless self[:client_key]
71
- else
72
- raise 'user is a required option' unless self[:user]
73
- raise 'password is a required option' unless self[:password]
74
- end
75
- end
76
-
77
- def validate_data_types
78
- validate_integer(:retry_limit)
79
- validate_integer(:retry_delay)
80
- validate_integer(:max_envelope_size)
81
- validate_integer(:operation_timeout)
82
- validate_integer(:receive_timeout, self[:operation_timeout])
83
- end
84
-
85
- def validate_integer(key, min = 0)
86
- value = self[key]
87
- raise "#{key} must be a Integer" unless value && value.is_a?(Integer)
88
- raise "#{key} must be greater than #{min}" unless value > min
89
- end
90
- end
91
- 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 'securerandom'
16
+
17
+ module WinRM
18
+ # WinRM connection options, provides defaults and validation.
19
+ class ConnectionOpts < Hash
20
+ DEFAULT_OPERATION_TIMEOUT = 60
21
+ DEFAULT_RECEIVE_TIMEOUT = DEFAULT_OPERATION_TIMEOUT + 10
22
+ DEFAULT_MAX_ENV_SIZE = 153600
23
+ DEFAULT_LOCALE = 'en-US'.freeze
24
+ DEFAULT_RETRY_DELAY = 10
25
+ DEFAULT_RETRY_LIMIT = 3
26
+
27
+ class << self
28
+ def create_with_defaults(overrides)
29
+ config = default.merge(overrides)
30
+ config = ensure_receive_timeout_is_greater_than_operation_timeout(config)
31
+ config.validate
32
+ config
33
+ end
34
+
35
+ private
36
+
37
+ def ensure_receive_timeout_is_greater_than_operation_timeout(config)
38
+ if config[:receive_timeout] < config[:operation_timeout]
39
+ config[:receive_timeout] = config[:operation_timeout] + 10
40
+ end
41
+ config
42
+ end
43
+
44
+ def default
45
+ config = ConnectionOpts.new
46
+ config[:session_id] = SecureRandom.uuid.to_s.upcase
47
+ config[:transport] = :negotiate
48
+ config[:locale] = DEFAULT_LOCALE
49
+ config[:max_envelope_size] = DEFAULT_MAX_ENV_SIZE
50
+ config[:operation_timeout] = DEFAULT_OPERATION_TIMEOUT
51
+ config[:receive_timeout] = DEFAULT_RECEIVE_TIMEOUT
52
+ config[:retry_delay] = DEFAULT_RETRY_DELAY
53
+ config[:retry_limit] = DEFAULT_RETRY_LIMIT
54
+ config
55
+ end
56
+ end
57
+
58
+ def validate
59
+ validate_required_fields
60
+ validate_data_types
61
+ end
62
+
63
+ private
64
+
65
+ def validate_required_fields
66
+ raise 'endpoint is a required option' unless self[:endpoint]
67
+
68
+ if self[:client_cert]
69
+ raise 'path to client key is required' unless self[:client_key]
70
+ else
71
+ raise 'user is a required option' unless self[:user]
72
+ raise 'password is a required option' unless self[:password]
73
+ end
74
+ end
75
+
76
+ def validate_data_types
77
+ validate_integer(:retry_limit)
78
+ validate_integer(:retry_delay)
79
+ validate_integer(:max_envelope_size)
80
+ validate_integer(:operation_timeout)
81
+ validate_integer(:receive_timeout, self[:operation_timeout])
82
+ end
83
+
84
+ def validate_integer(key, min = 0)
85
+ value = self[key]
86
+ raise "#{key} must be a Integer" unless value && value.is_a?(Integer)
87
+ raise "#{key} must be greater than #{min}" unless value > min
88
+ end
89
+ end
90
+ end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
- #
3
1
  # Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
4
2
  #
5
3
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,6 +50,20 @@ module WinRM
52
50
  end
53
51
  end
54
52
 
53
+ # A Fault returned in the SOAP response. The XML node contains Code, SubCode and Reason
54
+ class WinRMSoapFault < WinRMError
55
+ attr_reader :code
56
+ attr_reader :subcode
57
+ attr_reader :reason
58
+
59
+ def initialize(code, subcode, reason)
60
+ @code = code
61
+ @subcode = subcode
62
+ @reason = reason
63
+ super("[SOAP ERROR CODE: #{code} (#{subcode})]: #{reason}")
64
+ end
65
+ end
66
+
55
67
  # A Fault returned in the SOAP response. The XML node is a MSFT_WmiError
56
68
  class WinRMWMIError < WinRMError
57
69
  attr_reader :error_code