17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/routes/ssh.rb', line 17
def opts_validate
if @args[0].nil?
App::Terminal::error('You must specify what server you want to SSH into', "This must be specified in: #{App::Terminal::format_directory(ConfigUnique::CONFIG_FILE)}", true)
end
if @args[0] =~ /\Assh_\S+\z/i
config_param = @args[0]
else
config_param = "#{CONFIGURATION_PREFIX}#{@args[0]}"
end
unless App::Config::param_exists(config_param)
App::Terminal::error('Invalid Config Parameter', "The #{App::Terminal::format_highlight('config parameter')} #{App::Terminal::format_invalid(config_param)} doesn't exist in: #{App::Terminal::format_directory(ConfigUnique::CONFIG_FILE)}", true)
end
ssh_parts = App::Config.param(config_param).split('|')
@ssh_user = ssh_parts[0]
@ssh_host = ssh_parts[1]
@ssh_cert = ssh_parts[2].to_s.strip.length == 0 ? nil : ssh_parts[2]
help_message = [
"The file: #{App::Terminal::format_directory(ConfigUnique::CONFIG_FILE)} must contain a line similar to the following:",
nil,
'ssh_ec2=ec2-user|ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com|~/.ssh/pem-key.pem',
'ssh_ec2=ec2-user|ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com',
]
if @ssh_user.nil? || @ssh_user == ''
App::Terminal::error("SSH #{App::Terminal::format_highlight('user')} required", help_message, true)
end
if @ssh_host.nil? || @ssh_host == ''
App::Terminal::error("SSH #{App::Terminal::format_highlight('host')} required", help_message, true)
end
unless @ssh_cert.nil?
unless App::UtilsFiles::file_exists(File.expand_path(@ssh_cert))
App::Terminal::error("PEM key not found: #{App::Terminal::format_directory(@ssh_cert)}")
end
end
end
|