winrm 2.2.3 → 2.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/bin/rwinrm +90 -97
- data/lib/winrm/connection.rb +84 -86
- data/lib/winrm/connection_opts.rb +90 -91
- data/lib/winrm/exceptions.rb +14 -2
- data/lib/winrm/http/response_handler.rb +127 -96
- data/lib/winrm/http/transport.rb +462 -427
- data/lib/winrm/http/transport_factory.rb +1 -5
- data/lib/winrm/output.rb +1 -2
- data/lib/winrm/psrp/fragment.rb +0 -2
- data/lib/winrm/psrp/message.rb +128 -130
- data/lib/winrm/psrp/message_data/base.rb +0 -2
- data/lib/winrm/psrp/message_data/error_record.rb +2 -2
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
- data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
- data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
- data/lib/winrm/psrp/message_data.rb +0 -2
- data/lib/winrm/psrp/message_defragmenter.rb +2 -2
- data/lib/winrm/psrp/message_factory.rb +16 -5
- data/lib/winrm/psrp/message_fragmenter.rb +1 -3
- data/lib/winrm/psrp/powershell_output_decoder.rb +142 -144
- data/lib/winrm/psrp/receive_response_reader.rb +3 -5
- data/lib/winrm/psrp/uuid.rb +1 -2
- data/lib/winrm/shells/base.rb +7 -4
- data/lib/winrm/shells/cmd.rb +63 -65
- data/lib/winrm/shells/power_shell.rb +207 -202
- data/lib/winrm/shells/retryable.rb +44 -45
- data/lib/winrm/shells/shell_factory.rb +0 -2
- data/lib/winrm/version.rb +1 -3
- data/lib/winrm/wsmv/base.rb +0 -2
- data/lib/winrm/wsmv/cleanup_command.rb +1 -2
- data/lib/winrm/wsmv/close_shell.rb +1 -2
- data/lib/winrm/wsmv/command.rb +2 -3
- data/lib/winrm/wsmv/command_output.rb +2 -3
- data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
- data/lib/winrm/wsmv/configuration.rb +0 -2
- data/lib/winrm/wsmv/create_pipeline.rb +0 -2
- data/lib/winrm/wsmv/create_shell.rb +2 -6
- data/lib/winrm/wsmv/header.rb +213 -215
- data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
- data/lib/winrm/wsmv/keep_alive.rb +0 -2
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
- data/lib/winrm/wsmv/send_data.rb +0 -2
- data/lib/winrm/wsmv/soap.rb +0 -2
- data/lib/winrm/wsmv/wql_pull.rb +54 -56
- data/lib/winrm/wsmv/wql_query.rb +98 -99
- data/lib/winrm/wsmv/write_stdin.rb +0 -2
- data/lib/winrm.rb +3 -5
- metadata +81 -135
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -26
- data/.travis.yml +0 -11
- data/Gemfile +0 -3
- data/Rakefile +0 -34
- data/Vagrantfile +0 -6
- data/WinrmAppveyor.psm1 +0 -32
- data/appveyor.yml +0 -51
- data/changelog.md +0 -128
- data/preamble +0 -17
- data/tests/integration/auth_timeout_spec.rb +0 -18
- data/tests/integration/cmd_spec.rb +0 -131
- data/tests/integration/config-example.yml +0 -16
- data/tests/integration/issue_59_spec.rb +0 -26
- data/tests/integration/powershell_spec.rb +0 -165
- data/tests/integration/spec_helper.rb +0 -65
- data/tests/integration/transport_spec.rb +0 -99
- data/tests/integration/wql_spec.rb +0 -34
- data/tests/matchers.rb +0 -60
- data/tests/spec/configuration_spec.rb +0 -184
- data/tests/spec/connection_spec.rb +0 -39
- data/tests/spec/exception_spec.rb +0 -50
- data/tests/spec/http/transport_factory_spec.rb +0 -68
- data/tests/spec/http/transport_spec.rb +0 -44
- data/tests/spec/output_spec.rb +0 -127
- data/tests/spec/psrp/fragment_spec.rb +0 -62
- data/tests/spec/psrp/message_data/base_spec.rb +0 -13
- data/tests/spec/psrp/message_data/error_record_spec.rb +0 -41
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -25
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -32
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -40
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -25
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -16
- data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -30
- data/tests/spec/psrp/message_data_spec.rb +0 -35
- data/tests/spec/psrp/message_defragmenter_spec.rb +0 -47
- data/tests/spec/psrp/message_fragmenter_spec.rb +0 -105
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -100
- data/tests/spec/psrp/psrp_message_spec.rb +0 -70
- data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -172
- data/tests/spec/psrp/uuid_spec.rb +0 -28
- data/tests/spec/response_handler_spec.rb +0 -61
- data/tests/spec/shells/base_spec.rb +0 -225
- data/tests/spec/shells/cmd_spec.rb +0 -75
- data/tests/spec/shells/powershell_spec.rb +0 -175
- data/tests/spec/spec_helper.rb +0 -47
- data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
- data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
- data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
- data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
- data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
- data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
- data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +0 -22
- data/tests/spec/wsmv/close_shell_spec.rb +0 -17
- data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -37
- data/tests/spec/wsmv/command_output_spec.rb +0 -45
- data/tests/spec/wsmv/command_spec.rb +0 -19
- data/tests/spec/wsmv/configuration_spec.rb +0 -17
- data/tests/spec/wsmv/create_pipeline_spec.rb +0 -31
- data/tests/spec/wsmv/create_shell_spec.rb +0 -38
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -123
- data/tests/spec/wsmv/send_data_spec.rb +0 -30
- data/tests/spec/wsmv/wql_query_spec.rb +0 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +0 -22
- data/winrm.gemspec +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d70e24f7a32d8dac9c3d3a7c1675c40af3431df4e5c9a1b202cd87de21bb0a1f
|
4
|
+
data.tar.gz: 839b983ad19d3172c56cac95955efd20191a5f80880a53197366d2ef44b7dd4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require '
|
23
|
-
require '
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts '
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
options
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
options[:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
options[:
|
47
|
-
options[:
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
data/lib/winrm/connection.rb
CHANGED
@@ -1,86 +1,84 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
require_relative '
|
18
|
-
require_relative '
|
19
|
-
require_relative '
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# @
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
# @
|
55
|
-
# @
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
config
|
32
|
-
config
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
config =
|
48
|
-
config[:
|
49
|
-
config[:
|
50
|
-
config[:
|
51
|
-
config[:
|
52
|
-
config[:
|
53
|
-
config[:
|
54
|
-
config
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
raise '
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
validate_integer(:
|
79
|
-
validate_integer(:
|
80
|
-
validate_integer(:
|
81
|
-
validate_integer(:operation_timeout)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
value
|
87
|
-
raise "#{key} must be
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
data/lib/winrm/exceptions.rb
CHANGED
@@ -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
|