awspec 0.25.3 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/awspec.gemspec +1 -0
- data/doc/_resource_types/s3_bucket.md +10 -0
- data/doc/resource_types.md +32 -21
- data/lib/awspec.rb +1 -0
- data/lib/awspec/generator/doc/type/autoscaling_group.rb +1 -1
- data/lib/awspec/generator/doc/type/base.rb +5 -2
- data/lib/awspec/generator/doc/type/cloudwatch_alarm.rb +1 -1
- data/lib/awspec/generator/doc/type/directconnect_virtual_interface.rb +1 -1
- data/lib/awspec/generator/doc/type/ebs.rb +1 -1
- data/lib/awspec/generator/doc/type/ec2.rb +1 -1
- data/lib/awspec/generator/doc/type/elasticache.rb +1 -1
- data/lib/awspec/generator/doc/type/elasticache_cache_parameter_group.rb +1 -1
- data/lib/awspec/generator/doc/type/elb.rb +1 -1
- data/lib/awspec/generator/doc/type/iam_group.rb +1 -1
- data/lib/awspec/generator/doc/type/iam_policy.rb +1 -1
- data/lib/awspec/generator/doc/type/iam_role.rb +1 -1
- data/lib/awspec/generator/doc/type/iam_user.rb +1 -1
- data/lib/awspec/generator/doc/type/lambda.rb +1 -1
- data/lib/awspec/generator/doc/type/network_acl.rb +1 -1
- data/lib/awspec/generator/doc/type/rds.rb +1 -1
- data/lib/awspec/generator/doc/type/route53_hosted_zone.rb +1 -1
- data/lib/awspec/generator/doc/type/route_table.rb +1 -1
- data/lib/awspec/generator/doc/type/s3_bucket.rb +1 -1
- data/lib/awspec/generator/doc/type/security_group.rb +1 -1
- data/lib/awspec/generator/doc/type/ses_identity.rb +1 -1
- data/lib/awspec/generator/doc/type/subnet.rb +1 -1
- data/lib/awspec/generator/doc/type/vpc.rb +1 -1
- data/lib/awspec/generator/template.rb +1 -1
- data/lib/awspec/matcher/be_allowed.rb +2 -2
- data/lib/awspec/matcher/be_allowed_action.rb +2 -2
- data/lib/awspec/matcher/be_denied.rb +2 -2
- data/lib/awspec/matcher/belong_to_cache_subnet_group.rb +2 -2
- data/lib/awspec/matcher/belong_to_db_subnet_group.rb +2 -2
- data/lib/awspec/matcher/belong_to_iam_group.rb +2 -2
- data/lib/awspec/matcher/belong_to_metric.rb +3 -3
- data/lib/awspec/matcher/belong_to_replication_group.rb +2 -2
- data/lib/awspec/matcher/belong_to_subnet.rb +12 -12
- data/lib/awspec/matcher/belong_to_vpc.rb +4 -4
- data/lib/awspec/resource_reader.rb +48 -0
- data/lib/awspec/type/autoscaling_group.rb +4 -4
- data/lib/awspec/type/base.rb +8 -4
- data/lib/awspec/type/cloudwatch_alarm.rb +5 -5
- data/lib/awspec/type/directconnect_virtual_interface.rb +3 -3
- data/lib/awspec/type/ebs.rb +6 -6
- data/lib/awspec/type/ec2.rb +5 -5
- data/lib/awspec/type/elasticache.rb +5 -5
- data/lib/awspec/type/elasticache_cache_parameter_group.rb +1 -1
- data/lib/awspec/type/elb.rb +7 -7
- data/lib/awspec/type/iam_group.rb +3 -3
- data/lib/awspec/type/iam_policy.rb +3 -3
- data/lib/awspec/type/iam_role.rb +3 -3
- data/lib/awspec/type/iam_user.rb +3 -3
- data/lib/awspec/type/lambda.rb +3 -3
- data/lib/awspec/type/network_acl.rb +6 -6
- data/lib/awspec/type/rds.rb +10 -10
- data/lib/awspec/type/rds_db_parameter_group.rb +1 -1
- data/lib/awspec/type/route53_hosted_zone.rb +4 -4
- data/lib/awspec/type/route_table.rb +4 -4
- data/lib/awspec/type/s3_bucket.rb +6 -2
- data/lib/awspec/type/security_group.rb +8 -8
- data/lib/awspec/type/ses_identity.rb +2 -2
- data/lib/awspec/type/subnet.rb +3 -3
- data/lib/awspec/type/vpc.rb +3 -3
- data/lib/awspec/version.rb +1 -1
- metadata +17 -2
@@ -5,7 +5,7 @@ module Awspec::Generator
|
|
5
5
|
def initialize
|
6
6
|
super
|
7
7
|
@type = Awspec::Type::Subnet.new('my-route-table')
|
8
|
-
@ret = @type.
|
8
|
+
@ret = @type.resource_via_client
|
9
9
|
@matchers = [
|
10
10
|
Awspec::Type::Subnet::STATES.map { |state| 'be_' + state.tr('-', '_') }.join(', ')
|
11
11
|
]
|
@@ -60,7 +60,7 @@ module Awspec::Generator
|
|
60
60
|
super
|
61
61
|
@type_name = '#{@type.camelize}'
|
62
62
|
@type = Awspec::Type::#{@type.camelize}.new('my-#{@type.underscore.tr('_', '-')}')
|
63
|
-
@ret = @type.
|
63
|
+
@ret = @type.resource_via_client
|
64
64
|
@matchers = []
|
65
65
|
@ignore_matchers = []
|
66
66
|
@describes = []
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :be_allowed_action do |action_name|
|
2
|
-
match do |
|
3
|
-
results =
|
2
|
+
match do |type|
|
3
|
+
results = type.select_policy_evaluation_results(type.resource_via_client[:arn], action_name, @resource_arn)
|
4
4
|
results.find do |result|
|
5
5
|
result.eval_decision == 'allowed'
|
6
6
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
RSpec::Matchers.define :belong_to_cache_subnet_group do |cache_subnet_group_name|
|
2
|
-
match do |
|
3
|
-
return true if
|
2
|
+
match do |type|
|
3
|
+
return true if type.resource_via_client[:cache_subnet_group_name] == cache_subnet_group_name
|
4
4
|
end
|
5
5
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
RSpec::Matchers.define :belong_to_db_subnet_group do |db_subnet_group_name|
|
2
|
-
match do |
|
3
|
-
return true if
|
2
|
+
match do |type|
|
3
|
+
return true if type.resource_via_client[:db_subnet_group][:db_subnet_group_name] == db_subnet_group_name
|
4
4
|
end
|
5
5
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :belong_to_iam_group do |group_id|
|
2
|
-
match do |
|
3
|
-
groups =
|
2
|
+
match do |type|
|
3
|
+
groups = type.select_iam_group_by_user_name(type.resource_via_client[:user_name])
|
4
4
|
groups.find do |group|
|
5
5
|
group.group_id == group_id || group.group_name == group_id
|
6
6
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
RSpec::Matchers.define :belong_to_metric do |name|
|
2
|
-
match do |
|
2
|
+
match do |type|
|
3
3
|
if @namespace
|
4
|
-
|
4
|
+
type.namespace == @namespace && type.metric_name == name
|
5
5
|
else
|
6
|
-
|
6
|
+
type.metric_name == name
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -1,31 +1,31 @@
|
|
1
1
|
RSpec::Matchers.define :belong_to_subnet do |subnet_id|
|
2
|
-
match do |
|
2
|
+
match do |type|
|
3
3
|
# EC2
|
4
|
-
if
|
5
|
-
return true if
|
6
|
-
subnet =
|
4
|
+
if type.instance_of?(Awspec::Type::Ec2)
|
5
|
+
return true if type.subnet_id == subnet_id
|
6
|
+
subnet = type.find_subnet(subnet_id)
|
7
7
|
return false unless subnet
|
8
|
-
return subnet[:subnet_id] ==
|
8
|
+
return subnet[:subnet_id] == type.subnet_id
|
9
9
|
end
|
10
10
|
|
11
11
|
# RDS
|
12
|
-
if
|
13
|
-
subnets =
|
12
|
+
if type.instance_of?(Awspec::Type::Rds)
|
13
|
+
subnets = type.resource_via_client[:db_subnet_group][:subnets]
|
14
14
|
ret = subnets.find do |s|
|
15
15
|
s[:subnet_identifier] == subnet_id
|
16
16
|
end
|
17
17
|
|
18
|
-
return ret[:subnet_availability_zone][:name] ==
|
18
|
+
return ret[:subnet_availability_zone][:name] == type.availability_zone if ret
|
19
19
|
|
20
|
-
res =
|
21
|
-
|
22
|
-
|
20
|
+
res = type.ec2_client.describe_subnets({
|
21
|
+
filters: [{ name: 'tag:Name', values: [subnet_id] }]
|
22
|
+
})
|
23
23
|
return false unless res
|
24
24
|
ret = subnets.find do |s|
|
25
25
|
s[:subnet_identifier] == res[:subnets][0][:subnet_id]
|
26
26
|
end
|
27
27
|
|
28
|
-
return ret[:subnet_availability_zone][:name] ==
|
28
|
+
return ret[:subnet_availability_zone][:name] == type.availability_zone if ret
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
RSpec::Matchers.define :belong_to_vpc do |vpc_id|
|
2
|
-
match do |
|
3
|
-
return true if
|
4
|
-
ret =
|
2
|
+
match do |type|
|
3
|
+
return true if type.vpc_id == vpc_id
|
4
|
+
ret = type.find_vpc(vpc_id)
|
5
5
|
return false unless ret
|
6
|
-
ret[:vpc_id] ==
|
6
|
+
ret[:vpc_id] == type.vpc_id
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Awspec
|
2
|
+
module BlackListForwardable
|
3
|
+
class CalledMethodInBlackList < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
def method_missing_via_black_list(name, delegate_to: nil)
|
7
|
+
fail(ArguementError, 'delegate_to: must be specified') unless delegate_to
|
8
|
+
if match_black_list?(name)
|
9
|
+
fail CalledMethodInBlackList, "Method call #{name.inspect} is black-listed"
|
10
|
+
else
|
11
|
+
attr = delegate_to.send(name)
|
12
|
+
case attr
|
13
|
+
when Aws::Resources::Resource
|
14
|
+
ResourceReader.new(attr)
|
15
|
+
else
|
16
|
+
attr
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
BLACK_LIST_RE = /
|
24
|
+
create|
|
25
|
+
delete|
|
26
|
+
clear|
|
27
|
+
put|
|
28
|
+
update|
|
29
|
+
add
|
30
|
+
/ix
|
31
|
+
|
32
|
+
def match_black_list?(name)
|
33
|
+
BLACK_LIST_RE =~ name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class ResourceReader
|
38
|
+
include BlackListForwardable
|
39
|
+
|
40
|
+
def initialize(resource)
|
41
|
+
@resource_via_client = resource
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(name)
|
45
|
+
method_missing_via_black_list(name, delegate_to: @resource_via_client)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -2,19 +2,19 @@ module Awspec::Type
|
|
2
2
|
class AutoscalingGroup < Base
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
|
-
@
|
6
|
-
@id = @
|
5
|
+
@resource_via_client = find_autoscaling_group(id)
|
6
|
+
@id = @resource_via_client[:auto_scaling_group_arn] if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_elb?(name)
|
10
|
-
@
|
10
|
+
@resource_via_client.load_balancer_names.find do |lb_name|
|
11
11
|
lb_name == name
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def has_ec2?(id)
|
16
16
|
ec2 = find_ec2(id)
|
17
|
-
@
|
17
|
+
@resource_via_client.instances.find do |instance|
|
18
18
|
instance.instance_id = ec2.instance_id
|
19
19
|
end if ec2
|
20
20
|
end
|
data/lib/awspec/type/base.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'aws-sdk'
|
2
|
+
require 'awspec/resource_reader'
|
2
3
|
require 'awspec/helper/finder'
|
3
4
|
|
4
5
|
module Awspec::Type
|
5
6
|
class Base
|
6
7
|
include Awspec::Helper::Finder
|
7
|
-
|
8
|
+
include Awspec::BlackListForwardable
|
9
|
+
|
10
|
+
attr_reader :id, :resource_via_client
|
8
11
|
|
9
12
|
def initialize(id = nil)
|
10
13
|
@display_name = id
|
@@ -27,10 +30,11 @@ module Awspec::Type
|
|
27
30
|
|
28
31
|
def method_missing(name)
|
29
32
|
describe = name.to_sym
|
30
|
-
if @
|
31
|
-
@
|
33
|
+
if @resource_via_client.members.include?(describe)
|
34
|
+
@resource_via_client[describe]
|
32
35
|
else
|
33
|
-
super
|
36
|
+
super unless self.respond_to?(:hogehoge)
|
37
|
+
method_missing_via_black_list(name, delegate_to: hogehoge)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
@@ -2,20 +2,20 @@ module Awspec::Type
|
|
2
2
|
class CloudwatchAlarm < Base
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
|
-
@
|
6
|
-
@id = @
|
5
|
+
@resource_via_client = find_cloudwatch_alarm(id)
|
6
|
+
@id = @resource_via_client[:alarm_arn] if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_ok_action?(name)
|
10
|
-
@
|
10
|
+
@resource_via_client[:ok_actions].include?(name)
|
11
11
|
end
|
12
12
|
|
13
13
|
def has_alarm_action?(name)
|
14
|
-
@
|
14
|
+
@resource_via_client[:alarm_actions].include?(name)
|
15
15
|
end
|
16
16
|
|
17
17
|
def has_insufficient_data_action?(name)
|
18
|
-
@
|
18
|
+
@resource_via_client[:insufficient_data_actions].include?(name)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -2,8 +2,8 @@ module Awspec::Type
|
|
2
2
|
class DirectconnectVirtualInterface < Base
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
|
-
@
|
6
|
-
@id = @
|
5
|
+
@resource_via_client = find_virtual_interface(id)
|
6
|
+
@id = @resource_via_client[:virtual_interface_id] if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
STATES = %w(
|
@@ -13,7 +13,7 @@ module Awspec::Type
|
|
13
13
|
|
14
14
|
STATES.each do |state|
|
15
15
|
define_method state + '?' do
|
16
|
-
@
|
16
|
+
@resource_via_client[:virtual_interface_state] == state
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/awspec/type/ebs.rb
CHANGED
@@ -2,8 +2,8 @@ module Awspec::Type
|
|
2
2
|
class Ebs < Base
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
|
-
@
|
6
|
-
@id = @
|
5
|
+
@resource_via_client = find_ebs(id)
|
6
|
+
@id = @resource_via_client[:volume_id] if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
STATES = %w(
|
@@ -12,16 +12,16 @@ module Awspec::Type
|
|
12
12
|
|
13
13
|
STATES.each do |state|
|
14
14
|
define_method state.tr('-', '_') + '?' do
|
15
|
-
@
|
15
|
+
@resource_via_client[:state] == state
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def attached_to?(instance_id)
|
20
20
|
instance = find_ec2(instance_id)
|
21
21
|
return false unless instance
|
22
|
-
return false unless @
|
23
|
-
@
|
24
|
-
@
|
22
|
+
return false unless @resource_via_client[:attachments]
|
23
|
+
@resource_via_client[:attachments][0][:instance_id] == instance[:instance_id] && \
|
24
|
+
@resource_via_client[:attachments][0][:state] == 'attached'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/awspec/type/ec2.rb
CHANGED
@@ -5,8 +5,8 @@ module Awspec::Type
|
|
5
5
|
def initialize(id)
|
6
6
|
super
|
7
7
|
@client = @ec2_client
|
8
|
-
@
|
9
|
-
@id = @
|
8
|
+
@resource_via_client = find_ec2(id)
|
9
|
+
@id = @resource_via_client[:instance_id] if @resource_via_client
|
10
10
|
end
|
11
11
|
|
12
12
|
STATES = %w(
|
@@ -16,7 +16,7 @@ module Awspec::Type
|
|
16
16
|
|
17
17
|
STATES.each do |state|
|
18
18
|
define_method state.tr('-', '_') + '?' do
|
19
|
-
@
|
19
|
+
@resource_via_client[:state][:name] == state
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -36,7 +36,7 @@ module Awspec::Type
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def has_security_group?(sg_id)
|
39
|
-
sgs = @
|
39
|
+
sgs = @resource_via_client[:security_groups]
|
40
40
|
ret = sgs.find do |sg|
|
41
41
|
sg[:group_id] == sg_id || sg[:group_name] == sg_id
|
42
42
|
end
|
@@ -49,7 +49,7 @@ module Awspec::Type
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def has_ebs?(volume_id)
|
52
|
-
blocks = @
|
52
|
+
blocks = @resource_via_client[:block_device_mappings]
|
53
53
|
ret = blocks.find do |block|
|
54
54
|
next false unless block[:ebs]
|
55
55
|
block[:ebs][:volume_id] == volume_id
|
@@ -2,8 +2,8 @@ module Awspec::Type
|
|
2
2
|
class Elasticache < Base
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
|
-
@
|
6
|
-
@id = @
|
5
|
+
@resource_via_client = find_cache_cluster(id)
|
6
|
+
@id = @resource_via_client[:cache_cluster_id] if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
STATES = %w(
|
@@ -15,16 +15,16 @@ module Awspec::Type
|
|
15
15
|
|
16
16
|
STATES.each do |state|
|
17
17
|
define_method state.tr('-', '_') + '?' do
|
18
|
-
@
|
18
|
+
@resource_via_client[:cache_cluster_status] == state
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def has_cache_parameter_group?(group_name)
|
23
|
-
@
|
23
|
+
@resource_via_client[:cache_parameter_group][:cache_parameter_group_name] == group_name
|
24
24
|
end
|
25
25
|
|
26
26
|
def vpc_id
|
27
|
-
cache_subnet_group = find_cache_subnet_group(@
|
27
|
+
cache_subnet_group = find_cache_subnet_group(@resource_via_client[:cache_subnet_group_name])
|
28
28
|
cache_subnet_group[:vpc_id] if cache_subnet_group
|
29
29
|
end
|
30
30
|
end
|
data/lib/awspec/type/elb.rb
CHANGED
@@ -2,8 +2,8 @@ module Awspec::Type
|
|
2
2
|
class Elb < Base
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
|
-
@
|
6
|
-
@id = @
|
5
|
+
@resource_via_client = find_elb(id)
|
6
|
+
@id = @resource_via_client[:load_balancer_name] if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
health_check_options = %w(
|
@@ -13,19 +13,19 @@ module Awspec::Type
|
|
13
13
|
|
14
14
|
health_check_options.each do |option|
|
15
15
|
define_method 'health_check_' + option do
|
16
|
-
@
|
16
|
+
@resource_via_client[:health_check][option]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def has_ec2?(id)
|
21
21
|
ec2 = find_ec2(id)
|
22
|
-
@
|
22
|
+
@resource_via_client.instances.find do |instance|
|
23
23
|
instance.instance_id = ec2.instance_id
|
24
24
|
end if ec2
|
25
25
|
end
|
26
26
|
|
27
27
|
def has_security_group?(sg_id)
|
28
|
-
sgs = @
|
28
|
+
sgs = @resource_via_client[:security_groups]
|
29
29
|
ret = sgs.find do |sg|
|
30
30
|
sg == sg_id
|
31
31
|
end
|
@@ -38,7 +38,7 @@ module Awspec::Type
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def has_subnet?(subnet_id)
|
41
|
-
subnets = @
|
41
|
+
subnets = @resource_via_client[:subnets]
|
42
42
|
ret = subnets.find do |s|
|
43
43
|
s == subnet_id
|
44
44
|
end
|
@@ -50,7 +50,7 @@ module Awspec::Type
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def has_listener?(protocol:, port:, instance_protocol:, instance_port:)
|
53
|
-
@
|
53
|
+
@resource_via_client[:listener_descriptions].find do |desc|
|
54
54
|
listener = desc.listener
|
55
55
|
listener.protocol == protocol && listener.load_balancer_port == port && \
|
56
56
|
listener.instance_protocol == instance_protocol && listener.instance_port == instance_port
|