awspec 0.33.0 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -1
- data/lib/awspec.rb +1 -0
- data/lib/awspec/command/generate.rb +3 -4
- data/lib/awspec/error.rb +4 -0
- data/lib/awspec/ext.rb +1 -0
- data/lib/awspec/ext/array.rb +8 -0
- data/lib/awspec/generator.rb +1 -0
- data/lib/awspec/generator/spec/lambda.rb +29 -0
- data/lib/awspec/helper/finder.rb +2 -0
- data/lib/awspec/helper/finder/ami.rb +5 -3
- data/lib/awspec/helper/finder/autoscaling.rb +2 -2
- data/lib/awspec/helper/finder/cloudwatch.rb +4 -3
- data/lib/awspec/helper/finder/directconnect.rb +1 -1
- data/lib/awspec/helper/finder/ebs.rb +4 -3
- data/lib/awspec/helper/finder/ec2.rb +15 -51
- data/lib/awspec/helper/finder/elasticache.rb +2 -2
- data/lib/awspec/helper/finder/elb.rb +2 -2
- data/lib/awspec/helper/finder/iam.rb +1 -1
- data/lib/awspec/helper/finder/lambda.rb +8 -2
- data/lib/awspec/helper/finder/rds.rb +2 -2
- data/lib/awspec/helper/finder/route53.rb +3 -1
- data/lib/awspec/helper/finder/security_group.rb +10 -11
- data/lib/awspec/helper/finder/ses.rb +2 -2
- data/lib/awspec/helper/finder/subnet.rb +24 -0
- data/lib/awspec/helper/finder/vpc.rb +14 -28
- data/lib/awspec/helper/type.rb +8 -10
- data/lib/awspec/matcher/have_route.rb +1 -1
- data/lib/awspec/stub/duplicated_resource_type.rb +26 -0
- data/lib/awspec/stub/lambda.rb +5 -2
- data/lib/awspec/type/ami.rb +2 -2
- data/lib/awspec/type/autoscaling_group.rb +1 -1
- data/lib/awspec/type/base.rb +1 -1
- data/lib/awspec/type/cloudwatch_alarm.rb +4 -4
- data/lib/awspec/type/directconnect_virtual_interface.rb +2 -2
- data/lib/awspec/type/ebs.rb +5 -5
- data/lib/awspec/type/ec2.rb +12 -12
- data/lib/awspec/type/elasticache.rb +5 -5
- data/lib/awspec/type/elb.rb +8 -8
- data/lib/awspec/type/iam_group.rb +3 -3
- data/lib/awspec/type/iam_policy.rb +4 -4
- data/lib/awspec/type/iam_role.rb +2 -2
- data/lib/awspec/type/iam_user.rb +2 -2
- data/lib/awspec/type/lambda.rb +2 -2
- data/lib/awspec/type/launch_configuration.rb +3 -3
- data/lib/awspec/type/nat_gateway.rb +2 -2
- data/lib/awspec/type/network_acl.rb +5 -5
- data/lib/awspec/type/rds.rb +17 -17
- data/lib/awspec/type/route53_hosted_zone.rb +2 -2
- data/lib/awspec/type/route_table.rb +2 -2
- data/lib/awspec/type/security_group.rb +39 -39
- data/lib/awspec/type/ses_identity.rb +5 -5
- data/lib/awspec/type/subnet.rb +2 -2
- data/lib/awspec/type/vpc.rb +4 -4
- data/lib/awspec/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1909c7febd232e63f4f01933058887c972a174e
|
4
|
+
data.tar.gz: cb3d860018b22a635823a714d05b86ae23db32b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f71aa2801687ba6a5d85329fd7613e4d64ac27477daa109df26fd604b18def3103129f5f2576188665a0db7dfba1dc6412e905b58b3fd33deb89e233474959e
|
7
|
+
data.tar.gz: d16c5744e51f88335da74c058c90b4fb6f55563f3766d5b27d6b1ec8f6138222875f496336dea431a53d10facca6f91b8b790a1298061a8f5120370174c2e100
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
if defined?(RSpec)
|
16
16
|
task spec: 'spec:all'
|
17
17
|
namespace :spec do
|
18
|
-
task all: ['spec:type', 'spec:generator_spec', 'spec:generator_doc']
|
18
|
+
task all: ['spec:type', 'spec:core', 'spec:generator_spec', 'spec:generator_doc']
|
19
19
|
|
20
20
|
task type: types
|
21
21
|
|
@@ -25,6 +25,10 @@ if defined?(RSpec)
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
RSpec::Core::RakeTask.new(:core) do |t|
|
29
|
+
t.pattern = 'spec/core/*_spec.rb'
|
30
|
+
end
|
31
|
+
|
28
32
|
RSpec::Core::RakeTask.new(:generator_spec) do |t|
|
29
33
|
t.pattern = 'spec/generator/spec/*_spec.rb'
|
30
34
|
end
|
data/lib/awspec.rb
CHANGED
@@ -11,10 +11,9 @@ module Awspec
|
|
11
11
|
|
12
12
|
types.each do |type|
|
13
13
|
desc type + ' [vpc_id]', "Generate #{type} spec from VPC ID (or VPC \"Name\" tag)"
|
14
|
-
define_method type do
|
14
|
+
define_method type do |_vpc_id|
|
15
15
|
Awsecrets.load(profile: options[:profile])
|
16
|
-
|
17
|
-
eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_by_vpc_id(vpc_id)"
|
16
|
+
eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_by_vpc_id(_vpc_id)"
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -35,7 +34,7 @@ module Awspec
|
|
35
34
|
end
|
36
35
|
|
37
36
|
types_for_generate_all = %w(
|
38
|
-
iam_policy cloudwatch_alarm directconnect ebs
|
37
|
+
iam_policy cloudwatch_alarm directconnect ebs lambda
|
39
38
|
)
|
40
39
|
|
41
40
|
types_for_generate_all.each do |type|
|
data/lib/awspec/error.rb
ADDED
data/lib/awspec/ext.rb
CHANGED
data/lib/awspec/generator.rb
CHANGED
@@ -14,6 +14,7 @@ require 'awspec/generator/spec/directconnect'
|
|
14
14
|
require 'awspec/generator/spec/ebs'
|
15
15
|
require 'awspec/generator/spec/s3_bucket'
|
16
16
|
require 'awspec/generator/spec/nat_gateway'
|
17
|
+
require 'awspec/generator/spec/lambda'
|
17
18
|
|
18
19
|
# Doc
|
19
20
|
require 'awspec/generator/doc/type'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Spec
|
3
|
+
class Lambda
|
4
|
+
include Awspec::Helper::Finder
|
5
|
+
def generate_all
|
6
|
+
lambda_functions = select_all_lambda_functions
|
7
|
+
raise 'Not Found lambda' if lambda_functions.empty?
|
8
|
+
ERB.new(lambda_spec_template, nil, '-').result(binding).chomp
|
9
|
+
end
|
10
|
+
|
11
|
+
def lambda_spec_template
|
12
|
+
template = <<-'EOF'
|
13
|
+
<% lambda_functions.each do |function| %>
|
14
|
+
describe lambda('<%= function.function_name %>') do
|
15
|
+
it { should exist }
|
16
|
+
its(:description) { should eq '<%= function.description %>' }
|
17
|
+
its(:runtime) { should eq '<%= function.runtime %>' }
|
18
|
+
its(:handler) { should eq '<%= function.handler %>' }
|
19
|
+
its(:code_size) { should eq <%= function.code_size %> }
|
20
|
+
its(:timeout) { should eq <%= function.timeout %> }
|
21
|
+
its(:memory_size) { should eq <%= function.memory_size %> }
|
22
|
+
end
|
23
|
+
<% end %>
|
24
|
+
EOF
|
25
|
+
template
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/awspec/helper/finder.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'aws-sdk'
|
2
2
|
require 'awspec/helper/finder/vpc'
|
3
|
+
require 'awspec/helper/finder/subnet'
|
3
4
|
require 'awspec/helper/finder/ec2'
|
4
5
|
require 'awspec/helper/finder/security_group'
|
5
6
|
require 'awspec/helper/finder/rds'
|
@@ -19,6 +20,7 @@ require 'awspec/helper/finder/ami'
|
|
19
20
|
module Awspec::Helper
|
20
21
|
module Finder
|
21
22
|
include Awspec::Helper::Finder::Vpc
|
23
|
+
include Awspec::Helper::Finder::Subnet
|
22
24
|
include Awspec::Helper::Finder::Ec2
|
23
25
|
include Awspec::Helper::Finder::SecurityGroup
|
24
26
|
include Awspec::Helper::Finder::Rds
|
@@ -5,15 +5,17 @@ module Awspec::Helper
|
|
5
5
|
res = ec2_client.describe_images({
|
6
6
|
filters: [{ name: 'image-id', values: [image_id] }]
|
7
7
|
})
|
8
|
-
|
8
|
+
resource = res.images.single_resource(image_id)
|
9
|
+
return resource if resource
|
9
10
|
res = ec2_client.describe_images({
|
10
11
|
filters: [{ name: 'name', values: [image_id] }]
|
11
12
|
})
|
12
|
-
|
13
|
+
resource = res.images.single_resource(image_id)
|
14
|
+
return resource if resource
|
13
15
|
res = ec2_client.describe_images({
|
14
16
|
filters: [{ name: 'tag:Name', values: [image_id] }]
|
15
17
|
})
|
16
|
-
|
18
|
+
res.images.single_resource(image_id)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -5,14 +5,14 @@ module Awspec::Helper
|
|
5
5
|
res = autoscaling_client.describe_auto_scaling_groups({
|
6
6
|
auto_scaling_group_names: [id]
|
7
7
|
})
|
8
|
-
res
|
8
|
+
res.auto_scaling_groups.single_resource(id)
|
9
9
|
end
|
10
10
|
|
11
11
|
def find_launch_configuration(id)
|
12
12
|
res = autoscaling_client.describe_launch_configurations({
|
13
13
|
launch_configuration_names: [id]
|
14
14
|
})
|
15
|
-
res
|
15
|
+
res.launch_configurations.single_resource(id)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -5,12 +5,13 @@ module Awspec::Helper
|
|
5
5
|
res = cloudwatch_client.describe_alarms({
|
6
6
|
alarm_names: [id]
|
7
7
|
})
|
8
|
-
return res
|
8
|
+
return res.metric_alarms.first if res.metric_alarms.count == 1
|
9
9
|
|
10
10
|
res = cloudwatch_client.describe_alarms
|
11
|
-
res
|
12
|
-
alarm
|
11
|
+
alarms = res.metric_alarms.select do |alarm|
|
12
|
+
alarm.alarm_arn == id
|
13
13
|
end
|
14
|
+
alarms.single_resource(id)
|
14
15
|
end
|
15
16
|
|
16
17
|
def select_all_cloudwatch_alarms
|
@@ -7,7 +7,7 @@ module Awspec::Helper
|
|
7
7
|
next true if virtual_interface.virtual_interface_id == virtual_interface_id
|
8
8
|
next true if virtual_interface.virtual_interface_name == virtual_interface_id
|
9
9
|
end
|
10
|
-
|
10
|
+
ret.single_resource(virtual_interface_id)
|
11
11
|
end
|
12
12
|
|
13
13
|
def select_virtual_interfaces
|
@@ -5,18 +5,19 @@ module Awspec::Helper
|
|
5
5
|
res = ec2_client.describe_volumes({
|
6
6
|
filters: [{ name: 'volume-id', values: [volume_id] }]
|
7
7
|
})
|
8
|
-
|
8
|
+
resource = res.volumes.single_resource(volume_id)
|
9
|
+
return resource if resource
|
9
10
|
res = ec2_client.describe_volumes({
|
10
11
|
filters: [{ name: 'tag:Name', values: [volume_id] }]
|
11
12
|
})
|
12
|
-
|
13
|
+
res.volumes.single_resource(volume_id)
|
13
14
|
end
|
14
15
|
|
15
16
|
def select_ebs_by_instance_id(id)
|
16
17
|
res = find_ec2(id)
|
17
18
|
volumes = []
|
18
19
|
return volumes unless res
|
19
|
-
res
|
20
|
+
res.block_device_mappings.each do |block|
|
20
21
|
volume = find_ebs(block.ebs.volume_id)
|
21
22
|
volumes.push(volume) if volume
|
22
23
|
end
|
@@ -2,39 +2,20 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Ec2
|
4
4
|
def find_ec2(id)
|
5
|
-
|
6
|
-
|
5
|
+
# instance_id or tag:Name
|
6
|
+
begin
|
7
7
|
res = ec2_client.describe_instances({
|
8
|
-
|
8
|
+
instance_ids: [id]
|
9
9
|
})
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
id.each do |k, v|
|
14
|
-
filters.push({ name: k, values: Array(v) })
|
15
|
-
end
|
10
|
+
rescue
|
11
|
+
# Aws::EC2::Errors::InvalidInstanceIDMalformed
|
12
|
+
# Aws::EC2::Errors::InvalidInstanceIDNotFound
|
16
13
|
res = ec2_client.describe_instances({
|
17
|
-
filters:
|
14
|
+
filters: [{ name: 'tag:Name', values: [id] }]
|
18
15
|
})
|
19
|
-
elsif id.is_a?(String)
|
20
|
-
# instance_id or tag:Name
|
21
|
-
begin
|
22
|
-
res = ec2_client.describe_instances({
|
23
|
-
instance_ids: [id]
|
24
|
-
})
|
25
|
-
rescue
|
26
|
-
# Aws::EC2::Errors::InvalidInstanceIDMalformed
|
27
|
-
# Aws::EC2::Errors::InvalidInstanceIDNotFound
|
28
|
-
res = ec2_client.describe_instances({
|
29
|
-
filters: [{ name: 'tag:Name', values: [id] }]
|
30
|
-
})
|
31
|
-
end
|
32
|
-
else
|
33
|
-
return nil
|
34
16
|
end
|
35
17
|
# rubocop:enable Style/GuardClause
|
36
|
-
|
37
|
-
res[:reservations].first[:instances].count == 1
|
18
|
+
res.reservations.first.instances.single_resource(id) if res.reservations.count == 1
|
38
19
|
end
|
39
20
|
|
40
21
|
def find_ec2_attribute(id, attribute)
|
@@ -52,12 +33,12 @@ module Awspec::Helper
|
|
52
33
|
res = ec2_client.method(method_name).call({
|
53
34
|
filters: [{ name: type + '-gateway-id', values: [gateway_id] }]
|
54
35
|
})
|
55
|
-
|
56
|
-
return
|
36
|
+
resource = res[type + '_gateways'].single_resource(gateway_id)
|
37
|
+
return resource if resource
|
57
38
|
res = ec2_client.method(method_name).call({
|
58
39
|
filters: [{ name: 'tag:Name', values: [gateway_id] }]
|
59
40
|
})
|
60
|
-
|
41
|
+
res[type + '_gateways'].single_resource(gateway_id)
|
61
42
|
end
|
62
43
|
end
|
63
44
|
|
@@ -65,22 +46,7 @@ module Awspec::Helper
|
|
65
46
|
res = ec2_client.describe_nat_gateways({
|
66
47
|
filter: [{ name: 'nat-gateway-id', values: [gateway_id] }]
|
67
48
|
})
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def find_security_group(sg_id)
|
72
|
-
res = ec2_client.describe_security_groups({
|
73
|
-
filters: [{ name: 'group-id', values: [sg_id] }]
|
74
|
-
})
|
75
|
-
return res[:security_groups].first if res[:security_groups].count == 1
|
76
|
-
res = ec2_client.describe_security_groups({
|
77
|
-
filters: [{ name: 'group-name', values: [sg_id] }]
|
78
|
-
})
|
79
|
-
return res[:security_groups].first if res[:security_groups].count == 1
|
80
|
-
res = ec2_client.describe_security_groups({
|
81
|
-
filters: [{ name: 'tag:Name', values: [sg_id] }]
|
82
|
-
})
|
83
|
-
return res[:security_groups].first if res[:security_groups].count == 1
|
49
|
+
res.nat_gateways.single_resource(gateway_id)
|
84
50
|
end
|
85
51
|
|
86
52
|
def select_ec2_by_vpc_id(vpc_id)
|
@@ -88,8 +54,7 @@ module Awspec::Helper
|
|
88
54
|
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
89
55
|
})
|
90
56
|
instances = []
|
91
|
-
|
92
|
-
res[:reservations].each do |reservation|
|
57
|
+
res.reservations.each do |reservation|
|
93
58
|
reservation.instances.each do |instance|
|
94
59
|
instances.push(instance)
|
95
60
|
end
|
@@ -101,15 +66,14 @@ module Awspec::Helper
|
|
101
66
|
res = ec2_client.describe_addresses({
|
102
67
|
filters: [{ name: 'instance-id', values: [id] }]
|
103
68
|
})
|
104
|
-
|
105
|
-
res[:addresses]
|
69
|
+
res.addresses
|
106
70
|
end
|
107
71
|
|
108
72
|
def select_nat_gateway_by_vpc_id(vpc_id)
|
109
73
|
res = ec2_client.describe_nat_gateways({
|
110
74
|
filter: [{ name: 'vpc-id', values: [vpc_id] }]
|
111
75
|
})
|
112
|
-
res
|
76
|
+
res.nat_gateways
|
113
77
|
end
|
114
78
|
end
|
115
79
|
end
|
@@ -5,7 +5,7 @@ module Awspec::Helper
|
|
5
5
|
res = elasticache_client.describe_cache_clusters({
|
6
6
|
cache_cluster_id: id
|
7
7
|
})
|
8
|
-
res
|
8
|
+
res.cache_clusters.single_resource(id)
|
9
9
|
rescue
|
10
10
|
nil
|
11
11
|
end
|
@@ -14,7 +14,7 @@ module Awspec::Helper
|
|
14
14
|
res = elasticache_client.describe_cache_subnet_groups({
|
15
15
|
cache_subnet_group_name: group_name
|
16
16
|
})
|
17
|
-
res
|
17
|
+
res.cache_subnet_groups.single_resource(group_name)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -5,14 +5,14 @@ module Awspec::Helper
|
|
5
5
|
res = elb_client.describe_load_balancers({
|
6
6
|
load_balancer_names: [id]
|
7
7
|
})
|
8
|
-
|
8
|
+
res.load_balancer_descriptions.single_resource(id)
|
9
9
|
rescue
|
10
10
|
return nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def select_elb_by_vpc_id(vpc_id)
|
14
14
|
res = elb_client.describe_load_balancers
|
15
|
-
res
|
15
|
+
res.load_balancer_descriptions.select do |lb|
|
16
16
|
lb.vpc_id == vpc_id
|
17
17
|
end
|
18
18
|
end
|
@@ -12,14 +12,20 @@ module Awspec::Helper
|
|
12
12
|
(res.next_page? && res = res.next_page) || break
|
13
13
|
end
|
14
14
|
|
15
|
-
selected.
|
15
|
+
selected.single_resource(id)
|
16
16
|
end
|
17
17
|
|
18
18
|
def select_event_source_by_function_arn(function_arn)
|
19
19
|
res = lambda_client.list_event_source_mappings({
|
20
20
|
function_name: function_arn
|
21
21
|
})
|
22
|
-
res
|
22
|
+
res.event_source_mappings
|
23
|
+
end
|
24
|
+
|
25
|
+
def select_all_lambda_functions
|
26
|
+
res = lambda_client.list_functions.map do |responce|
|
27
|
+
responce.functions
|
28
|
+
end.flatten
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -6,12 +6,12 @@ module Awspec::Helper
|
|
6
6
|
res = rds_client.describe_db_instances({
|
7
7
|
db_instance_identifier: id
|
8
8
|
})
|
9
|
-
|
9
|
+
res.db_instances.single_resource(id)
|
10
10
|
end
|
11
11
|
|
12
12
|
def select_rds_by_vpc_id(vpc_id)
|
13
13
|
res = rds_client.describe_db_instances
|
14
|
-
res
|
14
|
+
res.db_instances.select do |db_instance|
|
15
15
|
db_instance.db_subnet_group.vpc_id == vpc_id
|
16
16
|
end
|
17
17
|
end
|
@@ -3,14 +3,16 @@ module Awspec::Helper
|
|
3
3
|
module Route53
|
4
4
|
def find_hosted_zone(id)
|
5
5
|
res = route53_client.list_hosted_zones
|
6
|
+
selected = []
|
6
7
|
loop do
|
7
8
|
res.hosted_zones.each do |hosted_zone|
|
8
9
|
if hosted_zone[:name] == id || hosted_zone[:id] == '/hostedzone/' + id || hosted_zone[:id] == id
|
9
|
-
|
10
|
+
selected.push(hosted_zone)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
(res.next_page? && res = res.next_page) || break
|
13
14
|
end
|
15
|
+
selected.single_resource(id)
|
14
16
|
end
|
15
17
|
|
16
18
|
def select_record_sets_by_hosted_zone_id(id)
|