awspec 0.26.2 → 0.27.0
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 +4 -4
- data/Rakefile +13 -2
- data/doc/_resource_types/ebs.md +18 -0
- data/doc/_resource_types/ec2.md +18 -0
- data/doc/_resource_types/network_acl.md +18 -0
- data/doc/_resource_types/rds.md +18 -0
- data/doc/_resource_types/route_table.md +18 -0
- data/doc/_resource_types/security_group.md +18 -0
- data/doc/_resource_types/subnet.md +18 -0
- data/doc/_resource_types/vpc.md +18 -0
- data/doc/resource_types.md +152 -0
- data/lib/awspec/helper/finder.rb +19 -15
- data/lib/awspec/helper/finder/autoscaling.rb +3 -3
- data/lib/awspec/helper/finder/cloudwatch.rb +5 -5
- data/lib/awspec/helper/finder/directconnect.rb +2 -2
- data/lib/awspec/helper/finder/ebs.rb +7 -7
- data/lib/awspec/helper/finder/ec2.rb +46 -46
- data/lib/awspec/helper/finder/elasticache.rb +6 -6
- data/lib/awspec/helper/finder/elb.rb +4 -4
- data/lib/awspec/helper/finder/iam.rb +16 -16
- data/lib/awspec/helper/finder/lambda.rb +4 -4
- data/lib/awspec/helper/finder/rds.rb +4 -4
- data/lib/awspec/helper/finder/route53.rb +4 -4
- data/lib/awspec/helper/finder/s3.rb +6 -6
- data/lib/awspec/helper/finder/security_group.rb +12 -12
- data/lib/awspec/helper/finder/ses.rb +1 -1
- data/lib/awspec/helper/finder/vpc.rb +49 -49
- data/lib/awspec/resource_reader.rb +5 -5
- data/lib/awspec/type/base.rb +6 -1
- data/lib/awspec/type/ebs.rb +2 -0
- data/lib/awspec/type/ec2.rb +2 -3
- data/lib/awspec/type/elasticache_cache_parameter_group.rb +3 -5
- data/lib/awspec/type/network_acl.rb +2 -0
- data/lib/awspec/type/rds.rb +8 -6
- data/lib/awspec/type/rds_db_parameter_group.rb +3 -5
- data/lib/awspec/type/route53_hosted_zone.rb +0 -2
- data/lib/awspec/type/route_table.rb +2 -0
- data/lib/awspec/type/s3_bucket.rb +6 -8
- data/lib/awspec/type/security_group.rb +1 -2
- data/lib/awspec/type/ses_identity.rb +15 -15
- data/lib/awspec/type/subnet.rb +2 -0
- data/lib/awspec/type/vpc.rb +1 -2
- data/lib/awspec/version.rb +1 -1
- metadata +2 -2
@@ -2,9 +2,9 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Autoscaling
|
4
4
|
def find_autoscaling_group(id)
|
5
|
-
res =
|
6
|
-
|
7
|
-
|
5
|
+
res = autoscaling_client.describe_auto_scaling_groups({
|
6
|
+
auto_scaling_group_names: [id]
|
7
|
+
})
|
8
8
|
res[:auto_scaling_groups].first if res[:auto_scaling_groups].count == 1
|
9
9
|
end
|
10
10
|
end
|
@@ -2,12 +2,12 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Cloudwatch
|
4
4
|
def find_cloudwatch_alarm(id)
|
5
|
-
res =
|
6
|
-
|
7
|
-
|
5
|
+
res = cloudwatch_client.describe_alarms({
|
6
|
+
alarm_names: [id]
|
7
|
+
})
|
8
8
|
return res[:metric_alarms].first if res[:metric_alarms].count == 1
|
9
9
|
|
10
|
-
res =
|
10
|
+
res = cloudwatch_client.describe_alarms
|
11
11
|
res[:metric_alarms].find do |alarm|
|
12
12
|
alarm[:alarm_arn] == id
|
13
13
|
end
|
@@ -15,7 +15,7 @@ module Awspec::Helper
|
|
15
15
|
|
16
16
|
def select_all_cloudwatch_alarms
|
17
17
|
selected = []
|
18
|
-
res =
|
18
|
+
res = cloudwatch_client.describe_alarms
|
19
19
|
|
20
20
|
loop do
|
21
21
|
selected += res.metric_alarms
|
@@ -2,7 +2,7 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Directconnect
|
4
4
|
def find_virtual_interface(virtual_interface_id)
|
5
|
-
res =
|
5
|
+
res = directconnect_client.describe_virtual_interfaces
|
6
6
|
ret = res.virtual_interfaces.select do |virtual_interface|
|
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
|
@@ -11,7 +11,7 @@ module Awspec::Helper
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def select_virtual_interfaces
|
14
|
-
res =
|
14
|
+
res = directconnect_client.describe_virtual_interfaces
|
15
15
|
res.virtual_interfaces
|
16
16
|
end
|
17
17
|
end
|
@@ -2,13 +2,13 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Ebs
|
4
4
|
def find_ebs(volume_id)
|
5
|
-
res =
|
6
|
-
|
7
|
-
|
5
|
+
res = ec2_client.describe_volumes({
|
6
|
+
filters: [{ name: 'volume-id', values: [volume_id] }]
|
7
|
+
})
|
8
8
|
return res[:volumes].first if res[:volumes].count == 1
|
9
|
-
res =
|
10
|
-
|
11
|
-
|
9
|
+
res = ec2_client.describe_volumes({
|
10
|
+
filters: [{ name: 'tag:Name', values: [volume_id] }]
|
11
|
+
})
|
12
12
|
return res[:volumes].first if res[:volumes].count == 1
|
13
13
|
end
|
14
14
|
|
@@ -25,7 +25,7 @@ module Awspec::Helper
|
|
25
25
|
|
26
26
|
def select_all_attached_ebs
|
27
27
|
selected = []
|
28
|
-
res =
|
28
|
+
res = ec2_client.describe_volumes
|
29
29
|
|
30
30
|
loop do
|
31
31
|
selected += res.volumes.select { |v| v.attachments.count > 0 }
|
@@ -4,30 +4,30 @@ module Awspec::Helper
|
|
4
4
|
def find_ec2(id)
|
5
5
|
if id.is_a?(Array)
|
6
6
|
# Aws::EC2::Client.describe_instances native filters format
|
7
|
-
res =
|
8
|
-
|
9
|
-
|
7
|
+
res = ec2_client.describe_instances({
|
8
|
+
filters: id
|
9
|
+
})
|
10
10
|
elsif id.is_a?(Hash)
|
11
11
|
# syntax sugar
|
12
12
|
filters = []
|
13
13
|
id.each do |k, v|
|
14
14
|
filters.push({ name: k, values: Array(v) })
|
15
15
|
end
|
16
|
-
res =
|
17
|
-
|
18
|
-
|
16
|
+
res = ec2_client.describe_instances({
|
17
|
+
filters: filters
|
18
|
+
})
|
19
19
|
elsif id.is_a?(String)
|
20
20
|
# instance_id or tag:Name
|
21
21
|
begin
|
22
|
-
res =
|
23
|
-
|
24
|
-
|
22
|
+
res = ec2_client.describe_instances({
|
23
|
+
instance_ids: [id]
|
24
|
+
})
|
25
25
|
rescue
|
26
26
|
# Aws::EC2::Errors::InvalidInstanceIDMalformed
|
27
27
|
# Aws::EC2::Errors::InvalidInstanceIDNotFound
|
28
|
-
res =
|
29
|
-
|
30
|
-
|
28
|
+
res = ec2_client.describe_instances({
|
29
|
+
filters: [{ name: 'tag:Name', values: [id] }]
|
30
|
+
})
|
31
31
|
end
|
32
32
|
else
|
33
33
|
return nil
|
@@ -37,9 +37,9 @@ module Awspec::Helper
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def find_ec2_attribute(id, attribute)
|
40
|
-
res =
|
41
|
-
|
42
|
-
|
40
|
+
res = ec2_client.describe_instance_attribute({
|
41
|
+
instance_id: id, attribute: attribute
|
42
|
+
})
|
43
43
|
end
|
44
44
|
|
45
45
|
# fine_internet_gateway fine_vpn_gateway fine_customer_gateway
|
@@ -47,46 +47,46 @@ module Awspec::Helper
|
|
47
47
|
gateway_types.each do |type|
|
48
48
|
define_method 'find_' + type + '_gateway' do |*args|
|
49
49
|
gateway_id = args.first
|
50
|
-
res =
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
res = ec2_client.method('describe_' + type + '_gateways').call({
|
51
|
+
filters: [
|
52
|
+
{
|
53
|
+
name: type + '-gateway-id',
|
54
|
+
values: [gateway_id]
|
55
|
+
}
|
56
|
+
]
|
57
|
+
})
|
58
58
|
return res[type + '_gateways'].first if res[type + '_gateways'].count == 1
|
59
|
-
res =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
res = ec2_client.method('describe_' + type + '_gateways').call({
|
60
|
+
filters: [
|
61
|
+
{
|
62
|
+
name: 'tag:Name',
|
63
|
+
values: [gateway_id]
|
64
|
+
}
|
65
|
+
]
|
66
|
+
})
|
67
67
|
return res[type + '_gateways'].first if res[type + '_gateways'].count == 1
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
def find_security_group(sg_id)
|
72
|
-
res =
|
73
|
-
|
74
|
-
|
72
|
+
res = ec2_client.describe_security_groups({
|
73
|
+
filters: [{ name: 'group-id', values: [sg_id] }]
|
74
|
+
})
|
75
75
|
return res[:security_groups].first if res[:security_groups].count == 1
|
76
|
-
res =
|
77
|
-
|
78
|
-
|
76
|
+
res = ec2_client.describe_security_groups({
|
77
|
+
filters: [{ name: 'group-name', values: [sg_id] }]
|
78
|
+
})
|
79
79
|
return res[:security_groups].first if res[:security_groups].count == 1
|
80
|
-
res =
|
81
|
-
|
82
|
-
|
80
|
+
res = ec2_client.describe_security_groups({
|
81
|
+
filters: [{ name: 'tag:Name', values: [sg_id] }]
|
82
|
+
})
|
83
83
|
return res[:security_groups].first if res[:security_groups].count == 1
|
84
84
|
end
|
85
85
|
|
86
86
|
def select_ec2_by_vpc_id(vpc_id)
|
87
|
-
res =
|
88
|
-
|
89
|
-
|
87
|
+
res = ec2_client.describe_instances({
|
88
|
+
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
89
|
+
})
|
90
90
|
instances = []
|
91
91
|
return instances unless res[:reservations].count > 0
|
92
92
|
res[:reservations].each do |reservation|
|
@@ -98,9 +98,9 @@ module Awspec::Helper
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def select_eip_by_instance_id(id)
|
101
|
-
res =
|
102
|
-
|
103
|
-
|
101
|
+
res = ec2_client.describe_addresses({
|
102
|
+
filters: [{ name: 'instance-id', values: [id] }]
|
103
|
+
})
|
104
104
|
return [] unless res[:addresses].count > 0
|
105
105
|
res[:addresses]
|
106
106
|
end
|
@@ -2,18 +2,18 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Elasticache
|
4
4
|
def find_cache_cluster(id)
|
5
|
-
res =
|
6
|
-
|
7
|
-
|
5
|
+
res = elasticache_client.describe_cache_clusters({
|
6
|
+
cache_cluster_id: id
|
7
|
+
})
|
8
8
|
res[:cache_clusters].first if res[:cache_clusters].count == 1
|
9
9
|
rescue
|
10
10
|
nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def find_cache_subnet_group(group_name)
|
14
|
-
res =
|
15
|
-
|
16
|
-
|
14
|
+
res = elasticache_client.describe_cache_subnet_groups({
|
15
|
+
cache_subnet_group_name: group_name
|
16
|
+
})
|
17
17
|
res[:cache_subnet_groups].first if res[:cache_subnet_groups].count == 1
|
18
18
|
end
|
19
19
|
end
|
@@ -2,16 +2,16 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Elb
|
4
4
|
def find_elb(id)
|
5
|
-
res =
|
6
|
-
|
7
|
-
|
5
|
+
res = elb_client.describe_load_balancers({
|
6
|
+
load_balancer_names: [id]
|
7
|
+
})
|
8
8
|
return res[:load_balancer_descriptions].first if res[:load_balancer_descriptions].count == 1
|
9
9
|
rescue
|
10
10
|
return nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def select_elb_by_vpc_id(vpc_id)
|
14
|
-
res =
|
14
|
+
res = elb_client.describe_load_balancers
|
15
15
|
res[:load_balancer_descriptions].select do |lb|
|
16
16
|
lb.vpc_id == vpc_id
|
17
17
|
end
|
@@ -7,7 +7,7 @@ module Awspec::Helper
|
|
7
7
|
define_method 'find_iam_' + type do |*args|
|
8
8
|
id = args.first
|
9
9
|
selected = []
|
10
|
-
res =
|
10
|
+
res = iam_client.method('list_' + type.pluralize).call
|
11
11
|
loop do
|
12
12
|
selected += res[type.pluralize].select do |u|
|
13
13
|
u[type + '_name'] == id || u[type + '_id'] == id || u.arn == id
|
@@ -25,41 +25,41 @@ module Awspec::Helper
|
|
25
25
|
action_names: [action_name]
|
26
26
|
}
|
27
27
|
options[:resource_arns] = [resource_arn] if resource_arn
|
28
|
-
res =
|
28
|
+
res = iam_client.simulate_principal_policy(options)
|
29
29
|
res.evaluation_results
|
30
30
|
end
|
31
31
|
|
32
32
|
def select_iam_group_by_user_name(user_name)
|
33
|
-
res =
|
34
|
-
|
35
|
-
|
33
|
+
res = iam_client.list_groups_for_user({
|
34
|
+
user_name: user_name
|
35
|
+
})
|
36
36
|
res.groups
|
37
37
|
end
|
38
38
|
|
39
39
|
def select_iam_policy_by_user_name(user_name)
|
40
|
-
res =
|
41
|
-
|
42
|
-
|
40
|
+
res = iam_client.list_attached_user_policies({
|
41
|
+
user_name: user_name
|
42
|
+
})
|
43
43
|
res.attached_policies
|
44
44
|
end
|
45
45
|
|
46
46
|
def select_iam_policy_by_group_name(group_name)
|
47
|
-
res =
|
48
|
-
|
49
|
-
|
47
|
+
res = iam_client.list_attached_group_policies({
|
48
|
+
group_name: group_name
|
49
|
+
})
|
50
50
|
res.attached_policies
|
51
51
|
end
|
52
52
|
|
53
53
|
def select_iam_policy_by_role_name(role_name)
|
54
|
-
res =
|
55
|
-
|
56
|
-
|
54
|
+
res = iam_client.list_attached_role_policies({
|
55
|
+
role_name: role_name
|
56
|
+
})
|
57
57
|
res.attached_policies
|
58
58
|
end
|
59
59
|
|
60
60
|
def select_all_attached_policies
|
61
61
|
selected = []
|
62
|
-
res =
|
62
|
+
res = iam_client.list_policies
|
63
63
|
|
64
64
|
loop do
|
65
65
|
selected += res.policies.select { |p| p.attachment_count > 0 }
|
@@ -71,7 +71,7 @@ module Awspec::Helper
|
|
71
71
|
|
72
72
|
def select_attached_entities(policy_id)
|
73
73
|
policy = find_iam_policy(policy_id)
|
74
|
-
|
74
|
+
iam_client.list_entities_for_policy(policy_arn: policy[:arn])
|
75
75
|
end
|
76
76
|
|
77
77
|
def select_attached_users(policy_id)
|
@@ -3,7 +3,7 @@ module Awspec::Helper
|
|
3
3
|
module Lambda
|
4
4
|
def find_lambda(id)
|
5
5
|
selected = []
|
6
|
-
res =
|
6
|
+
res = lambda_client.list_functions
|
7
7
|
|
8
8
|
loop do
|
9
9
|
selected += res.functions.select do |function|
|
@@ -16,9 +16,9 @@ module Awspec::Helper
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def select_event_source_by_function_arn(function_arn)
|
19
|
-
res =
|
20
|
-
|
21
|
-
|
19
|
+
res = lambda_client.list_event_source_mappings({
|
20
|
+
function_name: function_arn
|
21
|
+
})
|
22
22
|
res[:event_source_mappings]
|
23
23
|
end
|
24
24
|
end
|
@@ -3,14 +3,14 @@ module Awspec::Helper
|
|
3
3
|
module Rds
|
4
4
|
def find_rds(id)
|
5
5
|
# db_instance_identifier
|
6
|
-
res =
|
7
|
-
|
8
|
-
|
6
|
+
res = rds_client.describe_db_instances({
|
7
|
+
db_instance_identifier: id
|
8
|
+
})
|
9
9
|
return res[:db_instances].first if res[:db_instances].count == 1
|
10
10
|
end
|
11
11
|
|
12
12
|
def select_rds_by_vpc_id(vpc_id)
|
13
|
-
res =
|
13
|
+
res = rds_client.describe_db_instances
|
14
14
|
res[:db_instances].select do |db_instance|
|
15
15
|
db_instance.db_subnet_group.vpc_id == vpc_id
|
16
16
|
end
|
@@ -2,7 +2,7 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module Route53
|
4
4
|
def find_hosted_zone(id)
|
5
|
-
res =
|
5
|
+
res = route53_client.list_hosted_zones
|
6
6
|
loop do
|
7
7
|
res.hosted_zones.each do |hosted_zone|
|
8
8
|
if hosted_zone[:name] == id || hosted_zone[:id] == '/hostedzone/' + id || hosted_zone[:id] == id
|
@@ -15,9 +15,9 @@ module Awspec::Helper
|
|
15
15
|
|
16
16
|
def select_record_sets_by_hosted_zone_id(id)
|
17
17
|
selected = []
|
18
|
-
res =
|
19
|
-
|
20
|
-
|
18
|
+
res = route53_client.list_resource_record_sets({
|
19
|
+
hosted_zone_id: id
|
20
|
+
})
|
21
21
|
loop do
|
22
22
|
selected += res.resource_record_sets
|
23
23
|
(res.next_page? && res = res.next_page) || break
|
@@ -2,32 +2,32 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module S3
|
4
4
|
def find_bucket(id)
|
5
|
-
res =
|
6
|
-
ret =
|
5
|
+
res = s3_client.list_buckets
|
6
|
+
ret = s3_client.list_buckets[:buckets].find do |bucket|
|
7
7
|
bucket.name == id
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
def find_bucket_acl(id)
|
12
|
-
|
12
|
+
s3_client.get_bucket_acl(bucket: id)
|
13
13
|
rescue Aws::S3::Errors::NoSuchBucket
|
14
14
|
nil
|
15
15
|
end
|
16
16
|
|
17
17
|
def find_bucket_cors(id)
|
18
|
-
|
18
|
+
s3_client.get_bucket_cors(bucket: id)
|
19
19
|
rescue Aws::S3::Errors::NoSuchBucket
|
20
20
|
nil
|
21
21
|
end
|
22
22
|
|
23
23
|
def find_bucket_policy(id)
|
24
|
-
|
24
|
+
s3_client.get_bucket_policy(bucket: id)
|
25
25
|
rescue Aws::S3::Errors::NoSuchBucket
|
26
26
|
nil
|
27
27
|
end
|
28
28
|
|
29
29
|
def select_all_buckets
|
30
|
-
|
30
|
+
s3_client.list_buckets.buckets
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|