smart_proxy_remote_execution_ssh 0.3.2 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
- require 'smart_proxy_remote_execution_ssh/version'
2
1
  require 'smart_proxy_dynflow'
3
- require 'smart_proxy_remote_execution_ssh/webrick_ext'
2
+ require 'smart_proxy_remote_execution_ssh/version'
4
3
  require 'smart_proxy_remote_execution_ssh/plugin'
4
+ require 'smart_proxy_remote_execution_ssh/webrick_ext'
5
5
 
6
6
  module Proxy::RemoteExecution
7
7
  module Ssh
@@ -19,6 +19,10 @@ module Proxy::RemoteExecution
19
19
  unless File.exist?(public_key_file)
20
20
  raise "Ssh public key file #{public_key_file} doesn't exist"
21
21
  end
22
+
23
+ validate_mode!
24
+ validate_ssh_log_level!
25
+ validate_mqtt_settings!
22
26
  end
23
27
 
24
28
  def private_key_file
@@ -28,6 +32,60 @@ module Proxy::RemoteExecution
28
32
  def public_key_file
29
33
  File.expand_path("#{private_key_file}.pub")
30
34
  end
35
+
36
+ def validate_mode!
37
+ Plugin.settings.mode = Plugin.settings.mode.to_sym
38
+
39
+ unless Plugin::MODES.include? Plugin.settings.mode
40
+ raise "Mode has to be one of #{Plugin::MODES.join(', ')}, given #{Plugin.settings.mode}"
41
+ end
42
+
43
+ if Plugin.settings.async_ssh
44
+ Plugin.logger.warn('Option async_ssh is deprecated, use ssh-async mode instead.')
45
+
46
+ case Plugin.settings.mode
47
+ when :ssh
48
+ Plugin.logger.warn('Deprecated option async_ssh used together with ssh mode, switching mode to ssh-async.')
49
+ Plugin.settings.mode = :'ssh-async'
50
+ when :'async-ssh'
51
+ # This is a noop
52
+ else
53
+ Plugin.logger.warn('Deprecated option async_ssh used together with incompatible mode, ignoring.')
54
+ end
55
+ end
56
+ end
57
+
58
+ def validate_mqtt_settings!
59
+ return unless Plugin.settings.mode == :'pull-mqtt'
60
+
61
+ raise 'mqtt_broker has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_broker.nil?
62
+ raise 'mqtt_port has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_port.nil?
63
+ end
64
+
65
+ def validate_ssh_log_level!
66
+ wanted_level = Plugin.settings.ssh_log_level.to_s
67
+ levels = Plugin::SSH_LOG_LEVELS
68
+ unless levels.include? wanted_level
69
+ raise "Wrong value '#{Plugin.settings.ssh_log_level}' for ssh_log_level, must be one of #{levels.join(', ')}"
70
+ end
71
+
72
+ current = ::Proxy::SETTINGS.log_level.to_s.downcase
73
+
74
+ # regular log levels correspond to upcased ssh logger levels
75
+ ssh, regular = [wanted_level, current].map do |wanted|
76
+ levels.each_with_index.find { |value, _index| value == wanted }.last
77
+ end
78
+
79
+ if ssh < regular
80
+ raise 'ssh_log_level cannot be more verbose than regular log level'
81
+ end
82
+
83
+ Plugin.settings.ssh_log_level = Plugin.settings.ssh_log_level.to_sym
84
+ end
85
+
86
+ def job_storage
87
+ @job_storage ||= Proxy::RemoteExecution::Ssh::JobStorage.new
88
+ end
31
89
  end
32
90
  end
33
91
  end
@@ -4,14 +4,23 @@
4
4
  :local_working_dir: '/var/tmp'
5
5
  :remote_working_dir: '/var/tmp'
6
6
  # :kerberos_auth: false
7
- # :async_ssh: false
7
+
8
+ # Mode of operation, one of ssh, ssh-async, pull, pull-mqtt
9
+ :mode: ssh
8
10
 
9
11
  # Defines how often (in seconds) should the runner check
10
12
  # for new data leave empty to use the runner's default
11
13
  # (1 second for regular, 60 seconds with async_ssh enabled)
12
14
  # :runner_refresh_interval:
13
15
 
14
- # Defines the verbosity of logging coming from Net::SSH
15
- # one of :debug, :info, :warn, :error, :fatal
16
+ # Defines the verbosity of logging coming from ssh command
17
+ # one of :debug, :info, :error, :fatal
16
18
  # must be lower than general log level
17
19
  # :ssh_log_level: fatal
20
+
21
+ # Remove working directories on job completion
22
+ # :cleanup_working_dirs: true
23
+
24
+ # MQTT configuration, need to be set if mode is set to pull-mqtt
25
+ # :mqtt_broker: localhost
26
+ # :mqtt_port: 1883
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.3.2
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-09 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,16 +114,30 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.1'
117
+ version: '0.5'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.1'
124
+ version: '0.5'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: net-ssh
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 4.2.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 4.2.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: mqtt
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ">="
@@ -147,12 +161,26 @@ extra_rdoc_files:
147
161
  files:
148
162
  - LICENSE
149
163
  - README.md
150
- - bundler.plugins.d/remote_execution_ssh.rb
164
+ - bundler.d/remote_execution_ssh.rb
151
165
  - lib/smart_proxy_remote_execution_ssh.rb
166
+ - lib/smart_proxy_remote_execution_ssh/actions.rb
167
+ - lib/smart_proxy_remote_execution_ssh/actions/pull_script.rb
168
+ - lib/smart_proxy_remote_execution_ssh/actions/run_script.rb
152
169
  - lib/smart_proxy_remote_execution_ssh/api.rb
170
+ - lib/smart_proxy_remote_execution_ssh/async_scripts/control.sh
171
+ - lib/smart_proxy_remote_execution_ssh/async_scripts/retrieve.sh
153
172
  - lib/smart_proxy_remote_execution_ssh/cockpit.rb
173
+ - lib/smart_proxy_remote_execution_ssh/dispatcher.rb
154
174
  - lib/smart_proxy_remote_execution_ssh/http_config.ru
175
+ - lib/smart_proxy_remote_execution_ssh/job_storage.rb
176
+ - lib/smart_proxy_remote_execution_ssh/log_filter.rb
177
+ - lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb
155
178
  - lib/smart_proxy_remote_execution_ssh/plugin.rb
179
+ - lib/smart_proxy_remote_execution_ssh/runners.rb
180
+ - lib/smart_proxy_remote_execution_ssh/runners/fake_script_runner.rb
181
+ - lib/smart_proxy_remote_execution_ssh/runners/polling_script_runner.rb
182
+ - lib/smart_proxy_remote_execution_ssh/runners/script_runner.rb
183
+ - lib/smart_proxy_remote_execution_ssh/utils.rb
156
184
  - lib/smart_proxy_remote_execution_ssh/version.rb
157
185
  - lib/smart_proxy_remote_execution_ssh/webrick_ext.rb
158
186
  - settings.d/remote_execution_ssh.yml.example