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
|
# File 'lib/awspec/generator/spec/network_acl.rb', line 43
def generate_linespecs(acl)
linespecs = []
protocols = Awspec::Type::NetworkAcl::PROTOCOLS.invert
acl.entries.each do |entry|
line = ''
inout = 'inbound'
inout = 'outbound' if entry.egress
line += 'its(:' + inout + ') { should'
actions = { allow: 'be_allowed', deny: 'be_denied' }
line += ' ' + actions[entry.rule_action.to_sym]
port_range = entry.port_range
unless port_range.nil?
port = if port_range.from == port_range.to
port_range.from.to_s
else
"'" + port_range.from.to_s + '-' + port_range.to.to_s + "'"
end
line += '(' + port + ')'
end
line += ".protocol('" + protocols[entry.protocol.to_i] + "')"
line += ".source('" + entry.cidr_block + "')"
rule_number = entry.rule_number.to_i
rule_number = "'*'" if rule_number == 32_767
line += '.rule_number(' + rule_number.to_s + ')'
line += ' }'
linespecs.push(line)
end
linespecs
end
|