remotus 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b375e9a93879a30b113991e9b653e602f30d970743925527af92a964298d7a27
4
- data.tar.gz: 97bab3f384551a63e665d173e9b90330f03d3e8b56e6e89a9c216b18e37c2a66
3
+ metadata.gz: 86bb2b7b3be25ec98b48372e32f75f6ae70471bdb72635a44a1f50b20c1f5421
4
+ data.tar.gz: a2f1b203c618ffb909bc55f7edd0718bd960d53b968ea5418f1a80c7ff05b9a6
5
5
  SHA512:
6
- metadata.gz: 6b3ded8d0ceb3c4b36736e875ca9ed80a85d77d388d1fb26f5a9659350622230c4f17efaee017e7765ddc081cd0ba52e767af960514a54c4061f667b38f1933c
7
- data.tar.gz: 53aaf5d724c91a5639ce5f7928c6049b5912c21a523f2d1e5697191fb2511611e384fa5ce14fe92a53affaa8e707e42f5a5539ce83c93a16549bc1ac0fb3e5e5
6
+ metadata.gz: 28acc8709f9bcc670d175471973f309f76af530e4fb9cf1b566f58405ef4516fddc20dec63ca318c768c8f6247f6314d64838d2314fc5cf3f18a736f8fc24d38
7
+ data.tar.gz: e8d1a7cb11844225214b55fb59de52c0af958e8640db57c15eefac3e92dc3cae63a8186165108158ca93da134961a08f163fd7e2d7ec381f84524587a2881e98
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.5
2
+ TargetRubyVersion: 2.6
3
3
  NewCops: enable
4
4
 
5
5
  Style/StringLiterals:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.0.0] - 2023-04-25
2
+ * Update SSH dependencies to handle `pkeys are immutable on OpenSSL 3.0` errors on newer Ruby versions
3
+ * Remove Ruby 2.5 support
4
+
5
+ ## [0.6.0] - 2022-09-26
6
+ * Add `#close` method to all connection types
7
+ * Fix SSH gateway connection caching
8
+ * Ensure SSH gateway connections are closed gracefully before reinitializing a connection
9
+
1
10
  ## [0.5.0] - 2022-09-21
2
11
  * Ensure port argument is respected in `Remotus::SshConnection`
3
12
  * Add SSH gateway support
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remotus (0.5.0)
5
- connection_pool (~> 2.2)
6
- net-scp (~> 3.0)
7
- net-ssh (~> 6.1)
4
+ remotus (1.0.0)
5
+ connection_pool (~> 2.4)
6
+ net-scp (~> 4.0)
7
+ net-ssh (~> 7.1)
8
8
  net-ssh-gateway (~> 2.0)
9
9
  winrm (~> 2.3)
10
10
  winrm-elevated (~> 1.2)
@@ -15,9 +15,9 @@ GEM
15
15
  specs:
16
16
  ast (2.4.2)
17
17
  builder (3.2.4)
18
- connection_pool (2.3.0)
18
+ connection_pool (2.4.0)
19
19
  diff-lcs (1.5.0)
20
- erubi (1.11.0)
20
+ erubi (1.12.0)
21
21
  ffi (1.15.5)
22
22
  gssapi (1.3.1)
23
23
  ffi (>= 1.0.1)
@@ -25,59 +25,61 @@ GEM
25
25
  builder (>= 2.1.2)
26
26
  rexml (~> 3.0)
27
27
  httpclient (2.8.3)
28
- json (2.6.2)
28
+ json (2.6.3)
29
29
  little-plugger (1.1.4)
30
30
  logging (2.3.1)
31
31
  little-plugger (~> 1.1)
32
32
  multi_json (~> 1.14)
33
33
  multi_json (1.15.0)
34
- net-scp (3.0.0)
35
- net-ssh (>= 2.6.5, < 7.0.0)
36
- net-ssh (6.1.0)
34
+ net-scp (4.0.0)
35
+ net-ssh (>= 2.6.5, < 8.0.0)
36
+ net-ssh (7.1.0)
37
37
  net-ssh-gateway (2.0.0)
38
38
  net-ssh (>= 4.0.0)
39
39
  nori (2.6.0)
40
- parallel (1.22.1)
41
- parser (3.1.2.1)
40
+ parallel (1.23.0)
41
+ parser (3.2.2.1)
42
42
  ast (~> 2.4.1)
43
43
  rainbow (3.1.1)
44
44
  rake (13.0.6)
45
- regexp_parser (2.5.0)
45
+ regexp_parser (2.8.0)
46
46
  rexml (3.2.5)
47
- rspec (3.11.0)
48
- rspec-core (~> 3.11.0)
49
- rspec-expectations (~> 3.11.0)
50
- rspec-mocks (~> 3.11.0)
51
- rspec-core (3.11.0)
52
- rspec-support (~> 3.11.0)
53
- rspec-expectations (3.11.1)
47
+ rspec (3.12.0)
48
+ rspec-core (~> 3.12.0)
49
+ rspec-expectations (~> 3.12.0)
50
+ rspec-mocks (~> 3.12.0)
51
+ rspec-core (3.12.2)
52
+ rspec-support (~> 3.12.0)
53
+ rspec-expectations (3.12.3)
54
54
  diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.11.0)
56
- rspec-mocks (3.11.1)
55
+ rspec-support (~> 3.12.0)
56
+ rspec-mocks (3.12.5)
57
57
  diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.11.0)
59
- rspec-support (3.11.1)
60
- rubocop (1.36.0)
58
+ rspec-support (~> 3.12.0)
59
+ rspec-support (3.12.0)
60
+ rubocop (1.50.2)
61
61
  json (~> 2.3)
62
62
  parallel (~> 1.10)
63
- parser (>= 3.1.2.1)
63
+ parser (>= 3.2.0.0)
64
64
  rainbow (>= 2.2.2, < 4.0)
65
65
  regexp_parser (>= 1.8, < 3.0)
66
66
  rexml (>= 3.2.5, < 4.0)
67
- rubocop-ast (>= 1.20.1, < 2.0)
67
+ rubocop-ast (>= 1.28.0, < 2.0)
68
68
  ruby-progressbar (~> 1.7)
69
- unicode-display_width (>= 1.4.0, < 3.0)
70
- rubocop-ast (1.21.0)
71
- parser (>= 3.1.1.0)
69
+ unicode-display_width (>= 2.4.0, < 3.0)
70
+ rubocop-ast (1.28.0)
71
+ parser (>= 3.2.1.0)
72
+ rubocop-capybara (2.18.0)
73
+ rubocop (~> 1.41)
72
74
  rubocop-rake (0.6.0)
73
75
  rubocop (~> 1.0)
74
- rubocop-rspec (2.13.1)
76
+ rubocop-rspec (2.20.0)
75
77
  rubocop (~> 1.33)
76
- ruby-progressbar (1.11.0)
78
+ rubocop-capybara (~> 2.17)
79
+ ruby-progressbar (1.13.0)
77
80
  rubyntlm (0.6.3)
78
81
  rubyzip (2.3.2)
79
- unicode-display_width (2.3.0)
80
- webrick (1.7.0)
82
+ unicode-display_width (2.4.2)
81
83
  winrm (2.3.6)
82
84
  builder (>= 2.1.2)
83
85
  erubi (~> 1.8)
@@ -96,8 +98,7 @@ GEM
96
98
  logging (>= 1.6.1, < 3.0)
97
99
  rubyzip (~> 2.0)
98
100
  winrm (~> 2.0)
99
- yard (0.9.28)
100
- webrick (~> 1.7.0)
101
+ yard (0.9.34)
101
102
 
102
103
  PLATFORMS
103
104
  ruby
@@ -16,12 +16,15 @@ 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
22
25
 
23
- let(:test_script) { ::File.join(__dir__, "ssh_integration_script.sh") }
24
- let(:test_script_dest) { ::File.join("/home/testuser", ::File.basename(test_script)) }
26
+ let(:test_script) { File.join(__dir__, "ssh_integration_script.sh") }
27
+ let(:test_script_dest) { File.join("/home/testuser", File.basename(test_script)) }
25
28
 
26
29
  context "when a gateway and inaccessible target host exist" do
27
30
  let(:gateway_hostname) { `docker ps | grep remotus_gateway`.split.first }
@@ -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 = "1.0.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
  #
data/remotus.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Ruby gem for connecting to remote systems seamlessly via WinRM or SSH."
13
13
  spec.homepage = "https://github.com/wheatevo/remotus"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/wheatevo/remotus"
@@ -29,9 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Dependencies
32
- spec.add_dependency "connection_pool", "~> 2.2"
33
- spec.add_dependency "net-scp", "~> 3.0"
34
- spec.add_dependency "net-ssh", "~> 6.1"
32
+ spec.add_dependency "connection_pool", "~> 2.4"
33
+ spec.add_dependency "net-scp", "~> 4.0"
34
+ spec.add_dependency "net-ssh", "~> 7.1"
35
35
  spec.add_dependency "net-ssh-gateway", "~> 2.0"
36
36
  spec.add_dependency "winrm", "~> 2.3"
37
37
  spec.add_dependency "winrm-elevated", "~> 1.2"
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: 1.0.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: 2023-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
26
+ version: '2.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-scp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: net-ssh
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '6.1'
47
+ version: '7.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '6.1'
54
+ version: '7.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: net-ssh-gateway
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -248,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
248
  requirements:
249
249
  - - ">="
250
250
  - !ruby/object:Gem::Version
251
- version: 2.5.0
251
+ version: 2.6.0
252
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
254
  - - ">="