smart_proxy_remote_execution_ssh 0.10.1 → 0.10.3

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: debc9989aade4d23bda1b90e9fa8e85c99948f5b9ca37d6cecca7573bb994e5e
4
- data.tar.gz: 38a2731c7f28643daaa33ddd29f93172b7467877f36b12c750b82f86e921c04d
3
+ metadata.gz: 4bc5fac79b7bea854a28d0e8d26af6851ec0937015b88ffad4f8cea5215b3f8f
4
+ data.tar.gz: d4e14b27b7b2c02b441f2161473abe6aa629d1dac75d8045f83537f69cba197e
5
5
  SHA512:
6
- metadata.gz: a3f5776ce0f6ad361f2c344d0ff5d5cef9b6b032e23dc42ae0e877298abd9e95c0156c77334b106036f376e62c60c01ab13344d6bda53baa52c93c7caba79b71
7
- data.tar.gz: d1de077038e5fce86df1871e4702e2abb4c7de4937f66aa8730803bb4542aa8f26c1c848d24bb74db1ce5594514d3a552b92b7ad315d346ead5e7586cb20da20
6
+ metadata.gz: bd4e101e224717ae4e607b54692cf2f1cbcf0c1512ba912e3255aaaa934addcf4829e27b7dc75453d416527257d8dec0cb4ba388a33ee93ccc4db030ac06ea9f
7
+ data.tar.gz: 2dc61c86cfef3d383e41fad38bc0818f4a3231763bd74633102076bc8a9d9ebc3b01a4e927b9e00dd0e7cbb9e977b9e49dc5d05afb0a78e8d097384dcb74cba7
@@ -54,7 +54,9 @@ module Proxy::RemoteExecution::Ssh::Actions
54
54
 
55
55
  plan_event(PickupTimeout, input[:time_to_pickup], optional: true) if input[:time_to_pickup]
56
56
 
57
- input[:job_uuid] = job_storage.store_job(host_name, execution_plan_id, run_step_id, input[:script].tr("\r", ''), effective_user: input[:effective_user])
57
+ input[:job_uuid] =
58
+ job_storage.store_job(host_name, execution_plan_id, run_step_id, input[:script].tr("\r", ''),
59
+ effective_user: input[:effective_user])
58
60
  output[:state] = READY_FOR_PICKUP
59
61
  output[:result] = []
60
62
 
@@ -83,7 +85,11 @@ module Proxy::RemoteExecution::Ssh::Actions
83
85
 
84
86
  def process_external_unversioned(payload)
85
87
  continuous_output = Proxy::Dynflow::ContinuousOutput.new
86
- Array(payload['output']).each { |line| continuous_output.add_output(line, payload['type']) } if payload.key?('output')
88
+ if payload.key?('output')
89
+ Array(payload['output']).each do |line|
90
+ continuous_output.add_output(line, payload['type'])
91
+ end
92
+ end
87
93
  exit_code = payload['exit_code'].to_i if payload['exit_code']
88
94
  process_update(Proxy::Dynflow::Runner::Update.new(continuous_output, exit_code))
89
95
  end
@@ -2,15 +2,39 @@ require 'concurrent'
2
2
  require 'mqtt'
3
3
 
4
4
  class Proxy::RemoteExecution::Ssh::MQTT
5
+ class DispatcherSupervisor < Concurrent::Actor::RestartingContext
6
+ def initialize
7
+ limit = Proxy::RemoteExecution::Ssh::Plugin.settings[:mqtt_rate_limit]
8
+ @dispatcher = DispatcherActor.spawn('MQTT dispatcher',
9
+ Proxy::Dynflow::Core.world.clock,
10
+ limit)
11
+ end
12
+
13
+ def on_message(message)
14
+ case message
15
+ when :dispatcher_reference
16
+ @dispatcher
17
+ when :resumed
18
+ # Carry on
19
+ else
20
+ pass
21
+ end
22
+ end
23
+
24
+ # In case an exception is raised during processing, instruct concurrent-ruby
25
+ # to keep going without losing state
26
+ def behaviour_definition
27
+ Concurrent::Actor::Behaviour.restarting_behaviour_definition(:resume!)
28
+ end
29
+ end
30
+
5
31
  class Dispatcher
6
32
  include Singleton
7
33
 
8
34
  attr_reader :reference
9
35
  def initialize
10
- limit = Proxy::RemoteExecution::Ssh::Plugin.settings[:mqtt_rate_limit]
11
- @reference = DispatcherActor.spawn('MQTT dispatcher',
12
- Proxy::Dynflow::Core.world.clock,
13
- limit)
36
+ @supervisor = DispatcherSupervisor.spawn(name: 'RestartingSupervisor', args: [])
37
+ @reference = @supervisor.ask!(:dispatcher_reference)
14
38
  end
15
39
 
16
40
  def new(uuid, topic, payload)
@@ -159,11 +183,5 @@ class Proxy::RemoteExecution::Ssh::MQTT
159
183
  def timer_off
160
184
  @timer.shutdown
161
185
  end
162
-
163
- # In case an exception is raised during processing, instruct concurrent-ruby
164
- # to keep going without losing state
165
- def behaviour_definition
166
- Concurrent::Actor::Behaviour.restarting_behaviour_definition(:resume!)
167
- end
168
186
  end
169
187
  end
@@ -103,7 +103,8 @@ module Proxy::RemoteExecution::Ssh::Runners
103
103
  # does not close its stderr which trips up the process manager which
104
104
  # expects all FDs to be closed
105
105
 
106
- full_command = [method.ssh_command_prefix, 'ssh', establish_ssh_options, method.ssh_options, @host, 'true'].flatten
106
+ full_command = [method.ssh_command_prefix, 'ssh', establish_ssh_options, method.ssh_options, @host,
107
+ 'true'].flatten
107
108
  log_command(full_command)
108
109
  pm = Proxy::Dynflow::ProcessManager.new(full_command)
109
110
  pm.start!
@@ -90,7 +90,6 @@ module Proxy::RemoteExecution::Ssh::Runners
90
90
  def reset; end
91
91
  end
92
92
 
93
- # rubocop:disable Metrics/ClassLength
94
93
  class ScriptRunner < Proxy::Dynflow::Runner::Base
95
94
  include Proxy::Dynflow::Runner::ProcessManagerCommand
96
95
  include CommandLogging
@@ -162,17 +161,19 @@ module Proxy::RemoteExecution::Ssh::Runners
162
161
  end
163
162
 
164
163
  def preflight_checks
165
- ensure_remote_command(cp_script_to_remote("#!/bin/sh\nexec true", 'test'),
164
+ script = cp_script_to_remote("#!/bin/sh\nexec true")
165
+ ensure_remote_command(script,
166
166
  error: 'Failed to execute script on remote machine, exit code: %{exit_code}.'
167
167
  )
168
168
  unless @user_method.is_a? NoopUserMethod
169
- path = cp_script_to_remote("#!/bin/sh\nexec #{@user_method.cli_command_prefix} true", 'effective-user-test')
170
- ensure_remote_command(path,
169
+ ensure_remote_command("#{@user_method.cli_command_prefix} #{script}",
171
170
  error: 'Failed to change to effective user, exit code: %{exit_code}',
172
171
  tty: true,
173
172
  user_method: @user_method,
174
173
  close_stdin: false)
175
174
  end
175
+ # The path should already be escaped
176
+ ensure_remote_command("rm #{script}")
176
177
  end
177
178
 
178
179
  def prepare_start
@@ -180,7 +181,10 @@ module Proxy::RemoteExecution::Ssh::Runners
180
181
  @output_path = File.join(File.dirname(@remote_script), 'output')
181
182
  @exit_code_path = File.join(File.dirname(@remote_script), 'exit_code')
182
183
  @pid_path = File.join(File.dirname(@remote_script), 'pid')
183
- @remote_script_wrapper = upload_data("echo $$ > #{@pid_path}; exec \"$@\";", File.join(File.dirname(@remote_script), 'script-wrapper'), 555)
184
+ @remote_script_wrapper = upload_data(
185
+ "echo $$ > #{@pid_path}; exec \"$@\";",
186
+ File.join(File.dirname(@remote_script), 'script-wrapper'),
187
+ 555)
184
188
  end
185
189
 
186
190
  # the script that initiates the execution
@@ -192,7 +196,11 @@ module Proxy::RemoteExecution::Ssh::Runners
192
196
  #{@remote_script_wrapper} #{@user_method.cli_command_prefix}#{su_method ? "'#{@remote_script} < /dev/null '" : "#{@remote_script} < /dev/null"}
193
197
  echo \\$?>#{@exit_code_path}
194
198
  EOF
195
- exit $(cat #{@exit_code_path})
199
+ if [ -f #{@exit_code_path} ] && [ $(wc -l < #{@exit_code_path}) -gt 0 ]; then
200
+ exit $(cat #{@exit_code_path})
201
+ else
202
+ exit 1
203
+ fi
196
204
  SCRIPT
197
205
  end
198
206
 
@@ -394,5 +402,4 @@ module Proxy::RemoteExecution::Ssh::Runners
394
402
  end
395
403
  end
396
404
  end
397
- # rubocop:enable Metrics/ClassLength
398
405
  end
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module RemoteExecution
3
3
  module Ssh
4
- VERSION = '0.10.1'
4
+ VERSION = '0.10.3'
5
5
  end
6
6
  end
7
7
  end
@@ -50,7 +50,10 @@ module Proxy::RemoteExecution
50
50
  raise 'mqtt_port has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_port.nil?
51
51
 
52
52
  if Plugin.settings.mqtt_tls.nil?
53
- Plugin.settings.mqtt_tls = [[:foreman_ssl_cert, :ssl_certificate], [:foreman_ssl_key, :ssl_private_key], [:foreman_ssl_ca, :ssl_ca_file]].all? { |(client, server)| ::Proxy::SETTINGS[client] || ::Proxy::SETTINGS[server] }
53
+ Plugin.settings.mqtt_tls = [[:foreman_ssl_cert, :ssl_certificate], [:foreman_ssl_key, :ssl_private_key],
54
+ [:foreman_ssl_ca, :ssl_ca_file]].all? do |(client, server)|
55
+ ::Proxy::SETTINGS[client] || ::Proxy::SETTINGS[server]
56
+ end
54
57
  end
55
58
  end
56
59
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_remote_execution_ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +192,7 @@ homepage: https://github.com/theforeman/smart_proxy_remote_execution_ssh
192
192
  licenses:
193
193
  - GPL-3.0
194
194
  metadata: {}
195
- post_install_message:
195
+ post_install_message:
196
196
  rdoc_options: []
197
197
  require_paths:
198
198
  - lib
@@ -207,8 +207,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  requirements: []
210
- rubygems_version: 3.3.20
211
- signing_key:
210
+ rubygems_version: 3.1.6
211
+ signing_key:
212
212
  specification_version: 4
213
213
  summary: Ssh remote execution provider for Foreman Smart-Proxy
214
214
  test_files: []