remotus 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/docker/ssh_integration_spec.rb +3 -0
- data/lib/remotus/host_pool.rb +9 -0
- data/lib/remotus/pool.rb +16 -7
- data/lib/remotus/ssh_connection.rb +20 -5
- data/lib/remotus/version.rb +1 -1
- data/lib/remotus/winrm_connection.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca295a9d011d1c64d48612e24df9e8ecb1b377ffde82010532c4bfa893d9f4ed
|
4
|
+
data.tar.gz: 808051a8602029e898047a51e4e689e28d3ce50c629a20dc08de3a1349f89b49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e5268b157fc283afb2bc830838da9bba8b04f6055396123422d8bed43b97797f02cee6974f01b6d6db4658b00c99e77cc13474cc60ba8fdd9fa72dfa87e4f18
|
7
|
+
data.tar.gz: 5681064618614505ce74388725a03f8ab2f3e442d5feaa8ee1be4539ed9e9170f9f8e374fe6f9ce8f2ebeaeafc72624814f51f0280799b2820b1334aa955da62
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [0.6.0] - 2022-09-26
|
2
|
+
* Add `#close` method to all connection types
|
3
|
+
* Fix SSH gateway connection caching
|
4
|
+
* Ensure SSH gateway connections are closed gracefully before reinitializing a connection
|
5
|
+
|
1
6
|
## [0.5.0] - 2022-09-21
|
2
7
|
* Ensure port argument is respected in `Remotus::SshConnection`
|
3
8
|
* Add SSH gateway support
|
data/Gemfile.lock
CHANGED
data/lib/remotus/host_pool.rb
CHANGED
@@ -87,6 +87,15 @@ module Remotus
|
|
87
87
|
@expiration_time = Time.now
|
88
88
|
end
|
89
89
|
|
90
|
+
#
|
91
|
+
# Closes all open connections in the pool.
|
92
|
+
# @see Remotus::SshConnection#close
|
93
|
+
# @see Remotus::WinrmConnection#close
|
94
|
+
#
|
95
|
+
def close
|
96
|
+
@pool.reload(&:close)
|
97
|
+
end
|
98
|
+
|
90
99
|
#
|
91
100
|
# Provides an SSH or WinRM connection to a given block of code
|
92
101
|
#
|
data/lib/remotus/pool.rb
CHANGED
@@ -58,7 +58,11 @@ module Remotus
|
|
58
58
|
return 0 unless @pool
|
59
59
|
|
60
60
|
num_pools = count
|
61
|
-
|
61
|
+
|
62
|
+
# Force connection close
|
63
|
+
@pool.each { |_hostname, host_pool| host_pool.close }
|
64
|
+
@pool = {}
|
65
|
+
|
62
66
|
return num_pools
|
63
67
|
end
|
64
68
|
end
|
@@ -77,13 +81,18 @@ module Remotus
|
|
77
81
|
# If the pool is not yet initialized, no processes can be reaped
|
78
82
|
return 0 unless @pool
|
79
83
|
|
80
|
-
|
81
|
-
pre_reap_num_pools = count
|
82
|
-
@pool.reject! { |_hostname, host_pool| host_pool.expired? }
|
83
|
-
post_reap_num_pools = count
|
84
|
+
pools_reaped = 0
|
84
85
|
|
85
|
-
#
|
86
|
-
|
86
|
+
# Force connection close for expired host pools
|
87
|
+
@pool.each do |hostname, host_pool|
|
88
|
+
next unless host_pool.expired?
|
89
|
+
|
90
|
+
# Close and delete the host pool if it is expired
|
91
|
+
Remotus.logger.debug { "Reaping #{hostname} host pool" }
|
92
|
+
host_pool.close
|
93
|
+
@pool.delete(hostname)
|
94
|
+
pools_reaped += 1
|
95
|
+
end
|
87
96
|
|
88
97
|
Remotus.logger.debug { "Reaped #{pools_reaped} expired host pools" }
|
89
98
|
|
@@ -119,6 +119,9 @@ module Remotus
|
|
119
119
|
def connection
|
120
120
|
return @connection unless restart_connection?
|
121
121
|
|
122
|
+
# Close any active connections
|
123
|
+
close
|
124
|
+
|
122
125
|
target_cred = Remotus::Auth.credential(self)
|
123
126
|
|
124
127
|
Remotus.logger.debug { "Initializing SSH connection to #{target_cred.user}@#{@host}:#{@port}" }
|
@@ -141,12 +144,24 @@ module Remotus
|
|
141
144
|
Remotus.logger.debug { "Initializing SSH gateway connection to #{gateway_cred.user}@#{@gateway.host}:#{gateway_options[:port]}" }
|
142
145
|
|
143
146
|
@gateway.connection = Net::SSH::Gateway.new(@gateway.host, gateway_cred.user, **gateway_options)
|
144
|
-
@gateway.connection.ssh(@host, target_cred.user, **target_options)
|
147
|
+
@connection = @gateway.connection.ssh(@host, target_cred.user, **target_options)
|
145
148
|
else
|
146
149
|
@connection = Net::SSH.start(@host, target_cred.user, **target_options)
|
147
150
|
end
|
148
151
|
end
|
149
152
|
|
153
|
+
#
|
154
|
+
# Closes the current SSH connection if it is active
|
155
|
+
#
|
156
|
+
def close
|
157
|
+
@connection&.close
|
158
|
+
|
159
|
+
@gateway&.connection&.shutdown! if via_gateway?
|
160
|
+
|
161
|
+
@gateway = nil
|
162
|
+
@connection = nil
|
163
|
+
end
|
164
|
+
|
150
165
|
#
|
151
166
|
# Whether the remote host's SSH port is available
|
152
167
|
#
|
@@ -462,10 +477,10 @@ module Remotus
|
|
462
477
|
|
463
478
|
gateway_cred = Remotus::Auth.credential(@gateway)
|
464
479
|
|
465
|
-
return true if gateway_cred.user !=
|
466
|
-
return true if gateway_cred.password !=
|
467
|
-
return true if Array(gateway_cred.private_key) != Array(
|
468
|
-
return true if Array(gateway_cred.private_key_data) != Array(
|
480
|
+
return true if gateway_cred.user != gateway_session.options[:user]
|
481
|
+
return true if gateway_cred.password != gateway_session.options[:password]
|
482
|
+
return true if Array(gateway_cred.private_key) != Array(gateway_session.options[:keys])
|
483
|
+
return true if Array(gateway_cred.private_key_data) != Array(gateway_session.options[:key_data])
|
469
484
|
end
|
470
485
|
|
471
486
|
false
|
data/lib/remotus/version.rb
CHANGED
@@ -64,6 +64,9 @@ module Remotus
|
|
64
64
|
def base_connection(reload: false)
|
65
65
|
return @base_connection if !reload && !restart_base_connection?
|
66
66
|
|
67
|
+
# Close any active connections
|
68
|
+
close
|
69
|
+
|
67
70
|
Remotus.logger.debug { "Initializing WinRM connection to #{Remotus::Auth.credential(self).user}@#{@host}:#{@port}" }
|
68
71
|
@base_connection = WinRM::Connection.new(
|
69
72
|
endpoint: "http://#{@host}:#{@port}/wsman",
|
@@ -88,6 +91,15 @@ module Remotus
|
|
88
91
|
@connection = base_connection(reload: true).shell(@shell)
|
89
92
|
end
|
90
93
|
|
94
|
+
#
|
95
|
+
# Closes the current WinRM connection if it is active
|
96
|
+
#
|
97
|
+
def close
|
98
|
+
@connection&.close
|
99
|
+
@connection = nil
|
100
|
+
@base_connection = nil
|
101
|
+
end
|
102
|
+
|
91
103
|
#
|
92
104
|
# Whether the remote host's WinRM port is available
|
93
105
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Newell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|