awspec 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 909bee83f8e0ef005d5b759f4bcdb09f511fa538
4
- data.tar.gz: e2f7486711f097f392d15ea5a3c5e8e76e9ac0fe
3
+ metadata.gz: 61c1f9349ff77a468315fe6f7666e45e4009467a
4
+ data.tar.gz: b4df26ffef56668555305cbc9b5eae41a92a0738
5
5
  SHA512:
6
- metadata.gz: c5ee3970663f1fd780510981e655bdf03d5cccc8b1012075d44a3d6028586f4e8a912dbaa996090875e67bb6edf047ea7c64c71d1da41cb905805ab8c5e49a4a
7
- data.tar.gz: fc09064d0a1efb4fff46c50e2e8c01342ab49fce8b9799783a372792a4dcad45617920ce0c7d4c4ad5056119d22ea62903be0fd95a07c791a1150357df9ed772
6
+ metadata.gz: 599b28d68053b6c8fc5432bacc5f11a65b205343874e2433c824f615ad43c1bfd9c71729c3dfad98ad4c3568498e242b5df5c42798aed9f61452a932ad3eb3a2
7
+ data.tar.gz: 6df2de8ba7d4d83652737b29b512a9e984fee23fbd8af0b93f6084b1307a9fef6daf4b592344ca292d3a9d3c6bf76e1f02845079a8024aee203c1c099d427e14
data/README.md CHANGED
@@ -95,7 +95,7 @@ $ export AWS_PROFILE=mycreds; bundle exec rake spec
95
95
  - Route53
96
96
  - [x] Route53 Hosted Zone (`route53_hosted_zone`)
97
97
  - AutoScaling
98
- - [x] Auto Scaling Group (`auto_scaling_group`)
98
+ - [x] AutoScaling Group (`autoscaling_group`)
99
99
  - [x] Subnet (`subnet`)
100
100
  - [x] RouteTable (`route_table`)
101
101
  - [x] EBS Volume (`ebs`)
@@ -112,13 +112,10 @@ $ export AWS_PROFILE=mycreds; bundle exec rake spec
112
112
  - [x] CloudWatch Alarm (`cloudwatch_alarm`)
113
113
  - SES
114
114
  - [x] SES Identity (`ses_identity`)
115
+ - [x] NetworkAcl (`network_acl`)
115
116
 
116
117
  [Resource Types more infomation here](doc/resource_types.md)
117
118
 
118
- ### Next..?
119
-
120
- - ...
121
-
122
119
  ## References
123
120
 
124
121
  awspec is inspired by Serverspec.
@@ -7,7 +7,7 @@ module Awspec
7
7
  class_option :profile
8
8
 
9
9
  types = %w(
10
- vpc ec2 rds security_group elb
10
+ vpc ec2 rds security_group elb network_acl
11
11
  )
12
12
 
13
13
  types.each do |type|
@@ -19,10 +19,6 @@ module Awspec
19
19
  end
20
20
  end
21
21
 
22
- types_for_generate_all = %w(
23
- iam_policy cloudwatch_alarm
24
- )
25
-
26
22
  desc 'route53_hosted_zone [example.com.]', 'Generate route53_hosted_zone spec from Domain name'
27
23
  def route53_hosted_zone(hosted_zone)
28
24
  Awspec::Helper::CredentialsLoader.load(options[:profile])
@@ -9,6 +9,7 @@ require 'awspec/generator/spec/route53_hosted_zone'
9
9
  require 'awspec/generator/spec/elb'
10
10
  require 'awspec/generator/spec/iam_policy'
11
11
  require 'awspec/generator/spec/cloudwatch_alarm'
12
+ require 'awspec/generator/spec/network_acl'
12
13
 
13
14
  # Doc
14
15
  require 'awspec/generator/doc/type'
@@ -0,0 +1,96 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class NetworkAcl
4
+ include Awspec::Helper::Finder
5
+ def generate_by_vpc_id(vpc_id)
6
+ describes = %w(
7
+ )
8
+ vpc = find_vpc(vpc_id)
9
+ fail 'Not Found VPC' unless vpc
10
+ @vpc_id = vpc[:vpc_id]
11
+ @vpc_tag_name = vpc.tag_name
12
+ network_acls = select_network_acl_by_vpc_id(@vpc_id)
13
+ specs = network_acls.map do |acl|
14
+ linespecs = generate_linespecs(acl)
15
+ subnet_specs = generate_subnet_specs(acl)
16
+ network_acl_id = acl[:network_acl_id]
17
+ network_acl_tag_name = acl.tag_name
18
+ inbound_entries_count = acl.entries.count do |entry|
19
+ entry.egress == false
20
+ end
21
+ outbound_entries_count = acl.entries.count do |entry|
22
+ entry.egress == true
23
+ end
24
+ content = ERB.new(network_acl_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
25
+ end
26
+ specs.join("\n")
27
+ end
28
+
29
+ def generate_subnet_specs(acl)
30
+ specs = []
31
+ acl.associations.each do |a|
32
+ subnet = find_subnet(a.subnet_id)
33
+ if subnet.tag_name
34
+ spec = "it { should have_subnet('" + subnet.tag_name + "') }"
35
+ else
36
+ spec = "it { should have_subnet('" + subnet.subnet_id + "') }"
37
+ end
38
+ specs.push(spec)
39
+ end
40
+ specs
41
+ end
42
+
43
+ def generate_linespecs(acl)
44
+ linespecs = []
45
+ protocols = Awspec::Type::NetworkAcl::PROTOCOLS.invert
46
+ acl.entries.each do |entry|
47
+ line = ''
48
+ inout = 'inbound'
49
+ inout = 'outbound' if entry.egress
50
+ line += 'its(:' + inout + ') { should'
51
+ actions = { allow: 'be_allowed', deny: 'be_denied' }
52
+ line += ' ' + actions[entry.rule_action.to_sym]
53
+ port_range = entry.port_range
54
+ unless port_range.nil?
55
+ if port_range.from == port_range.to
56
+ port = port_range.from.to_s
57
+ else
58
+ port = "'" + port_range.from.to_s + '-' + port_range.to.to_s + "'"
59
+ end
60
+ line += '(' + port + ')'
61
+ end
62
+ line += ".protocol('" + protocols[entry.protocol.to_i] + "')"
63
+ line += ".source('" + entry.cidr_block + "')"
64
+ rule_number = entry.rule_number.to_i
65
+ rule_number = "'*'" if rule_number == 32_767
66
+ line += '.rule_number(' + rule_number.to_s + ')'
67
+ line += ' }'
68
+ linespecs.push(line)
69
+ end
70
+ linespecs
71
+ end
72
+
73
+ def network_acl_spec_template
74
+ template = <<-'EOF'
75
+ <%- if network_acl_tag_name -%>
76
+ describe network_acl('<%= network_acl_tag_name %>') do
77
+ <%- else -%>
78
+ describe network_acl('<%= network_acl_id %>') do
79
+ <%- end -%>
80
+ it { should exist }
81
+ it { should belong_to_vpc('<%= @vpc_tag_name %>') }
82
+ <% subnet_specs.each do |spec| %>
83
+ <%= spec %>
84
+ <% end %>
85
+ <% linespecs.each do |line| %>
86
+ <%= line %>
87
+ <% end %>
88
+ its(:inbound_entries_count) { should eq <%= inbound_entries_count %> }
89
+ its(:outbound_entries_count) { should eq <%= inbound_entries_count %> }
90
+ end
91
+ EOF
92
+ template
93
+ end
94
+ end
95
+ end
96
+ end
@@ -47,6 +47,24 @@ module Awspec::Type
47
47
  end
48
48
  end
49
49
 
50
+ # rubocop:disable Metrics/LineLength
51
+ PROTOCOLS = { 'ALL' => -1, 'HOPOPT' => 0, 'ICMP' => 1, 'IGMP' => 2, 'GGP' => 3, 'IPv4' => 4, 'ST' => 5, 'TCP' => 6, 'CBT' => 7, 'EGP' => 8, 'IGP' => 9, 'BBN-RCC-MON' => 10,
52
+ 'NVP-II' => 11, 'PUP' => 12, 'ARGUS' => 13, 'EMCON' => 14, 'XNET' => 15, 'CHAOS' => 16, 'UDP' => 17, 'MUX' => 18, 'DCN-MEAS' => 19, 'HMP' => 20,
53
+ 'PRM' => 21, 'XNS-IDP' => 22, 'TRUNK-1' => 23, 'TRUNK-2' => 24, 'LEAF-1' => 25, 'LEAF-2' => 26, 'RDP' => 27, 'IRTP' => 28, 'ISO-TP4' => 29, 'NETBLT' => 30,
54
+ 'MFE-NSP' => 31, 'MERIT-INP' => 32, 'DCCP' => 33, '3PC' => 34, 'IDPR' => 35, 'XTP' => 36, 'DDP' => 37, 'IDPR-CMTP' => 38, 'TP++' => 39, 'IL' => 40,
55
+ 'IPv6' => 41, 'SDRP' => 42, 'IPv6-Route' => 43, 'IPv6-Frag' => 44, 'IDRP' => 45, 'RSVP' => 46, 'GRE' => 47, 'DSR' => 48, 'BNA' => 49, 'ESP' => 50,
56
+ 'AH' => 51, 'I-NLSP' => 52, 'SWIPE' => 53, 'NARP' => 54, 'MOBILE' => 55, 'TLSP' => 56, 'IPv6-ICMP' => 58, 'IPv6-NoNxt' => 59, 'IPv6-Opts' => 60,
57
+ '61' => 61, 'CFTP' => 62, '63' => 63, 'SAT-EXPAK' => 64, 'KRYPTOLAN' => 65, 'RVD' => 66, 'IPPC' => 67, '68' => 68, 'SAT-MON' => 69, 'VISA' => 70,
58
+ 'IPCV' => 71, 'CPNX' => 72, 'CPHB' => 73, 'WSN' => 74, 'PVP' => 75, 'BR-SAT-MON' => 76, 'SUN-ND' => 77, 'WB-MON' => 78, 'WB-EXPAK' => 79, 'ISO-IP' => 80,
59
+ 'VMTP' => 81, 'SECURE-VMTP' => 82, 'VINES' => 83, 'IPTM' => 84, 'TTP' => 84, 'NSFNET-IGP' => 85, 'DGP' => 86, 'TCF' => 87, 'EIGRP' => 88, 'OSPFIGP' => 89, 'Sprite-RPC' => 90,
60
+ 'LARP' => 91, 'MTP' => 92, 'AX.25' => 93, 'IPIP' => 94, 'MICP' => 95, 'SCC-SP' => 96, 'ETHERIP' => 97, 'ENCAP' => 98, '99' => 99, 'GMTP' => 100,
61
+ 'IFMP' => 101, 'PNNI' => 102, 'PIM' => 103, 'ARIS' => 104, 'SCPS' => 105, 'QNX' => 106, 'A/N' => 107, 'IPComp' => 108, 'SNP' => 109, 'Compaq-Peer' => 110,
62
+ 'IPX-in-IP' => 111, 'VRRP' => 112, 'PGM' => 113, '114' => 114, 'L2TP' => 115, 'DDX' => 116, 'IATP' => 117, 'STP' => 118, 'SRP' => 119, 'UTI' => 120,
63
+ 'SMP' => 121, 'SM' => 122, 'PTP' => 123, 'ISIS over IPv4' => 124, 'FIRE' => 125, 'CRTP' => 126, 'CRUDP' => 127, 'SSCOPMCE' => 128, 'IPLT' => 129, 'SPS' => 130,
64
+ 'PIPE' => 131, 'SCTP' => 132, 'FC' => 133, 'RSVP-E2E-IGNORE' => 134, 'Mobility Header' => 135, 'UDPLite' => 136, 'MPLS-in-IP' => 137, 'manet' => 138, 'HIP' => 139, 'Shim6' => 140,
65
+ 'WESP' => 141, 'ROHC' => 142, '253' => 253, '254' => 254 }
66
+ # rubocop:enable Metrics/LineLength
67
+
50
68
  private
51
69
 
52
70
  def entry?(rule_action, port = nil, protocol = nil, cidr = nil, rule_number = nil)
@@ -71,24 +89,6 @@ module Awspec::Type
71
89
  end
72
90
  end
73
91
 
74
- # rubocop:disable Metrics/LineLength
75
- PROTOCOLS = { 'ALL' => -1, 'HOPOPT' => 0, 'ICMP' => 1, 'IGMP' => 2, 'GGP' => 3, 'IPv4' => 4, 'ST' => 5, 'TCP' => 6, 'CBT' => 7, 'EGP' => 8, 'IGP' => 9, 'BBN-RCC-MON' => 10,
76
- 'NVP-II' => 11, 'PUP' => 12, 'ARGUS' => 13, 'EMCON' => 14, 'XNET' => 15, 'CHAOS' => 16, 'UDP' => 17, 'MUX' => 18, 'DCN-MEAS' => 19, 'HMP' => 20,
77
- 'PRM' => 21, 'XNS-IDP' => 22, 'TRUNK-1' => 23, 'TRUNK-2' => 24, 'LEAF-1' => 25, 'LEAF-2' => 26, 'RDP' => 27, 'IRTP' => 28, 'ISO-TP4' => 29, 'NETBLT' => 30,
78
- 'MFE-NSP' => 31, 'MERIT-INP' => 32, 'DCCP' => 33, '3PC' => 34, 'IDPR' => 35, 'XTP' => 36, 'DDP' => 37, 'IDPR-CMTP' => 38, 'TP++' => 39, 'IL' => 40,
79
- 'IPv6' => 41, 'SDRP' => 42, 'IPv6-Route' => 43, 'IPv6-Frag' => 44, 'IDRP' => 45, 'RSVP' => 46, 'GRE' => 47, 'DSR' => 48, 'BNA' => 49, 'ESP' => 50,
80
- 'AH' => 51, 'I-NLSP' => 52, 'SWIPE' => 53, 'NARP' => 54, 'MOBILE' => 55, 'TLSP' => 56, 'IPv6-ICMP' => 58, 'IPv6-NoNxt' => 59, 'IPv6-Opts' => 60,
81
- '61' => 61, 'CFTP' => 62, '63' => 63, 'SAT-EXPAK' => 64, 'KRYPTOLAN' => 65, 'RVD' => 66, 'IPPC' => 67, '68' => 68, 'SAT-MON' => 69, 'VISA' => 70,
82
- 'IPCV' => 71, 'CPNX' => 72, 'CPHB' => 73, 'WSN' => 74, 'PVP' => 75, 'BR-SAT-MON' => 76, 'SUN-ND' => 77, 'WB-MON' => 78, 'WB-EXPAK' => 79, 'ISO-IP' => 80,
83
- 'VMTP' => 81, 'SECURE-VMTP' => 82, 'VINES' => 83, 'IPTM' => 84, 'TTP' => 84, 'NSFNET-IGP' => 85, 'DGP' => 86, 'TCF' => 87, 'EIGRP' => 88, 'OSPFIGP' => 89, 'Sprite-RPC' => 90,
84
- 'LARP' => 91, 'MTP' => 92, 'AX.25' => 93, 'IPIP' => 94, 'MICP' => 95, 'SCC-SP' => 96, 'ETHERIP' => 97, 'ENCAP' => 98, '99' => 99, 'GMTP' => 100,
85
- 'IFMP' => 101, 'PNNI' => 102, 'PIM' => 103, 'ARIS' => 104, 'SCPS' => 105, 'QNX' => 106, 'A/N' => 107, 'IPComp' => 108, 'SNP' => 109, 'Compaq-Peer' => 110,
86
- 'IPX-in-IP' => 111, 'VRRP' => 112, 'PGM' => 113, '114' => 114, 'L2TP' => 115, 'DDX' => 116, 'IATP' => 117, 'STP' => 118, 'SRP' => 119, 'UTI' => 120,
87
- 'SMP' => 121, 'SM' => 122, 'PTP' => 123, 'ISIS over IPv4' => 124, 'FIRE' => 125, 'CRTP' => 126, 'CRUDP' => 127, 'SSCOPMCE' => 128, 'IPLT' => 129, 'SPS' => 130,
88
- 'PIPE' => 131, 'SCTP' => 132, 'FC' => 133, 'RSVP-E2E-IGNORE' => 134, 'Mobility Header' => 135, 'UDPLite' => 136, 'MPLS-in-IP' => 137, 'manet' => 138, 'HIP' => 139, 'Shim6' => 140,
89
- 'WESP' => 141, 'ROHC' => 142, '253' => 253, '254' => 254 }
90
- # rubocop:enable Metrics/LineLength
91
-
92
92
  def protocol_match?(a, b)
93
93
  if a.match(/\A\d+\z/) && a.to_i >= 0
94
94
  return false unless b.to_i == a.to_i
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.20.0'
2
+ VERSION = '0.20.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
@@ -216,6 +216,7 @@ files:
216
216
  - lib/awspec/generator/spec/ec2.rb
217
217
  - lib/awspec/generator/spec/elb.rb
218
218
  - lib/awspec/generator/spec/iam_policy.rb
219
+ - lib/awspec/generator/spec/network_acl.rb
219
220
  - lib/awspec/generator/spec/rds.rb
220
221
  - lib/awspec/generator/spec/route53_hosted_zone.rb
221
222
  - lib/awspec/generator/spec/security_group.rb