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 +4 -4
- data/lib/awspec/command/generate.rb +8 -2
- data/lib/awspec/generator.rb +1 -0
- data/lib/awspec/generator/spec/ec2.rb +7 -4
- data/lib/awspec/generator/spec/rds.rb +2 -2
- data/lib/awspec/generator/spec/route53_hosted_zone.rb +54 -0
- data/lib/awspec/generator/spec/security_group.rb +1 -1
- data/lib/awspec/generator/spec/vpc.rb +1 -1
- data/lib/awspec/setup.rb +17 -1
- data/lib/awspec/type/ec2.rb +2 -2
- data/lib/awspec/type/rds.rb +2 -2
- data/lib/awspec/type/rds_db_parameter_group.rb +1 -1
- data/lib/awspec/type/route53_hosted_zone.rb +2 -2
- data/lib/awspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 757db940be85a0bf4a58b7b685b9872846a4415d
|
4
|
+
data.tar.gz: 7024a655265da3c039ae75b8d28059e365341e7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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]',
|
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.
|
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')
|
data/lib/awspec/generator.rb
CHANGED
@@ -2,7 +2,7 @@ module Awspec::Generator
|
|
2
2
|
module Spec
|
3
3
|
class Ec2
|
4
4
|
include Awspec::Helper::Finder
|
5
|
-
def
|
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.
|
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
|
-
|
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
|
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.
|
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
|
data/lib/awspec/setup.rb
CHANGED
@@ -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
|
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
|
data/lib/awspec/type/ec2.rb
CHANGED
data/lib/awspec/type/rds.rb
CHANGED
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.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-
|
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
|