Module: Proxy::RemoteExecution::Ssh
- Defined in:
- lib/smart_proxy_remote_execution_ssh/version.rb,
lib/smart_proxy_remote_execution_ssh/dispatcher.rb,
lib/smart_proxy_remote_execution_ssh/job_storage.rb,
lib/smart_proxy_remote_execution_ssh/actions/run_script.rb,
lib/smart_proxy_remote_execution_ssh/runners.rb,
lib/smart_proxy_remote_execution_ssh/actions.rb,
lib/smart_proxy_remote_execution_ssh/plugin.rb,
lib/smart_proxy_remote_execution_ssh/mqtt.rb,
lib/smart_proxy_remote_execution_ssh/api.rb,
lib/smart_proxy_remote_execution_ssh.rb
Defined Under Namespace
Modules: Actions, Runners
Classes: Api, Dispatcher, JobStorage, MQTT, Plugin
Constant Summary
collapse
- VERSION =
'1.0.2'
Class Method Summary
collapse
Class Method Details
.ca_public_key_file ⇒ Object
28
29
30
31
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 28
def ca_public_key_file
path = Plugin.settings.ssh_user_ca_public_key_file
File.expand_path(path) if present?(path)
end
|
.cert_file ⇒ Object
24
25
26
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 24
def cert_file
File.expand_path("#{private_key_file}-cert.pub")
end
|
.private_key_file ⇒ Object
16
17
18
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 16
def private_key_file
File.expand_path(Plugin.settings.ssh_identity_key_file)
end
|
.public_key_file ⇒ Object
20
21
22
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 20
def public_key_file
File.expand_path("#{private_key_file}.pub")
end
|
103
104
105
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 103
def requires_configured_ssh?
Plugin.settings.mode == :ssh || Plugin.settings.cockpit_integration
end
|
.validate! ⇒ Object
9
10
11
12
13
14
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 9
def validate!
validate_mode!
validate_ssh_settings!
validate_mqtt_settings!
validate_socket_path!
end
|
.validate_mode! ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 33
def validate_mode!
Plugin.settings.mode = Plugin.settings.mode.to_sym
unless Plugin::MODES.include? Plugin.settings.mode
raise "Mode has to be one of #{Plugin::MODES.join(', ')}, given #{Plugin.settings.mode}"
end
end
|
.validate_mqtt_settings! ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 41
def validate_mqtt_settings!
return unless with_mqtt?
raise 'mqtt_broker has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_broker.nil?
raise 'mqtt_port has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_port.nil?
if Plugin.settings.mqtt_tls.nil?
Plugin.settings.mqtt_tls = [[:foreman_ssl_cert, :ssl_certificate], [:foreman_ssl_key, :ssl_private_key],
[:foreman_ssl_ca, :ssl_ca_file]].all? do |(client, server)|
::Proxy::SETTINGS[client] || ::Proxy::SETTINGS[server]
end
end
end
|
.validate_socket_path! ⇒ Object
107
108
109
110
111
112
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 107
def validate_socket_path!
return unless Plugin.settings.mode == :'ssh'
socket_path = File.expand_path(Plugin.settings.socket_working_dir)
raise "Socket path #{socket_path} is too long" if socket_path.length > Plugin::SOCKET_PATH_MAX_LENGTH
end
|
.validate_ssh_log_level! ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 82
def validate_ssh_log_level!
wanted_level = Plugin.settings.ssh_log_level.to_s
levels = Plugin::SSH_LOG_LEVELS
unless levels.include? wanted_level
raise "Wrong value '#{Plugin.settings.ssh_log_level}' for ssh_log_level, must be one of #{levels.join(', ')}"
end
current = ::Proxy::SETTINGS.log_level.to_s.downcase
ssh, regular = [wanted_level, current].map do |wanted|
levels.each_with_index.find { |value, _index| value == wanted }.last
end
if ssh < regular
raise 'ssh_log_level cannot be more verbose than regular log level'
end
Plugin.settings.ssh_log_level = Plugin.settings.ssh_log_level.to_sym
end
|
.validate_ssh_settings! ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 55
def validate_ssh_settings!
return unless requires_configured_ssh?
unless private_key_file
raise "settings for `ssh_identity_key` not set"
end
unless File.exist?(private_key_file)
raise "SSH private key file #{private_key_file} doesn't exist.\n"\
"You can generate one with `ssh-keygen -t rsa -b 4096 -f #{private_key_file} -N ''`"
end
unless File.exist?(public_key_file)
raise "SSH public key file #{public_key_file} doesn't exist"
end
if present?(Plugin.settings.ssh_user_ca_public_key_file)
{ ca_public_key_file: 'CA public key', cert_file: 'certificate' }.each do |file, label|
file_path = public_send(file)
unless file_path && File.exist?(file_path)
raise "SSH #{label} file '#{file_path}' doesn't exist"
end
end
end
validate_ssh_log_level!
end
|
.with_mqtt? ⇒ Boolean
118
119
120
|
# File 'lib/smart_proxy_remote_execution_ssh.rb', line 118
def with_mqtt?
Proxy::RemoteExecution::Ssh::Plugin.settings.mode == :'pull-mqtt'
end
|