11
12
13
14
15
16
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/audit/lib/my_option_parser.rb', line 11
def parse()
@options = {}
opts = OptionParser.new do|opts|
opts.banner = "Usage: ./main.rb\t--ssh HOST[:PORT] [--user USERNAME] --key KEYFILE --benchmark BENCHMARK"
opts.separator "\t\t\t--ami AMI-ID --credentials CREDENTIALS --benchmark BENCHMARK"
@options[:verbose] = false
opts.on('-v', '--[no-]verbose', 'Output more information') do|v|
@options[:verbose] = v
end
opts.on('-A', '--ami AMI-ID', String, 'Select this AMI for audit') do|ami|
@options[:ami] = ami
end
opts.on('-S', '--ssh HOST', String, 'Select this host for audit') do|host|
@options[:ssh] = host
end
opts.on('-B', '--benchmark BENCHMARK', String, 'Use this benchmark file') do|bm|
@options[:benchmark] = bm
end
opts.on('-K', '--key KEY', String, 'Use this private key file for authentication') do|key|
@options[:key] = key
end
opts.on('-P', '--password PASSWORD', String, 'Use this password for authentication') do|pwd|
@options[:password] = pwd
end
opts.on('-C', '--credentials CREDENTIALS', String, 'Use these Amazon Account credentials to start the AMI') do|cd|
@options[:credentials] = cd
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
opts.parse(@args)
if @options[:ssh].nil? and @options[:ami].nil? then
print "You must specify one of the --ssh or --ami options. Exiting.\n"
exit 1
end
if not @options[:ssh].nil? and not @options[:ami].nil? then
print "Options --ssh and --ami are mutually exclusive, but both chosen. Please specify only one of them. Exiting.\n"
exit 1
end
if @options[:benchmark].nil? then
print "Option --benchmark is required. Please specify a benchmark file for this audit. Exiting.\n"
exit 1
end
if not @options[:ssh].nil? and @options[:key].nil? and @options[:password].nil? then
print "At least one authentication method for SSH is required. Please specify either --key or --password. Exiting.\n"
exit 1
end
return self
end
|