remotus 0.5.0 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b375e9a93879a30b113991e9b653e602f30d970743925527af92a964298d7a27
4
- data.tar.gz: 97bab3f384551a63e665d173e9b90330f03d3e8b56e6e89a9c216b18e37c2a66
3
+ metadata.gz: ca295a9d011d1c64d48612e24df9e8ecb1b377ffde82010532c4bfa893d9f4ed
4
+ data.tar.gz: 808051a8602029e898047a51e4e689e28d3ce50c629a20dc08de3a1349f89b49
5
5
  SHA512:
6
- metadata.gz: 6b3ded8d0ceb3c4b36736e875ca9ed80a85d77d388d1fb26f5a9659350622230c4f17efaee017e7765ddc081cd0ba52e767af960514a54c4061f667b38f1933c
7
- data.tar.gz: 53aaf5d724c91a5639ce5f7928c6049b5912c21a523f2d1e5697191fb2511611e384fa5ce14fe92a53affaa8e707e42f5a5539ce83c93a16549bc1ac0fb3e5e5
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remotus (0.5.0)
4
+ remotus (0.6.0)
5
5
  connection_pool (~> 2.2)
6
6
  net-scp (~> 3.0)
7
7
  net-ssh (~> 6.1)
@@ -16,6 +16,9 @@ RSpec.describe "Remotus::SshConnection Integration Tests" do
16
16
  end
17
17
 
18
18
  after(:all) do
19
+ # Close all active connections
20
+ Remotus.clear
21
+
19
22
  # docker-compose cleanup
20
23
  `docker-compose -f "docker-compose.yml" down -v`
21
24
  end
@@ -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
- @pool.reject! { |_hostname, _host_pool| true }
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
- # reap all expired host pools
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
- # Calculate the number of pools reaped
86
- pools_reaped = pre_reap_num_pools - post_reap_num_pools
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 != @connection.options[:user]
466
- return true if gateway_cred.password != @connection.options[:password]
467
- return true if Array(gateway_cred.private_key) != Array(@connection.options[:keys])
468
- return true if Array(gateway_cred.private_key_data) != Array(@connection.options[:key_data])
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Remotus
4
4
  # Remotus gem version
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
@@ -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.5.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-20 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool