awspec 0.20.2 → 0.21.0
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 +4 -4
- data/awspec.gemspec +1 -0
- data/doc/_resource_types/route_table.md +9 -0
- data/doc/resource_types.md +8 -0
- data/lib/awspec/generator/spec/route_table.rb +18 -3
- data/lib/awspec/helper.rb +1 -0
- data/lib/awspec/helper/color.rb +5 -0
- data/lib/awspec/helper/finder/ec2.rb +24 -20
- data/lib/awspec/helper/finder/vpc.rb +11 -0
- data/lib/awspec/helper/type.rb +2 -1
- data/lib/awspec/matcher/have_route.rb +27 -6
- data/lib/awspec/stub/route_table.rb +50 -0
- data/lib/awspec/type/route_table.rb +16 -4
- data/lib/awspec/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b5d0cf9f4832184634ab74c32058ab4ae35f5a0
|
|
4
|
+
data.tar.gz: 5a7c565b050c7a8056e0c6b1c93505b3283d4db5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9d15177534f9c8aa864c9a8e2bc11039554499409e8b720425623dcc531a14f85d5842578bdab20d0b19a00e03a01f88f9f03eda5951c159b7b77d960616adc2
|
|
7
|
+
data.tar.gz: 5e9a7aefb3dd7b9120f3df3e303e824c12563813deab2bdaa131b760a393dd3ced81fc9fbfbfcc5c8e79de19d2e59a2645383fd58a497d0d73dec22d331cbe41
|
data/awspec.gemspec
CHANGED
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
spec.add_runtime_dependency 'aws_config'
|
|
27
27
|
spec.add_runtime_dependency 'thor'
|
|
28
28
|
spec.add_runtime_dependency 'activesupport'
|
|
29
|
+
spec.add_runtime_dependency 'term-ansicolor'
|
|
29
30
|
spec.add_development_dependency 'bundler', '~> 1.9'
|
|
30
31
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
31
32
|
spec.add_development_dependency 'rubocop'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
### have_route
|
|
2
|
+
|
|
3
|
+
```ruby
|
|
4
|
+
describe route_table('my-route-table') do
|
|
5
|
+
it { should have_route('10.0.0.0/16').target(gateway: 'local') }
|
|
6
|
+
it { should have_route('0.0.0.0/0').target(gateway: 'my-igw') }
|
|
7
|
+
it { should have_route('192.168.1.0/24').target(instance: 'my-instance') }
|
|
8
|
+
end
|
|
9
|
+
```
|
data/doc/resource_types.md
CHANGED
|
@@ -219,6 +219,14 @@ RouteTable resource type.
|
|
|
219
219
|
|
|
220
220
|
### have_route
|
|
221
221
|
|
|
222
|
+
```ruby
|
|
223
|
+
describe route_table('my-route-table') do
|
|
224
|
+
it { should have_route('10.0.0.0/16').target(gateway: 'local') }
|
|
225
|
+
it { should have_route('0.0.0.0/0').target(gateway: 'my-igw') }
|
|
226
|
+
it { should have_route('192.168.1.0/24').target(instance: 'my-instance') }
|
|
227
|
+
end
|
|
228
|
+
```
|
|
229
|
+
|
|
222
230
|
#### its(:route_table_id), its(:vpc_id)
|
|
223
231
|
## <a name="ebs">ebs</a>
|
|
224
232
|
|
|
@@ -22,14 +22,29 @@ module Awspec::Generator
|
|
|
22
22
|
def generate_linespecs(route_table)
|
|
23
23
|
linespecs = []
|
|
24
24
|
route_table.routes.each do |route|
|
|
25
|
-
linespecs.push(ERB.new(
|
|
25
|
+
linespecs.push(ERB.new(route_table_spec_gateway_linetemplate, nil, '-').result(binding)) if route.gateway_id
|
|
26
|
+
if route.instance_id
|
|
27
|
+
instance = find_ec2(route.instance_id)
|
|
28
|
+
linespecs.push(ERB.new(route_table_spec_instance_linetemplate, nil, '-').result(binding)) if instance
|
|
29
|
+
end
|
|
26
30
|
end
|
|
27
31
|
linespecs
|
|
28
32
|
end
|
|
29
33
|
|
|
30
|
-
def
|
|
34
|
+
def route_table_spec_gateway_linetemplate
|
|
31
35
|
template = <<-'EOF'
|
|
32
|
-
it {
|
|
36
|
+
it { should have_route('<%= route.destination_cidr_block %>').target(geteway: '<%= route.gateway_id %>') }
|
|
37
|
+
EOF
|
|
38
|
+
template
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def route_table_spec_instance_linetemplate
|
|
42
|
+
template = <<-'EOF'
|
|
43
|
+
<%- if instance.tag_name -%>
|
|
44
|
+
it { should have_route('<%= route.destination_cidr_block %>').target(instance: '<%= instance.tag_name %>') }
|
|
45
|
+
<%- else -%>
|
|
46
|
+
it { should have_route('<%= route.destination_cidr_block %>').target(instance: '<%= route.instance_id %>') }
|
|
47
|
+
<%- end -%>
|
|
33
48
|
EOF
|
|
34
49
|
template
|
|
35
50
|
end
|
data/lib/awspec/helper.rb
CHANGED
|
@@ -42,26 +42,30 @@ module Awspec::Helper
|
|
|
42
42
|
})
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
# fine_internet_gateway fine_virtual_gateway fine_customer_gateway
|
|
46
|
+
gateway_types = %w(internet virtual cutromer)
|
|
47
|
+
gateway_types.each do |type|
|
|
48
|
+
define_method 'find_' + type + '_gateway' do |*args|
|
|
49
|
+
gateway_id = args.first
|
|
50
|
+
res = @ec2_client.method('describe_' + type + '_gateways').call({
|
|
51
|
+
filters: [
|
|
52
|
+
{
|
|
53
|
+
name: 'internet-gateway-id',
|
|
54
|
+
values: [gateway_id]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
})
|
|
58
|
+
return res[type + '_gateways'].first if res[type + '_gateways'].count == 1
|
|
59
|
+
res = @ec2_client.method('describe_' + type + '_gateways').call({
|
|
60
|
+
filters: [
|
|
61
|
+
{
|
|
62
|
+
name: 'tag:Name',
|
|
63
|
+
values: [gateway_id]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
return res[type + '_gateways'].first if res[type + '_gateways'].count == 1
|
|
68
|
+
end
|
|
65
69
|
end
|
|
66
70
|
|
|
67
71
|
def find_security_group(sg_id)
|
|
@@ -47,6 +47,17 @@ module Awspec::Helper
|
|
|
47
47
|
})
|
|
48
48
|
res[:network_acls]
|
|
49
49
|
end
|
|
50
|
+
|
|
51
|
+
def find_subnet(subnet_id)
|
|
52
|
+
res = @ec2_client.describe_subnets({
|
|
53
|
+
filters: [{ name: 'subnet-id', values: [subnet_id] }]
|
|
54
|
+
})
|
|
55
|
+
return res[:subnets].first if res[:subnets].count == 1
|
|
56
|
+
res = @ec2_client.describe_subnets({
|
|
57
|
+
filters: [{ name: 'tag:Name', values: [subnet_id] }]
|
|
58
|
+
})
|
|
59
|
+
return res[:subnets].first if res[:subnets].count == 1
|
|
60
|
+
end
|
|
50
61
|
end
|
|
51
62
|
end
|
|
52
63
|
end
|
data/lib/awspec/helper/type.rb
CHANGED
|
@@ -19,7 +19,8 @@ module Awspec
|
|
|
19
19
|
|
|
20
20
|
# deprecated resource type
|
|
21
21
|
def auto_scaling_group(name)
|
|
22
|
-
puts '
|
|
22
|
+
puts ''
|
|
23
|
+
puts Color.on_red(Color.white('!!! `auto_scaling_group` type is deprecated. use `autoscaling_group` !!!'))
|
|
23
24
|
Awspec::Type::AutoscalingGroup.new(name)
|
|
24
25
|
end
|
|
25
26
|
end
|
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
require 'ipaddr'
|
|
2
|
+
|
|
3
|
+
RSpec::Matchers.define :have_route do |destination|
|
|
2
4
|
match do |route_table|
|
|
3
|
-
|
|
5
|
+
if !is_ipaddr?(destination) && @use_destination # for deprecated usage
|
|
6
|
+
@gateway_id = destination
|
|
7
|
+
else
|
|
8
|
+
@destination = destination
|
|
9
|
+
end
|
|
10
|
+
route_table.has_route?(@destination, @gateway_id, @instance_id)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
chain :target do |target|
|
|
14
|
+
@gateway_id = target[:gateway]
|
|
15
|
+
@intance_id = target[:instance]
|
|
4
16
|
end
|
|
5
17
|
|
|
6
|
-
chain :destination do |
|
|
7
|
-
|
|
18
|
+
chain :destination do |dest|
|
|
19
|
+
# rubocop:disable Metrics/LineLength
|
|
20
|
+
puts ''
|
|
21
|
+
puts Color.on_red(Color.white('!!! route_table destination is deprecated. see https://github.com/k1LoW/awspec/pull/65 !!!'))
|
|
22
|
+
# rubocop:enable Metrics/LineLength
|
|
23
|
+
@use_destination = true
|
|
24
|
+
@destination = dest
|
|
8
25
|
end
|
|
9
26
|
|
|
10
|
-
|
|
11
|
-
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def is_ipaddr?(str)
|
|
30
|
+
IPAddr.new(str)
|
|
31
|
+
rescue
|
|
32
|
+
false
|
|
12
33
|
end
|
|
13
34
|
end
|
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
Aws.config[:ec2] = {
|
|
2
2
|
stub_responses: {
|
|
3
|
+
describe_instances: {
|
|
4
|
+
reservations: [
|
|
5
|
+
{
|
|
6
|
+
instances: [
|
|
7
|
+
{
|
|
8
|
+
instance_id: 'i-ec12345a',
|
|
9
|
+
image_id: 'ami-abc12def',
|
|
10
|
+
vpc_id: 'vpc-ab123cde',
|
|
11
|
+
subnet_id: 'subnet-1234a567',
|
|
12
|
+
public_ip_address: '123.0.456.789',
|
|
13
|
+
private_ip_address: '10.0.1.1',
|
|
14
|
+
instance_type: 't2.small',
|
|
15
|
+
state: {
|
|
16
|
+
name: 'running'
|
|
17
|
+
},
|
|
18
|
+
security_groups: [
|
|
19
|
+
{
|
|
20
|
+
group_id: 'sg-1a2b3cd4',
|
|
21
|
+
group_name: 'my-security-group-name'
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
block_device_mappings: [
|
|
25
|
+
{
|
|
26
|
+
device_name: '/dev/sda',
|
|
27
|
+
ebs: {
|
|
28
|
+
volume_id: 'vol-123a123b'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
tags: [
|
|
33
|
+
{
|
|
34
|
+
key: 'Name',
|
|
35
|
+
value: 'my-ec2'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
3
43
|
describe_vpcs: {
|
|
4
44
|
vpcs: [
|
|
5
45
|
{
|
|
@@ -40,6 +80,16 @@ Aws.config[:ec2] = {
|
|
|
40
80
|
network_interface_id: nil,
|
|
41
81
|
vpc_peering_connection_id: nil,
|
|
42
82
|
state: 'active'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
destination_cidr_block: '192.168.1.0/24',
|
|
86
|
+
destination_prefix_list_id: nil,
|
|
87
|
+
gateway_id: nil,
|
|
88
|
+
instance_id: 'i-ec12345a',
|
|
89
|
+
instance_owner_id: nil,
|
|
90
|
+
network_interface_id: nil,
|
|
91
|
+
vpc_peering_connection_id: nil,
|
|
92
|
+
state: 'active'
|
|
43
93
|
}
|
|
44
94
|
],
|
|
45
95
|
tags: [
|
|
@@ -6,14 +6,26 @@ module Awspec::Type
|
|
|
6
6
|
@id = @resource[:route_table_id] if @resource
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def has_route?(
|
|
9
|
+
def has_route?(destination, gateway_id = nil, instance_id = nil)
|
|
10
10
|
@resource.routes.find do |route|
|
|
11
11
|
if destination
|
|
12
12
|
next false unless route.destination_cidr_block == destination
|
|
13
13
|
end
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
# * gateway
|
|
15
|
+
next true if route.gateway_id == gateway_id
|
|
16
|
+
# internet gateway
|
|
17
|
+
igw = find_internet_gateway(gateway_id)
|
|
18
|
+
next true if igw && igw.tag_name == gateway_id
|
|
19
|
+
# virtual gateway
|
|
20
|
+
vgw = find_virtual_gateway(gateway_id)
|
|
21
|
+
next true if vgw && vgw.tag_name == gateway_id
|
|
22
|
+
# customer gateway
|
|
23
|
+
cgw = find_customer_gateway(gateway_id)
|
|
24
|
+
next true if cgw && cgw.tag_name == gateway_id
|
|
25
|
+
# instance
|
|
26
|
+
next true if route.instance_id == instance_id
|
|
27
|
+
instance = find_ec2(instance_id)
|
|
28
|
+
next true if instance && instance.tag_name == instance_id
|
|
17
29
|
end
|
|
18
30
|
end
|
|
19
31
|
end
|
data/lib/awspec/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: awspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- k1LoW
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-11-
|
|
11
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -94,6 +94,20 @@ dependencies:
|
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: term-ansicolor
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
97
111
|
- !ruby/object:Gem::Dependency
|
|
98
112
|
name: bundler
|
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -178,6 +192,7 @@ files:
|
|
|
178
192
|
- doc/_resource_types/lambda.md
|
|
179
193
|
- doc/_resource_types/network_acl.md
|
|
180
194
|
- doc/_resource_types/rds_db_parameter_group.md
|
|
195
|
+
- doc/_resource_types/route_table.md
|
|
181
196
|
- doc/_resource_types/security_group.md
|
|
182
197
|
- doc/contributing.md
|
|
183
198
|
- doc/resource_types.md
|
|
@@ -224,6 +239,7 @@ files:
|
|
|
224
239
|
- lib/awspec/generator/spec/vpc.rb
|
|
225
240
|
- lib/awspec/generator/template.rb
|
|
226
241
|
- lib/awspec/helper.rb
|
|
242
|
+
- lib/awspec/helper/color.rb
|
|
227
243
|
- lib/awspec/helper/credentials_loader.rb
|
|
228
244
|
- lib/awspec/helper/finder.rb
|
|
229
245
|
- lib/awspec/helper/finder/autoscaling.rb
|