awspec 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/doc/_resource_types/security_group.md +10 -0
- data/doc/resource_types.md +9 -0
- data/lib/awspec/command/generate.rb +1 -1
- data/lib/awspec/generator.rb +1 -0
- data/lib/awspec/generator/spec/ec2.rb +11 -3
- data/lib/awspec/generator/spec/elb.rb +57 -0
- data/lib/awspec/generator/spec/rds.rb +3 -3
- data/lib/awspec/generator/spec/vpc.rb +3 -3
- data/lib/awspec/helper/finder.rb +2 -0
- data/lib/awspec/helper/finder/ebs.rb +27 -0
- data/lib/awspec/helper/finder/ec2.rb +0 -11
- data/lib/awspec/helper/finder/elb.rb +7 -0
- data/lib/awspec/helper/finder/rds.rb +1 -2
- data/lib/awspec/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 233cbc5d2647507ec61335211db2877435b21d93
|
4
|
+
data.tar.gz: a3dca3393a13bcbf2802b80c0fc2f3a226a3ff9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11b94b62d04b77bbd8f477e0f4b554f13309d447b44e336ea558802a10b33cb54ec7cbda2a50031a489a04c216dd60ea789193e7a3d065d81baa784506cfa566
|
7
|
+
data.tar.gz: b141e71cea34ed5595e9d983dbee5505d55b118d9a55b5461c6dca080966513a6456a34fd974618f78fa34dda73ddccff994989fbddd965cc5558dcac303d3b8
|
data/.travis.yml
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
### its(:inbound), its(:outbound)
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
describe security_group('my-security-group-name') do
|
5
|
+
its(:outbound) { should be_opened }
|
6
|
+
its(:inbound) { should be_opened(80) }
|
7
|
+
its(:inbound) { should be_opened(80).protocol('tcp').for('203.0.113.1/32') }
|
8
|
+
its(:inbound) { should be_opened(22).protocol('tcp').for('sg-5a6b7cd8') }
|
9
|
+
end
|
10
|
+
```
|
data/doc/resource_types.md
CHANGED
@@ -127,6 +127,15 @@ SecurityGroup resource type.
|
|
127
127
|
|
128
128
|
### its(:inbound), its(:outbound)
|
129
129
|
|
130
|
+
```ruby
|
131
|
+
describe security_group('my-security-group-name') do
|
132
|
+
its(:outbound) { should be_opened }
|
133
|
+
its(:inbound) { should be_opened(80) }
|
134
|
+
its(:inbound) { should be_opened(80).protocol('tcp').for('203.0.113.1/32') }
|
135
|
+
its(:inbound) { should be_opened(22).protocol('tcp').for('sg-5a6b7cd8') }
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
130
139
|
#### its(:ip_permissions_count), its(:ip_permissions_egress_count), its(:owner_id), its(:group_name), its(:group_id), its(:description), its(:vpc_id)
|
131
140
|
## <a name="vpc">vpc</a>
|
132
141
|
|
data/lib/awspec/generator.rb
CHANGED
@@ -17,6 +17,7 @@ module Awspec::Generator
|
|
17
17
|
instance_tag_name = instance.tag_name
|
18
18
|
subnet = find_subnet(instance.subnet_id)
|
19
19
|
eips = select_eip_by_instance_id(instance_id)
|
20
|
+
volumes = select_ebs_by_instance_id(instance_id)
|
20
21
|
content = ERB.new(ec2_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
21
22
|
end
|
22
23
|
specs.join("\n")
|
@@ -34,10 +35,10 @@ describe ec2('<%= instance_id %>') do
|
|
34
35
|
it { should be_<%= instance.state.name %> }
|
35
36
|
<% describes.each do |describe| %>
|
36
37
|
<%- if instance.members.include?(describe.to_sym) && !instance[describe.to_sym].nil? -%>
|
37
|
-
<%- if instance[describe].is_a?(
|
38
|
-
its(:<%= describe %>) { should eq <%= instance[describe] %> }
|
39
|
-
<%- else -%>
|
38
|
+
<%- if instance[describe].is_a?(String) -%>
|
40
39
|
its(:<%= describe %>) { should eq '<%= instance[describe] %>' }
|
40
|
+
<%- else -%>
|
41
|
+
its(:<%= describe %>) { should eq <%= instance[describe] %> }
|
41
42
|
<%- end -%>
|
42
43
|
<%- end -%>
|
43
44
|
<% end %>
|
@@ -57,6 +58,13 @@ describe ec2('<%= instance_id %>') do
|
|
57
58
|
<% eips.each do |eip| %>
|
58
59
|
it { should have_eip('<%= eip.public_ip %>') }
|
59
60
|
<% end %>
|
61
|
+
<% volumes.each do |volume| %>
|
62
|
+
<%- if volume.tag_name -%>
|
63
|
+
it { should have_ebs('<%= volume.tag_name %>') }
|
64
|
+
<%- else -%>
|
65
|
+
it { should have_ebs('<%= volume.volume_id %>') }
|
66
|
+
<%- end -%>
|
67
|
+
<% end %>
|
60
68
|
end
|
61
69
|
EOF
|
62
70
|
template
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Spec
|
3
|
+
class Elb
|
4
|
+
include Awspec::Helper::Finder
|
5
|
+
def generate_by_vpc_id(vpc_id)
|
6
|
+
describes = %w(
|
7
|
+
load_balancer_name
|
8
|
+
)
|
9
|
+
health_check_options = %w(
|
10
|
+
target interval timeout
|
11
|
+
unhealthy_threshold healthy_threshold
|
12
|
+
)
|
13
|
+
vpc = find_vpc(vpc_id)
|
14
|
+
fail 'Not Found VPC' unless vpc
|
15
|
+
@vpc_id = vpc[:vpc_id]
|
16
|
+
@vpc_tag_name = vpc.tag_name
|
17
|
+
lbs = select_elb_by_vpc_id(@vpc_id)
|
18
|
+
|
19
|
+
specs = lbs.map do |lb|
|
20
|
+
content = ERB.new(elb_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
21
|
+
end
|
22
|
+
specs.join("\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
# rubocop:disable all
|
26
|
+
def elb_spec_template
|
27
|
+
template = <<-'EOF'
|
28
|
+
describe elb('<%= lb.load_balancer_name %>') do
|
29
|
+
it { should exist }
|
30
|
+
<% describes.each do |describe| %>
|
31
|
+
<%- if lb.members.include?(describe.to_sym) && !lb[describe.to_sym].nil? -%>
|
32
|
+
<%- if lb[describe].is_a?(TrueClass) || lb[describe].is_a?(FalseClass) -%>
|
33
|
+
its(:<%= describe %>) { should eq <%= lb[describe] %> }
|
34
|
+
<%- else -%>
|
35
|
+
its(:<%= describe %>) { should eq '<%= lb[describe] %>' }
|
36
|
+
<%- end -%>
|
37
|
+
<%- end -%>
|
38
|
+
<% end %>
|
39
|
+
<% health_check_options.each do |option| %>
|
40
|
+
<%- if lb[:health_check].members.include?(option.to_sym) && !lb[:health_check][option].nil? -%>
|
41
|
+
<%- if lb[:health_check][option].is_a?(String) -%>
|
42
|
+
its(:health_check_<%= option %>) { should eq '<%= lb[:health_check][option] %>' }
|
43
|
+
<%- else -%>
|
44
|
+
its(:health_check_<%= option %>) { should eq <%= lb[:health_check][option] %> }
|
45
|
+
<%- end -%>
|
46
|
+
<%- end -%>
|
47
|
+
<% end %>
|
48
|
+
<% lb[:listener_descriptions].each do |desc| %>
|
49
|
+
it { should have_listener(protocol: '<%= desc.listener.protocol %>', port: <%= desc.listener.load_balancer_port %>, instance_protocol: '<%= desc.listener.instance_protocol %>', instance_port: <%= desc.listener.instance_port %>) }
|
50
|
+
<% end %>
|
51
|
+
end
|
52
|
+
EOF
|
53
|
+
template
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -31,10 +31,10 @@ describe rds('<%= instance_id %>') do
|
|
31
31
|
it { should be_<%= db_instance.db_instance_status %> }
|
32
32
|
<% describes.each do |describe| %>
|
33
33
|
<%- if db_instance.members.include?(describe.to_sym) && !db_instance[describe.to_sym].nil? -%>
|
34
|
-
<%- if db_instance[describe].is_a?(
|
35
|
-
its(:<%= describe %>) { should eq <%= db_instance[describe] %> }
|
36
|
-
<%- else -%>
|
34
|
+
<%- if db_instance[describe].is_a?(String) -%>
|
37
35
|
its(:<%= describe %>) { should eq '<%= db_instance[describe] %>' }
|
36
|
+
<%- else -%>
|
37
|
+
its(:<%= describe %>) { should eq <%= db_instance[describe] %> }
|
38
38
|
<%- end -%>
|
39
39
|
<%- end -%>
|
40
40
|
<% end %>
|
@@ -27,10 +27,10 @@ describe vpc('<%= @vpc_id %>') do
|
|
27
27
|
it { should be_<%= vpc.state %> }
|
28
28
|
<% describes.each do |describe| %>
|
29
29
|
<%- if vpc.key?(describe) -%>
|
30
|
-
<%- if vpc[describe].is_a?(
|
31
|
-
its(:<%= describe %>) { should eq <%= vpc[describe] %> }
|
32
|
-
<%- else -%>
|
30
|
+
<%- if vpc[describe].is_a?(String) -%>
|
33
31
|
its(:<%= describe %>) { should eq '<%= vpc[describe] %>' }
|
32
|
+
<%- else -%>
|
33
|
+
its(:<%= describe %>) { should eq <%= vpc[describe] %> }
|
34
34
|
<%- end -%>
|
35
35
|
<%- end -%>
|
36
36
|
<% end %>
|
data/lib/awspec/helper/finder.rb
CHANGED
@@ -6,6 +6,7 @@ require 'awspec/helper/finder/rds'
|
|
6
6
|
require 'awspec/helper/finder/route53'
|
7
7
|
require 'awspec/helper/finder/s3'
|
8
8
|
require 'awspec/helper/finder/auto_scaling'
|
9
|
+
require 'awspec/helper/finder/ebs'
|
9
10
|
require 'awspec/helper/finder/elb'
|
10
11
|
|
11
12
|
module Awspec::Helper
|
@@ -18,6 +19,7 @@ module Awspec::Helper
|
|
18
19
|
include Awspec::Helper::Finder::Route53
|
19
20
|
include Awspec::Helper::Finder::S3
|
20
21
|
include Awspec::Helper::Finder::AutoScaling
|
22
|
+
include Awspec::Helper::Finder::Ebs
|
21
23
|
include Awspec::Helper::Finder::Elb
|
22
24
|
|
23
25
|
# rubocop:disable all
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Awspec::Helper
|
2
|
+
module Finder
|
3
|
+
module Ebs
|
4
|
+
def find_ebs(volume_id)
|
5
|
+
res = @ec2_client.describe_volumes({
|
6
|
+
filters: [{ name: 'volume-id', values: [volume_id] }]
|
7
|
+
})
|
8
|
+
return res[:volumes][0] if res[:volumes].count == 1
|
9
|
+
res = @ec2_client.describe_volumes({
|
10
|
+
filters: [{ name: 'tag:Name', values: [volume_id] }]
|
11
|
+
})
|
12
|
+
return res[:volumes][0] if res[:volumes].count == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def select_ebs_by_instance_id(id)
|
16
|
+
res = find_ec2(id)
|
17
|
+
volumes = []
|
18
|
+
return volumes unless res
|
19
|
+
res[:block_device_mappings].each do |block|
|
20
|
+
volume = find_ebs(block.ebs.volume_id)
|
21
|
+
volumes.push(volume) if volume
|
22
|
+
end
|
23
|
+
volumes
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -73,17 +73,6 @@ module Awspec::Helper
|
|
73
73
|
return res[:security_groups][0] if res[:security_groups].count == 1
|
74
74
|
end
|
75
75
|
|
76
|
-
def find_ebs(volume_id)
|
77
|
-
res = @ec2_client.describe_volumes({
|
78
|
-
filters: [{ name: 'volume-id', values: [volume_id] }]
|
79
|
-
})
|
80
|
-
return res[:volumes][0] if res[:volumes].count == 1
|
81
|
-
res = @ec2_client.describe_volumes({
|
82
|
-
filters: [{ name: 'tag:Name', values: [volume_id] }]
|
83
|
-
})
|
84
|
-
return res[:volumes][0] if res[:volumes].count == 1
|
85
|
-
end
|
86
|
-
|
87
76
|
def select_ec2_by_vpc_id(vpc_id)
|
88
77
|
res = @ec2_client.describe_instances({
|
89
78
|
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
@@ -11,10 +11,9 @@ module Awspec::Helper
|
|
11
11
|
|
12
12
|
def select_rds_by_vpc_id(vpc_id)
|
13
13
|
res = @rds_client.describe_db_instances
|
14
|
-
|
14
|
+
res[:db_instances].select do |db_instance|
|
15
15
|
db_instance.db_subnet_group.vpc_id == vpc_id
|
16
16
|
end
|
17
|
-
db_instances
|
18
17
|
end
|
19
18
|
end
|
20
19
|
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k1LoW
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- bin/awspec
|
143
143
|
- doc/_resource_types/ec2.md
|
144
144
|
- doc/_resource_types/elb.md
|
145
|
+
- doc/_resource_types/security_group.md
|
145
146
|
- doc/resource_types.md
|
146
147
|
- lib/awspec.rb
|
147
148
|
- lib/awspec/cli.rb
|
@@ -165,6 +166,7 @@ files:
|
|
165
166
|
- lib/awspec/generator/doc/subnet.rb
|
166
167
|
- lib/awspec/generator/doc/vpc.rb
|
167
168
|
- lib/awspec/generator/spec/ec2.rb
|
169
|
+
- lib/awspec/generator/spec/elb.rb
|
168
170
|
- lib/awspec/generator/spec/rds.rb
|
169
171
|
- lib/awspec/generator/spec/route53_hosted_zone.rb
|
170
172
|
- lib/awspec/generator/spec/security_group.rb
|
@@ -172,6 +174,7 @@ files:
|
|
172
174
|
- lib/awspec/helper.rb
|
173
175
|
- lib/awspec/helper/finder.rb
|
174
176
|
- lib/awspec/helper/finder/auto_scaling.rb
|
177
|
+
- lib/awspec/helper/finder/ebs.rb
|
175
178
|
- lib/awspec/helper/finder/ec2.rb
|
176
179
|
- lib/awspec/helper/finder/elb.rb
|
177
180
|
- lib/awspec/helper/finder/rds.rb
|