awspec 0.6.0 → 0.6.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: 64695d36dc5c2eacd3cfb6999fa4639aaad880a5
4
- data.tar.gz: 8f8929979324810c08d756abb48f7f0259a74d17
3
+ metadata.gz: 233cbc5d2647507ec61335211db2877435b21d93
4
+ data.tar.gz: a3dca3393a13bcbf2802b80c0fc2f3a226a3ff9a
5
5
  SHA512:
6
- metadata.gz: a38ee03bfc99f1eac2854bc49b43cb31fc533fdebaa11a4bfef33c0a7bbc0d6060bbc769a254483349fa74c8b7c7916a9285030a4dcfe11e889705915dcbbcf6
7
- data.tar.gz: 04d2562dfed0c1edf4cb1a0cd62c8d9b66b3136c9c7d25b3cad7671b45260d9d0d2d660b8857d120e8c7360a2c65f0d4ee123258222a9a1a4fff6d4b47b6cf20
6
+ metadata.gz: 11b94b62d04b77bbd8f477e0f4b554f13309d447b44e336ea558802a10b33cb54ec7cbda2a50031a489a04c216dd60ea789193e7a3d065d81baa784506cfa566
7
+ data.tar.gz: b141e71cea34ed5595e9d983dbee5505d55b118d9a55b5461c6dca080966513a6456a34fd974618f78fa34dda73ddccff994989fbddd965cc5558dcac303d3b8
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.6
4
- - 2.2.1
3
+ - 2.2.3
4
+ - 2.1.7
5
5
 
6
6
  before_install:
7
7
  - gem update bundler
@@ -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
+ ```
@@ -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
 
@@ -4,7 +4,7 @@ require 'awspec/setup'
4
4
  module Awspec
5
5
  class Generate < Thor
6
6
  types = %w(
7
- vpc ec2 rds security_group
7
+ vpc ec2 rds security_group elb
8
8
  )
9
9
 
10
10
  types.each do |type|
@@ -6,6 +6,7 @@ require 'awspec/generator/spec/rds'
6
6
  require 'awspec/generator/spec/vpc'
7
7
  require 'awspec/generator/spec/security_group'
8
8
  require 'awspec/generator/spec/route53_hosted_zone'
9
+ require 'awspec/generator/spec/elb'
9
10
 
10
11
  # Doc
11
12
  types.each do |type|
@@ -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?(TrueClass) || instance[describe].is_a?(FalseClass) -%>
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?(TrueClass) || db_instance[describe].is_a?(FalseClass) -%>
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?(TrueClass) || vpc[describe].is_a?(FalseClass) -%>
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 %>
@@ -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] }]
@@ -9,6 +9,13 @@ module Awspec::Helper
9
9
  rescue
10
10
  return nil
11
11
  end
12
+
13
+ def select_elb_by_vpc_id(vpc_id)
14
+ res = @elb_client.describe_load_balancers
15
+ res[:load_balancer_descriptions].select do |lb|
16
+ lb.vpc_id == vpc_id
17
+ end
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -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
- db_instances = res[:db_instances].select do |db_instance|
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
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
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.0
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-20 00:00:00.000000000 Z
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