awspec 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b78df0f6ccf21eb679be4d198c3b5c623555628
4
- data.tar.gz: 808c449ddfc01e12591724c77abb7b3445c9e73d
3
+ metadata.gz: 757db940be85a0bf4a58b7b685b9872846a4415d
4
+ data.tar.gz: 7024a655265da3c039ae75b8d28059e365341e7d
5
5
  SHA512:
6
- metadata.gz: c88a4c3035e02132816ff1d268eb92d437193f65211002042897a037eaa68618898c1c143c8eb0b9d5310dedd964cb04cefe9f0ab21b2ca14db2951b7798b528
7
- data.tar.gz: d7b878cba6424cc5998e73fb2422e1159294cd89440a8d3772716ac02ad2c335b6869227993df51c8925664de38f3f50fb735105d2a199ce5efbdaf83009ba69
6
+ metadata.gz: 17611435cf27ed855193720dcc961ad08f2c52ecf73f51064031970128fb244731b0486c9e8801ad7c7663d8d08bdf5f3dfdeb0da799a50805d51a0d8f1a91ca
7
+ data.tar.gz: adca87391cab21aefad2260a135d1ce44438992142f177d49de636b81856ca4d4f99731d7441928f3a1fde36a3633be154b7351fd2004bc83aa6600f1a190725
@@ -8,14 +8,20 @@ module Awspec
8
8
  )
9
9
 
10
10
  types.each do |type|
11
- desc type + ' [vpc_id]', 'Generate VPC spec from VPC ID (or VPC "Name" tag)'
11
+ desc type + ' [vpc_id]', "Generate #{type} spec from VPC ID (or VPC \"Name\" tag)"
12
12
  define_method type do |*args|
13
13
  load_secrets
14
14
  vpc_id = args.first
15
- eval "puts Awspec::Generator::Spec::#{type.to_camel_case}.new.generate_from_vpc(vpc_id)"
15
+ eval "puts Awspec::Generator::Spec::#{type.to_camel_case}.new.generate_by_vpc_id(vpc_id)"
16
16
  end
17
17
  end
18
18
 
19
+ desc 'route53_hosted_zone [example.com.]', 'Generate route53_hosted_zone spec from Domain name'
20
+ def route53_hosted_zone(hosted_zone)
21
+ load_secrets
22
+ puts Awspec::Generator::Spec::Route53HostedZone.new.generate_by_domain_name(hosted_zone)
23
+ end
24
+
19
25
  no_commands do
20
26
  def load_secrets
21
27
  creds = YAML.load_file('spec/secrets.yml') if File.exist?('spec/secrets.yml')
@@ -2,3 +2,4 @@ require 'awspec/generator/spec/ec2'
2
2
  require 'awspec/generator/spec/rds'
3
3
  require 'awspec/generator/spec/vpc'
4
4
  require 'awspec/generator/spec/security_group'
5
+ require 'awspec/generator/spec/route53_hosted_zone'
@@ -2,7 +2,7 @@ module Awspec::Generator
2
2
  module Spec
3
3
  class Ec2
4
4
  include Awspec::Helper::Finder
5
- def generate_from_vpc(vpc_id)
5
+ def generate_by_vpc_id(vpc_id)
6
6
  describes = %w(
7
7
  instance_id image_id private_dns_name public_dns_name
8
8
  instance_type private_ip_address public_ip_address
@@ -16,7 +16,6 @@ module Awspec::Generator
16
16
  instance_id = instance[:instance_id]
17
17
  instance_tag_name = instance.tag_name
18
18
  subnet = find_subnet(instance.subnet_id)
19
- subnet_tag_name = subnet.tag_name
20
19
  eips = select_eip_by_instance_id(instance_id)
21
20
  content = ERB.new(ec2_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
22
21
  end
@@ -34,7 +33,7 @@ describe ec2('<%= instance_id %>') do
34
33
  it { should exist }
35
34
  it { should be_<%= instance.state.name %> }
36
35
  <% describes.each do |describe| %>
37
- <%- if instance.key?(describe) -%>
36
+ <%- if instance.members.include?(describe.to_sym) && !instance[describe.to_sym].nil? -%>
38
37
  <%- if instance[describe].is_a?(TrueClass) || instance[describe].is_a?(FalseClass) -%>
39
38
  its(:<%= describe %>) { should eq <%= instance[describe] %> }
40
39
  <%- else -%>
@@ -50,7 +49,11 @@ describe ec2('<%= instance_id %>') do
50
49
  <%- else -%>
51
50
  it { should belong_to_vpc('<%= @vpc_id %>') }
52
51
  <%- end -%>
53
- it { should belong_to_subnet('<%= subnet_tag_name %>') }
52
+ <%- if subnet.tag_name -%>
53
+ it { should belong_to_subnet('<%= subnet.tag_name %>') }
54
+ <%- else -%>
55
+ it { should belong_to_subnet('<%= subnet.subnet_id %>') }
56
+ <%- end -%>
54
57
  <% eips.each do |eip| %>
55
58
  it { should have_eip('<%= eip.public_ip %>') }
56
59
  <% end %>
@@ -2,7 +2,7 @@ module Awspec::Generator
2
2
  module Spec
3
3
  class Rds
4
4
  include Awspec::Helper::Finder
5
- def generate_from_vpc(vpc_id)
5
+ def generate_by_vpc_id(vpc_id)
6
6
  describes = %w(
7
7
  db_instance_identifier db_instance_class multi_az availability_zone
8
8
  )
@@ -30,7 +30,7 @@ describe rds('<%= instance_id %>') do
30
30
  it { should exist }
31
31
  it { should be_<%= db_instance.db_instance_status %> }
32
32
  <% describes.each do |describe| %>
33
- <%- if db_instance.key?(describe) -%>
33
+ <%- if db_instance.members.include?(describe.to_sym) && !db_instance[describe.to_sym].nil? -%>
34
34
  <%- if db_instance[describe].is_a?(TrueClass) || db_instance[describe].is_a?(FalseClass) -%>
35
35
  its(:<%= describe %>) { should eq <%= db_instance[describe] %> }
36
36
  <%- else -%>
@@ -0,0 +1,54 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class Route53HostedZone
4
+ include Awspec::Helper::Finder
5
+ def generate_by_domain_name(id)
6
+ hosted_zone = find_hosted_zone(id)
7
+ fail 'Not Found Route53 Hosted Zone' unless hosted_zone
8
+ id = hosted_zone[:id]
9
+ res = @route53_client.list_resource_record_sets({
10
+ hosted_zone_id: id
11
+ })
12
+ resource_record_sets = res.resource_record_sets.map do |record_set|
13
+ generate_linespec(record_set)
14
+ end
15
+
16
+ content = ERB.new(route53_hosted_zone_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
17
+ end
18
+
19
+ def generate_linespec(record_set)
20
+ if !record_set.resource_records.empty?
21
+ template = <<-'EOF'
22
+ it { should have_record_set('<%= record_set.name %>').<%= type %>('<%= v %>').ttl(<%= record_set.ttl %>) }
23
+ EOF
24
+ v = record_set.resource_records.map { |r| r.value }.join("\n")
25
+ type = record_set.type.downcase
26
+ return ERB.new(template, nil, '-').result(binding)
27
+ else
28
+ # ALIAS
29
+ dns_name = record_set.alias_target.dns_name
30
+ hosted_zone_id = record_set.alias_target.hosted_zone_id
31
+ # rubocop:disable all
32
+ template = <<-'EOF'
33
+ it { should have_record_set('<%= record_set.name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>').ttl(<%= record_set.ttl %>) }
34
+ EOF
35
+ # rubocop:enable all
36
+ return ERB.new(template, nil, '-').result(binding)
37
+ end
38
+ end
39
+
40
+ def route53_hosted_zone_spec_template
41
+ template = <<-'EOF'
42
+ describe route53_hosted_zone('<%= hosted_zone.name %>') do
43
+ it { should exist }
44
+ its(:resource_record_set_count) { should eq <%= hosted_zone.resource_record_set_count %> }
45
+ <% resource_record_sets.each do |line| %>
46
+ <%= line %>
47
+ <% end %>
48
+ end
49
+ EOF
50
+ template
51
+ end
52
+ end
53
+ end
54
+ end
@@ -2,7 +2,7 @@ module Awspec::Generator
2
2
  module Spec
3
3
  class SecurityGroup
4
4
  include Awspec::Helper::Finder
5
- def generate_from_vpc(vpc_id)
5
+ def generate_by_vpc_id(vpc_id)
6
6
  describes = %w(
7
7
  group_id
8
8
  )
@@ -2,7 +2,7 @@ module Awspec::Generator
2
2
  module Spec
3
3
  class Vpc
4
4
  include Awspec::Helper::Finder
5
- def generate_from_vpc(vpc_id)
5
+ def generate_by_vpc_id(vpc_id)
6
6
  describes = %w(
7
7
  vpc_id cidr_block
8
8
  )
@@ -7,6 +7,7 @@ module Awspec
7
7
  generate_spec_helper
8
8
  generate_rakefile
9
9
  generate_dotgitignore
10
+ generate_dotrspec
10
11
  end
11
12
 
12
13
  def self.generate_spec_helper
@@ -29,7 +30,7 @@ EOF
29
30
  end
30
31
  else
31
32
  FileUtils.mkdir dir
32
- puts ' + #{dir}/'
33
+ puts " + #{dir}/"
33
34
  end
34
35
 
35
36
  if File.exist? 'spec/spec_helper.rb'
@@ -72,5 +73,20 @@ EOF
72
73
  puts ' + spec/.gitignore'
73
74
  end
74
75
  end
76
+
77
+ def self.generate_dotrspec
78
+ content = <<-'EOF'
79
+ --color
80
+ --format documentation
81
+ EOF
82
+ if File.exist? '.rspec'
83
+ $stderr.puts '!! .rspec already exists'
84
+ else
85
+ File.open('.rspec', 'w') do |f|
86
+ f.puts content
87
+ end
88
+ puts ' + .rspec'
89
+ end
90
+ end
75
91
  end
76
92
  end
@@ -21,8 +21,8 @@ module Awspec::Type
21
21
  end
22
22
 
23
23
  def method_missing(name)
24
- describe = name.to_s
25
- if @instance.key?(describe)
24
+ describe = name.to_sym
25
+ if @instance.members.include?(describe)
26
26
  @instance[describe]
27
27
  else
28
28
  super
@@ -25,8 +25,8 @@ module Awspec::Type
25
25
  end
26
26
 
27
27
  def method_missing(name)
28
- describe = name.to_s
29
- if @instance.key?(describe)
28
+ describe = name.to_sym
29
+ if @instance.members.include?(describe)
30
30
  @instance[describe]
31
31
  else
32
32
  super
@@ -22,7 +22,7 @@ module Awspec::Type
22
22
 
23
23
  def method_missing(name)
24
24
  param_name = name.to_s
25
- if @parameters.key?(param_name)
25
+ if @parameters.include?(param_name)
26
26
  @parameters[param_name].to_s
27
27
  else
28
28
  super
@@ -32,8 +32,8 @@ module Awspec::Type
32
32
  end
33
33
 
34
34
  def method_missing(name)
35
- describe = name.to_s
36
- if @hosted_zone.key?(describe)
35
+ describe = name.to_sym
36
+ if @hosted_zone.members.include?(describe)
37
37
  @hosted_zone[describe]
38
38
  else
39
39
  super
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
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.2.2
4
+ version: 0.2.3
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-06 00:00:00.000000000 Z
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -135,6 +135,7 @@ files:
135
135
  - lib/awspec/generator.rb
136
136
  - lib/awspec/generator/spec/ec2.rb
137
137
  - lib/awspec/generator/spec/rds.rb
138
+ - lib/awspec/generator/spec/route53_hosted_zone.rb
138
139
  - lib/awspec/generator/spec/security_group.rb
139
140
  - lib/awspec/generator/spec/vpc.rb
140
141
  - lib/awspec/helper.rb