deploy-agent 1.2.1 → 1.4.1

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: 4ef182af99f1a1dafc375cd5e1b744a626e4f023dc5c04b8d88140a0243568a9
4
- data.tar.gz: eb44700f80e225332e68ffe055ce462bf0b0e234fe435d2ca73c226921371dd4
3
+ metadata.gz: 944241c474fe9e8a7f3dc96805f25672f7ef67f637c829ecee0e70df4bf97689
4
+ data.tar.gz: d869a3e2b4100889bc02950c989db2298215e3bc66628b2c09325f498172ee33
5
5
  SHA512:
6
- metadata.gz: cb906670bef6ab1ef210df73c47c6ca34d0f08f521e30229a0cb88e4603aa1dfbb9871541dd596279e7b0d83b1c85b938ef3b41b16b8011456d5703c33717db8
7
- data.tar.gz: 870c8c2838a691f2ebee07bb964a2348730f80b2f4a49adc60de09628300945ff6368c3a769987619034aa37340b31babc8a3fad8bfc21fc23988190b84ff738
6
+ metadata.gz: 5c50f09a5aa5ec13156cbe4ef6ca7642447e9888d2703ec411b5b43a7c130154db359ce76696ae8c63b1dbd44a91e2be5239d54397cda4c769a2387c6a633ed9
7
+ data.tar.gz: fedac9d8f5bd77f35cf27baff2b0354a9bfbf2418ef385fe2fd206adb7fb7992c9f45c01137b5ccf062d780b8ae915de91ae6bd4b1b2a567e86a3e7528afdb5d
data/bin/deploy-agent CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- $:.unshift(File.expand_path('../../lib', __FILE__))
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
3
5
  require 'deploy_agent'
4
6
 
5
7
  DeployAgent::CLI.new.dispatch(ARGV)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/deploy_agent/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'deploy-agent'
7
+ s.version = DeployAgent::VERSION
8
+ s.required_ruby_version = '>= 2.7'
9
+ s.summary = 'The DeployHQ Agent'
10
+ s.description = 'This gem allows you to configure a secure proxy through which DeployHQ can forward connections'
11
+ s.authors = ['Charlie Smurthwaite']
12
+ s.email = ['support@deployhq.com']
13
+ s.files = Dir.glob('{lib,bin}/**/*')
14
+ s.files << 'ca.crt'
15
+ s.files << 'deploy-agent.gemspec'
16
+ s.homepage = 'https://www.deployhq.com/'
17
+ s.bindir = 'bin'
18
+ s.executables << 'deploy-agent'
19
+
20
+ s.add_dependency 'nio4r', '~> 2.7'
21
+ s.add_dependency 'rb-readline', '~> 0.5'
22
+ s.add_dependency 'timers', '~> 4.3'
23
+ end
@@ -1,11 +1,13 @@
1
- gem 'nio4r', '2.1.0'
2
- gem 'timers', '4.1.2'
3
1
  require 'nio'
4
2
  require 'timers'
5
3
  require 'logger'
6
4
 
7
5
  module DeployAgent
8
6
  class Agent
7
+ def initialize(options = {})
8
+ @retries = 0
9
+ @options = options
10
+ end
9
11
 
10
12
  def run
11
13
  nio_selector = NIO::Selector.new
@@ -21,22 +23,40 @@ module DeployAgent
21
23
  monitor.value.tx_data if monitor.writeable?
22
24
  end
23
25
  timers.fire
26
+
27
+ @retries = 0
28
+ end
29
+ rescue OpenSSL::SSL::SSLError => e
30
+ @retries += 1
31
+
32
+ if @retries == 4
33
+ raise e
34
+ else
35
+ retry
24
36
  end
25
37
  rescue ServerConnection::ServerDisconnected
26
38
  retry
39
+ rescue Interrupt, SignalException => e
40
+ logger.info("Stopping")
41
+ rescue Exception => e
42
+ logger.debug("#{e.class}: #{e.message}")
43
+ raise e
27
44
  end
28
45
 
29
46
  def logger
30
47
  @logger ||= begin
31
48
  if $background
32
49
  logger = Logger.new(LOG_PATH, 5, 10240)
33
- logger.level = Logger::INFO
34
- logger
35
50
  else
36
- Logger.new(STDOUT)
51
+ logger = Logger.new(STDOUT)
37
52
  end
53
+ logger.level = @options[:verbose] ? Logger::DEBUG : Logger::INFO
54
+ logger
38
55
  end
39
56
  end
40
57
 
58
+ private
59
+
60
+ attr_reader :options
41
61
  end
42
62
  end
@@ -1,10 +1,20 @@
1
1
  require 'ipaddr'
2
+ require 'optparse'
2
3
 
3
4
  module DeployAgent
4
5
  class CLI
5
6
 
6
7
  def dispatch(arguments)
7
8
  methods = self.public_methods(false).delete_if { |n| n == :dispatch }.sort
9
+
10
+ @options = {}
11
+
12
+ OptionParser.new do |opts|
13
+ opts.on('-v', '--verbose', 'Log extra debug information') do
14
+ @options[:verbose] = true
15
+ end
16
+ end.parse!(arguments)
17
+
8
18
  if arguments[0] && methods.include?(arguments[0].to_sym)
9
19
  public_send(arguments[0])
10
20
  else
@@ -62,7 +72,7 @@ module DeployAgent
62
72
 
63
73
  def run
64
74
  ensure_configured
65
- Agent.new.run
75
+ Agent.new(@options).run
66
76
  end
67
77
 
68
78
  def accesslist
@@ -79,6 +89,10 @@ module DeployAgent
79
89
  puts "To edit the list of allowed servers, please modify " + ACCESS_PATH
80
90
  end
81
91
 
92
+ def version
93
+ puts DeployAgent::VERSION
94
+ end
95
+
82
96
  private
83
97
 
84
98
  def ensure_configured
@@ -109,7 +123,7 @@ module DeployAgent
109
123
 
110
124
  def write_pid
111
125
  File.open(PID_PATH, 'w') { |f| f.write Process.pid.to_s }
112
- at_exit { File.delete(PID_PATH) if File.exists?(PID_PATH) }
126
+ at_exit { File.delete(PID_PATH) if File.exist?(PID_PATH) }
113
127
  end
114
128
 
115
129
  end
@@ -79,7 +79,7 @@ module DeployAgent
79
79
  # Nothing more to send, wait for inbound data only
80
80
  @nio_monitor.interests = :r
81
81
  end
82
- rescue Errno::ECONNRESET
82
+ rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ENETRESET
83
83
  # The backend has closed the connection. Inform the Deploy server.
84
84
  @server_connection.send_connection_close(@id)
85
85
  # Ensure everything is tidied up
@@ -91,7 +91,7 @@ module DeployAgent
91
91
  data = @tcp_socket.readpartial(10240)
92
92
  @agent.logger.debug "[#{@id}] #{data.bytesize} bytes received from destination"
93
93
  @server_connection.send_data(@id, data)
94
- rescue EOFError, Errno::ECONNRESET
94
+ rescue EOFError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ENETRESET
95
95
  @agent.logger.info "[#{@id}] Destination closed connection"
96
96
  # The backend has closed the connection. Inform the Deploy server.
97
97
  @server_connection.send_connection_close(@id)
@@ -54,10 +54,17 @@ module DeployAgent
54
54
  # Receive and process packets from the control server
55
55
  def rx_data
56
56
  # Ensure all received data is read
57
- @rx_buffer << @socket.readpartial(10240)
58
- while(@socket.pending > 0)
59
- @rx_buffer << @socket.readpartial(10240)
57
+ loop do
58
+ begin
59
+ data = @socket.read_nonblock(10240)
60
+ raise EOFError if data.nil?
61
+
62
+ @rx_buffer << data
63
+ rescue IO::WaitReadable, IO::WaitWritable
64
+ break # nothing more to read
65
+ end
60
66
  end
67
+
61
68
  # Wait until we have a complete packet of data
62
69
  while @rx_buffer.bytesize >=2 && @rx_buffer.bytesize >= @rx_buffer[0,2].unpack('n')[0]
63
70
  length = @rx_buffer.slice!(0,2).unpack('n')[0]
@@ -106,7 +113,7 @@ module DeployAgent
106
113
  close
107
114
  end
108
115
  end
109
- rescue EOFError, Errno::ECONNRESET
116
+ rescue EOFError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ENETRESET
110
117
  close
111
118
  end
112
119
 
@@ -144,7 +151,9 @@ module DeployAgent
144
151
 
145
152
  # Called by event loop to send all waiting packets to the Deploy server
146
153
  def tx_data
154
+ @agent.logger.debug('Writing to socket')
147
155
  bytes_sent = @socket.write_nonblock(@tx_buffer[0,1024])
156
+ @agent.logger.debug('Writing to socket completed')
148
157
  # Send as much data as possible
149
158
  if bytes_sent >= @tx_buffer.bytesize
150
159
  @tx_buffer = String.new.force_encoding('BINARY')
@@ -154,7 +163,7 @@ module DeployAgent
154
163
  # the remaining data in the send buffer
155
164
  @tx_buffer.slice!(0, bytes_sent)
156
165
  end
157
- rescue EOFError, Errno::ECONNRESET
166
+ rescue EOFError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ENETRESET
158
167
  close
159
168
  end
160
169
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeployAgent
4
+ VERSION = '1.4.1'
5
+ end
data/lib/deploy_agent.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'deploy_agent/version'
1
2
  require 'deploy_agent/configuration_generator'
2
3
  require 'deploy_agent/server_connection'
3
4
  require 'deploy_agent/destination_connection'
metadata CHANGED
@@ -1,72 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
- - aTech Media
8
- autorequire:
7
+ - Charlie Smurthwaite
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
10
+ date: 2026-02-19 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: nio4r
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 2.1.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 2.1.0
27
- - !ruby/object:Gem::Dependency
28
- name: timers
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
16
+ - - "~>"
32
17
  - !ruby/object:Gem::Version
33
- version: 4.1.2
18
+ version: '2.7'
34
19
  type: :runtime
35
20
  prerelease: false
36
21
  version_requirements: !ruby/object:Gem::Requirement
37
22
  requirements:
38
- - - '='
23
+ - - "~>"
39
24
  - !ruby/object:Gem::Version
40
- version: 4.1.2
25
+ version: '2.7'
41
26
  - !ruby/object:Gem::Dependency
42
27
  name: rb-readline
43
28
  requirement: !ruby/object:Gem::Requirement
44
29
  requirements:
45
- - - '='
30
+ - - "~>"
46
31
  - !ruby/object:Gem::Version
47
- version: 0.5.5
32
+ version: '0.5'
48
33
  type: :runtime
49
34
  prerelease: false
50
35
  version_requirements: !ruby/object:Gem::Requirement
51
36
  requirements:
52
- - - '='
37
+ - - "~>"
53
38
  - !ruby/object:Gem::Version
54
- version: 0.5.5
39
+ version: '0.5'
55
40
  - !ruby/object:Gem::Dependency
56
- name: bundler
41
+ name: timers
57
42
  requirement: !ruby/object:Gem::Requirement
58
43
  requirements:
59
44
  - - "~>"
60
45
  - !ruby/object:Gem::Version
61
- version: '1.16'
62
- type: :development
46
+ version: '4.3'
47
+ type: :runtime
63
48
  prerelease: false
64
49
  version_requirements: !ruby/object:Gem::Requirement
65
50
  requirements:
66
51
  - - "~>"
67
52
  - !ruby/object:Gem::Version
68
- version: '1.16'
69
- description: This gem allows you to configure a secure proxy through which Deploy
53
+ version: '4.3'
54
+ description: This gem allows you to configure a secure proxy through which DeployHQ
70
55
  can forward connections
71
56
  email:
72
57
  - support@deployhq.com
@@ -77,16 +62,17 @@ extra_rdoc_files: []
77
62
  files:
78
63
  - bin/deploy-agent
79
64
  - ca.crt
65
+ - deploy-agent.gemspec
80
66
  - lib/deploy_agent.rb
81
67
  - lib/deploy_agent/agent.rb
82
68
  - lib/deploy_agent/cli.rb
83
69
  - lib/deploy_agent/configuration_generator.rb
84
70
  - lib/deploy_agent/destination_connection.rb
85
71
  - lib/deploy_agent/server_connection.rb
72
+ - lib/deploy_agent/version.rb
86
73
  homepage: https://www.deployhq.com/
87
74
  licenses: []
88
75
  metadata: {}
89
- post_install_message:
90
76
  rdoc_options: []
91
77
  require_paths:
92
78
  - lib
@@ -94,16 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
80
  requirements:
95
81
  - - ">="
96
82
  - !ruby/object:Gem::Version
97
- version: '0'
83
+ version: '2.7'
98
84
  required_rubygems_version: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - ">="
101
87
  - !ruby/object:Gem::Version
102
88
  version: '0'
103
89
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.7.8
106
- signing_key:
90
+ rubygems_version: 3.6.2
107
91
  specification_version: 4
108
- summary: The Deploy agent
92
+ summary: The DeployHQ Agent
109
93
  test_files: []