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
|
# File 'lib/portalign/config.rb', line 23
def self.parse_opts(args)
{}.tap do |config|
opts = OptionParser.new do |opts|
opts.banner = "Usage: portalign [options]"
opts.separator ""
opts.separator "General options:"
opts.on("--access-key-id=ACCESS_KEY_ID", "The AWS access key id. Better to specify in a config file. See README") do |access_key_id|
config[:access_key_id] = access_key_id
end
opts.on("--secret-access-key=SECRET_ACCESS_KEY", "The AWS secret access key. Better to specify in a config file. See README") do |secret_access_key|
config[:secret_access_key] = secret_access_key
end
opts.on("-p PORTS", "--ports=PORTS", Array, "A comma delimited list of ports to align. Defaults to 22") do |ports|
config[:ports] = ports.map(&:to_i)
end
opts.on("-s SECURITY_GROUPS", "--security_groups=SECURITY_GROUPS", Array, "A comma delimited list of security groups to update.") do |security_groups|
config[:security_groups] = security_groups
end
opts.on("--protocol=PROTOCOL", [:tcp, :udp, :icmp], "The protocol to use. Defaults to tcp.") do |protocol|
config[:protocol] = protocol
end
opts.on("-d", "--deauthorize", "Remove the current IP (and 0.0.0.0/0) from the security groups.") do |deauthorize|
config[:deauthorize] = deauthorize
end
opts.on("-w", "--wide", "Authorizes 0.0.0.0/0 in the security groups.") do |wide|
config[:wide] = wide
end
opts.separator ""
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("-v", "--version", "Show version") do
puts "portalign v#{Portalign::VERSION}"
exit
end
end
opts.parse!(args)
%w(ports security_groups).each {|opt| force_array(config, opt)}
end
end
|