awspec 0.69.1 → 0.70.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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -1
  3. data/.travis.yml +1 -0
  4. data/Rakefile +10 -1
  5. data/awspec.gemspec +3 -3
  6. data/doc/_resource_types/cloudwatch_logs.md +40 -0
  7. data/doc/_resource_types/ec2_account_attributes.md +8 -0
  8. data/doc/_resource_types/lambda_account_settings.md +10 -0
  9. data/doc/_resource_types/rds_account_attributes.md +8 -0
  10. data/doc/_resource_types/ses_send_quota.md +9 -0
  11. data/doc/contributing.md +10 -0
  12. data/doc/resource_types.md +262 -27
  13. data/lib/awspec/error.rb +2 -0
  14. data/lib/awspec/ext.rb +1 -0
  15. data/lib/awspec/ext/hash.rb +10 -0
  16. data/lib/awspec/generator.rb +6 -0
  17. data/lib/awspec/generator/doc/type.rb +35 -1
  18. data/lib/awspec/generator/doc/type/account.rb +71 -0
  19. data/lib/awspec/generator/doc/type/account_attribute.rb +69 -0
  20. data/lib/awspec/generator/doc/type/account_attribute_base.rb +32 -0
  21. data/lib/awspec/generator/doc/type/base.rb +10 -3
  22. data/lib/awspec/generator/doc/type/cloudwatch_logs.rb +17 -0
  23. data/lib/awspec/generator/doc/type/ec2_account_attributes.rb +17 -0
  24. data/lib/awspec/generator/doc/type/lambda_account_settings.rb +17 -0
  25. data/lib/awspec/generator/doc/type/rds_account_attributes.rb +17 -0
  26. data/lib/awspec/generator/doc/type/ses_send_quota.rb +17 -0
  27. data/lib/awspec/generator/template.rb +38 -1
  28. data/lib/awspec/helper/finder.rb +8 -1
  29. data/lib/awspec/helper/finder/account_attributes.rb +61 -0
  30. data/lib/awspec/helper/finder/cloudwatch_logs.rb +35 -0
  31. data/lib/awspec/helper/type.rb +31 -0
  32. data/lib/awspec/matcher.rb +3 -0
  33. data/lib/awspec/matcher/have_subscription_filter.rb +9 -0
  34. data/lib/awspec/shared_context.rb +8 -0
  35. data/lib/awspec/stub/account.rb +146 -0
  36. data/lib/awspec/stub/cloudwatch_logs.rb +34 -0
  37. data/lib/awspec/stub/ecs.rb +9 -9
  38. data/lib/awspec/stub/ecs_cluster.rb +9 -9
  39. data/lib/awspec/stub/ecs_container_instance.rb +9 -9
  40. data/lib/awspec/toolbox.rb +6 -1
  41. data/lib/awspec/type/account.rb +35 -0
  42. data/lib/awspec/type/account_attribute.rb +28 -0
  43. data/lib/awspec/type/account_attribute_base.rb +4 -0
  44. data/lib/awspec/type/acm.rb +1 -1
  45. data/lib/awspec/type/alb.rb +1 -1
  46. data/lib/awspec/type/ami.rb +1 -1
  47. data/lib/awspec/type/autoscaling_group.rb +3 -2
  48. data/lib/awspec/type/base.rb +6 -25
  49. data/lib/awspec/type/cloudfront_distribution.rb +1 -1
  50. data/lib/awspec/type/cloudtrail.rb +1 -1
  51. data/lib/awspec/type/cloudwatch_alarm.rb +1 -1
  52. data/lib/awspec/type/cloudwatch_event.rb +1 -1
  53. data/lib/awspec/type/cloudwatch_logs.rb +27 -0
  54. data/lib/awspec/type/customer_gateway.rb +1 -1
  55. data/lib/awspec/type/directconnect_virtual_interface.rb +1 -1
  56. data/lib/awspec/type/ebs.rb +1 -1
  57. data/lib/awspec/type/ec2.rb +1 -1
  58. data/lib/awspec/type/ec2_account_attributes.rb +7 -0
  59. data/lib/awspec/type/ecr_repository.rb +1 -1
  60. data/lib/awspec/type/ecs_cluster.rb +1 -1
  61. data/lib/awspec/type/ecs_container_instance.rb +1 -1
  62. data/lib/awspec/type/ecs_service.rb +1 -1
  63. data/lib/awspec/type/ecs_task_definition.rb +1 -1
  64. data/lib/awspec/type/efs.rb +1 -1
  65. data/lib/awspec/type/elasticache.rb +1 -1
  66. data/lib/awspec/type/elasticache_cache_parameter_group.rb +1 -1
  67. data/lib/awspec/type/elasticsearch.rb +1 -1
  68. data/lib/awspec/type/elastictranscoder_pipeline.rb +1 -1
  69. data/lib/awspec/type/elb.rb +3 -2
  70. data/lib/awspec/type/iam_group.rb +1 -1
  71. data/lib/awspec/type/iam_policy.rb +1 -1
  72. data/lib/awspec/type/iam_role.rb +1 -1
  73. data/lib/awspec/type/iam_user.rb +1 -1
  74. data/lib/awspec/type/internet_gateway.rb +1 -1
  75. data/lib/awspec/type/kms.rb +1 -1
  76. data/lib/awspec/type/lambda.rb +1 -1
  77. data/lib/awspec/type/lambda_account_settings.rb +7 -0
  78. data/lib/awspec/type/launch_configuration.rb +1 -1
  79. data/lib/awspec/type/nat_gateway.rb +1 -1
  80. data/lib/awspec/type/network_acl.rb +1 -1
  81. data/lib/awspec/type/network_interface.rb +1 -1
  82. data/lib/awspec/type/rds.rb +1 -1
  83. data/lib/awspec/type/rds_account_attributes.rb +7 -0
  84. data/lib/awspec/type/rds_db_cluster_parameter_group.rb +1 -1
  85. data/lib/awspec/type/rds_db_parameter_group.rb +1 -1
  86. data/lib/awspec/type/resource_base.rb +24 -0
  87. data/lib/awspec/type/route53_hosted_zone.rb +1 -1
  88. data/lib/awspec/type/route_table.rb +1 -1
  89. data/lib/awspec/type/s3_bucket.rb +1 -1
  90. data/lib/awspec/type/security_group.rb +1 -1
  91. data/lib/awspec/type/ses_identity.rb +1 -1
  92. data/lib/awspec/type/ses_send_quota.rb +7 -0
  93. data/lib/awspec/type/subnet.rb +1 -1
  94. data/lib/awspec/type/vpc.rb +1 -1
  95. data/lib/awspec/type/vpn_connection.rb +1 -1
  96. data/lib/awspec/type/vpn_gateway.rb +1 -1
  97. data/lib/awspec/type/waf_web_acl.rb +1 -1
  98. data/lib/awspec/version.rb +1 -1
  99. metadata +36 -8
@@ -28,6 +28,9 @@ require 'awspec/helper/finder/elastictranscoder'
28
28
  require 'awspec/helper/finder/cloudtrail'
29
29
  require 'awspec/helper/finder/waf'
30
30
  require 'awspec/helper/finder/acm'
31
+ require 'awspec/helper/finder/cloudwatch_logs'
32
+
33
+ require 'awspec/helper/finder/account_attributes'
31
34
 
32
35
  module Awspec::Helper
33
36
  module Finder
@@ -60,6 +63,8 @@ module Awspec::Helper
60
63
  include Awspec::Helper::Finder::Cloudtrail
61
64
  include Awspec::Helper::Finder::Waf
62
65
  include Awspec::Helper::Finder::Acm
66
+ include Awspec::Helper::Finder::AccountAttributes
67
+ include Awspec::Helper::Finder::CloudwatchLogs
63
68
 
64
69
  CLIENTS = {
65
70
  ec2_client: Aws::EC2::Client,
@@ -85,7 +90,9 @@ module Awspec::Helper
85
90
  elasticsearch_client: Aws::ElasticsearchService::Client,
86
91
  cloudtrail_client: Aws::CloudTrail::Client,
87
92
  waf_client: Aws::WAF::Client,
88
- acm_client: Aws::ACM::Client
93
+ sts_client: Aws::STS::Client,
94
+ acm_client: Aws::ACM::Client,
95
+ cloudwatch_logs_client: Aws::CloudWatchLogs::Client
89
96
  }
90
97
 
91
98
  CLIENTS.each do |method_name, client|
@@ -0,0 +1,61 @@
1
+ module Awspec::Helper
2
+ module Finder
3
+ module AccountAttributes
4
+ def find_ec2_account_attributes
5
+ attributes = {}
6
+ ec2_client.describe_account_attributes.account_attributes.each do |attr|
7
+ values = attr[:attribute_values].map do |v|
8
+ v[:attribute_value]
9
+ end
10
+ if attr[:attribute_name] == 'supported-platforms'
11
+ # supported-platforms
12
+ attributes[attr[:attribute_name].tr('-', '_').to_sym] = values
13
+ else
14
+ value = values.first
15
+ if value =~ /\A\d+\z/
16
+ attributes[attr[:attribute_name].tr('-', '_').to_sym] = value.to_i
17
+ else
18
+ attributes[attr[:attribute_name].tr('-', '_').to_sym] = value
19
+ end
20
+ end
21
+ end
22
+ attributes.to_struct
23
+ end
24
+
25
+ def find_rds_account_attributes
26
+ attributes = {}
27
+ rds_client.describe_account_attributes.account_quotas.each do |attr|
28
+ values = {
29
+ used: attr[:used],
30
+ max: attr[:max]
31
+ }
32
+ attributes[attr[:account_quota_name].to_sym] = values.to_struct
33
+ end
34
+ attributes.to_struct
35
+ end
36
+
37
+ def find_lambda_account_settings
38
+ attributes = {}
39
+ settings = lambda_client.get_account_settings
40
+ settings.account_limit.members.each do |key|
41
+ attributes[key] = { limit: settings.account_limit[key] }
42
+ end
43
+ settings.account_usage.members.each do |key|
44
+ if attributes.include?(key)
45
+ attributes[key][:usage] = settings.account_usage[key]
46
+ else
47
+ attributes[key] = { usage: settings.account_usage[key] }
48
+ end
49
+ end
50
+ attributes.to_struct
51
+ end
52
+
53
+ def find_ses_send_quota
54
+ ses_client.get_send_quota
55
+ rescue
56
+ # Aws::Errors::NoSuchEndpointError
57
+ nil
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ module Awspec::Helper
2
+ module Finder
3
+ module CloudwatchLogs
4
+ def find_cloudwatch_logs_group(id)
5
+ cloudwatch_logs_client.describe_log_groups({
6
+ log_group_name_prefix: id
7
+ }).log_groups.find do |log_group|
8
+ log_group.log_group_name == id
9
+ end
10
+ end
11
+
12
+ def find_cloudwatch_logs_stream_by_log_group_name(id)
13
+ cloudwatch_logs_client.describe_log_streams({ log_group_name: id }).log_streams.last
14
+ end
15
+
16
+ def find_cloudwatch_logs_metric_fileter_by_log_group_name(id, filter_name)
17
+ cloudwatch_logs_client.describe_metric_filters({
18
+ log_group_name: id,
19
+ filter_name_prefix: filter_name
20
+ }).metric_filters.find do |filter|
21
+ filter.filter_name == filter_name
22
+ end
23
+ end
24
+
25
+ def find_cloudwatch_logs_subscription_fileter_by_log_group_name(id, filter_name)
26
+ cloudwatch_logs_client.describe_subscription_filters({
27
+ log_group_name: id,
28
+ filter_name_prefix: filter_name
29
+ }).subscription_filters.find do |filter|
30
+ filter.filter_name == filter_name
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,6 +2,10 @@ module Awspec
2
2
  module Helper
3
3
  module Type
4
4
  require 'awspec/type/base'
5
+ require 'awspec/type/resource_base'
6
+ require 'awspec/type/account_attribute_base'
7
+ require 'awspec/type/account'
8
+ require 'awspec/type/account_attribute'
5
9
 
6
10
  TYPES = %w(
7
11
  alb ami autoscaling_group cloudtrail cloudwatch_alarm cloudwatch_event directconnect_virtual_interface
@@ -11,16 +15,43 @@ module Awspec
11
15
  network_acl network_interface rds rds_db_cluster_parameter_group rds_db_parameter_group route53_hosted_zone
12
16
  route_table s3_bucket security_group ses_identity subnet vpc cloudfront_distribution
13
17
  elastictranscoder_pipeline waf_web_acl customer_gateway vpn_gateway vpn_connection internet_gateway acm
18
+ cloudwatch_logs
19
+ )
20
+
21
+ ACCOUNT_ATTRIBUTES = %w(
22
+ ec2_account_attributes rds_account_attributes lambda_account_settings ses_send_quota
14
23
  )
15
24
 
16
25
  TYPES.each do |type|
17
26
  require "awspec/type/#{type}"
18
27
  define_method type do |*args|
28
+ unless Object.const_get("Awspec::Type::#{type.camelize}").superclass.to_s == 'Awspec::Type::ResourceBase'
29
+ raise "Awspec::Type::#{type.camelize} should extend Awspec::Type::ResourceBase"
30
+ end
19
31
  name = args.first
20
32
  eval "Awspec::Type::#{type.camelize}.new(name)"
21
33
  end
22
34
  end
23
35
 
36
+ ACCOUNT_ATTRIBUTES.each do |type|
37
+ require "awspec/type/#{type}"
38
+ define_method type do
39
+ unless Object.const_get("Awspec::Type::#{type.camelize}").superclass.to_s \
40
+ == 'Awspec::Type::AccountAttributeBase'
41
+ raise "Awspec::Type::#{type.camelize} should extend Awspec::Type::AccountAttributeBase"
42
+ end
43
+ eval "Awspec::Type::#{type.camelize}.new"
44
+ end
45
+ end
46
+
47
+ def account
48
+ Awspec::Type::Account.new
49
+ end
50
+
51
+ def account_attribute(key)
52
+ Awspec::Type::AccountAttribute.new(key)
53
+ end
54
+
24
55
  def self.deprecate_resource_type(old_type, new_type)
25
56
  define_method(old_type) do |*args, &block|
26
57
  puts ''
@@ -47,3 +47,6 @@ require 'awspec/matcher/have_key_policy'
47
47
 
48
48
  # WafWebAcl
49
49
  require 'awspec/matcher/have_rule'
50
+
51
+ # CloudWatch Logs
52
+ require 'awspec/matcher/have_subscription_filter'
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :have_subscription_filter do |filter_name|
2
+ match do |log_group_name|
3
+ log_group_name.has_subscription_filter?(filter_name, @pattern)
4
+ end
5
+
6
+ chain :filter_pattern do |pattern|
7
+ @pattern = pattern
8
+ end
9
+ end
@@ -10,6 +10,14 @@ shared_context 'region', :region do
10
10
  end
11
11
  end
12
12
 
13
+ shared_context 'account', :account do
14
+ before do |example|
15
+ sts_client = Aws::STS::Client.new
16
+ raise Awspec::InvalidAccountError unless sts_client.get_caller_identity.account == example.metadata[:account]
17
+ example.metadata[:described_class].account = example.metadata[:account]
18
+ end
19
+ end
20
+
13
21
  shared_context 'cluster', :cluster do
14
22
  before do |example|
15
23
  example.metadata[:described_class].cluster = example.metadata[:cluster]
@@ -0,0 +1,146 @@
1
+ Aws.config[:ec2] = {
2
+ stub_responses: {
3
+ describe_account_attributes: {
4
+ account_attributes: [
5
+ {
6
+ attribute_name: 'supported-platforms',
7
+ attribute_values: [
8
+ {
9
+ attribute_value: 'EC2'
10
+ },
11
+ {
12
+ attribute_value: 'VPC'
13
+ }
14
+ ]
15
+ },
16
+ {
17
+ attribute_name: 'vpc-max-security-groups-per-interface',
18
+ attribute_values: [
19
+ {
20
+ attribute_value: '5'
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ attribute_name: 'max-elastic-ips',
26
+ attribute_values: [
27
+ {
28
+ attribute_value: '5'
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ attribute_name: 'max-instances',
34
+ attribute_values: [
35
+ {
36
+ attribute_value: '20'
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ attribute_name: 'vpc-max-elastic-ips',
42
+ attribute_values: [
43
+ {
44
+ attribute_value: '5'
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ attribute_name: 'default-vpc',
50
+ attribute_values: [
51
+ {
52
+ attribute_value: 'none'
53
+ }
54
+ ]
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ }
60
+ Aws.config[:rds] = {
61
+ stub_responses: {
62
+ describe_account_attributes: {
63
+ account_quotas: [
64
+ {
65
+ account_quota_name: 'DBInstances', used: 0, max: 40
66
+ },
67
+ {
68
+ account_quota_name: 'ReservedDBInstances', used: 0, max: 40
69
+ },
70
+ {
71
+ account_quota_name: 'AllocatedStorage', used: 0, max: 100_000
72
+ },
73
+ {
74
+ account_quota_name: 'DBSecurityGroups', used: 0, max: 25
75
+ },
76
+ {
77
+ account_quota_name: 'AuthorizationsPerDBSecurityGroup', used: 0, max: 20
78
+ },
79
+ {
80
+ account_quota_name: 'DBParameterGroups', used: 1, max: 50
81
+ },
82
+ {
83
+ account_quota_name: 'ManualSnapshots', used: 0, max: 100
84
+ },
85
+ {
86
+ account_quota_name: 'EventSubscriptions', used: 0, max: 20
87
+ },
88
+ {
89
+ account_quota_name: 'DBSubnetGroups', used: 1, max: 50
90
+ },
91
+ {
92
+ account_quota_name: 'OptionGroups', used: 0, max: 20
93
+ },
94
+ {
95
+ account_quota_name: 'SubnetsPerDBSubnetGroup', used: 2, max: 20
96
+ },
97
+ {
98
+ account_quota_name: 'ReadReplicasPerMaster', used: 0, max: 5
99
+ },
100
+ {
101
+ account_quota_name: 'DBClusters', used: 0, max: 40
102
+ },
103
+ {
104
+ account_quota_name: 'DBClusterParameterGroups', used: 0, max: 50
105
+ },
106
+ {
107
+ account_quota_name: 'DBClusterRoles', used: 0, max: 5
108
+ }
109
+ ]
110
+ }
111
+ }
112
+ }
113
+ Aws.config[:lambda] = {
114
+ stub_responses: {
115
+ get_account_settings: {
116
+ account_limit: {
117
+ total_code_size: 80_530_636_800,
118
+ code_size_unzipped: 262_144_000,
119
+ code_size_zipped: 52_428_800,
120
+ concurrent_executions: 200
121
+ },
122
+ account_usage: {
123
+ total_code_size: 2_034_651_562,
124
+ function_count: 8
125
+ }
126
+ }
127
+ }
128
+ }
129
+ Aws.config[:ses] = {
130
+ stub_responses: {
131
+ get_send_quota: {
132
+ max_24_hour_send: 200.0,
133
+ max_send_rate: 1.0,
134
+ sent_last_24_hours: 1.0
135
+ }
136
+ }
137
+ }
138
+ Aws.config[:sts] = {
139
+ stub_responses: {
140
+ get_caller_identity: {
141
+ account: '123456789012',
142
+ arn: 'arn:aws:iam::123456789012:user/Alice',
143
+ user_id: 'AKIAI44QH8DHBEXAMPLE'
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,34 @@
1
+ Aws.config[:cloudwatchlogs] = {
2
+ stub_responses: {
3
+ describe_log_groups: {
4
+ log_groups: [
5
+ {
6
+ log_group_name: 'my-cloudwatch-logs-group',
7
+ retention_in_days: 365
8
+ }
9
+ ]
10
+ },
11
+ describe_log_streams: {
12
+ log_streams: [
13
+ {
14
+ log_stream_name: 'my-cloudwatch-logs-stream'
15
+ }
16
+ ]
17
+ },
18
+ describe_metric_filters: {
19
+ metric_filters: [
20
+ {
21
+ filter_name: 'my-cloudwatch-logs-metric-filter'
22
+ }
23
+ ]
24
+ },
25
+ describe_subscription_filters: {
26
+ subscription_filters: [
27
+ {
28
+ filter_name: 'my-cloudwatch-logs-subscription-filter',
29
+ filter_pattern: '[host, ident, authuser, date, request, status, bytes]'
30
+ }
31
+ ]
32
+ }
33
+ }
34
+ }
@@ -50,10 +50,10 @@ Aws.config[:ecs] = {
50
50
  integer_value: 0,
51
51
  long_value: 0,
52
52
  string_set_value: %w[
53
- '2376',
54
- '22',
55
- '51678',
56
- '2375'
53
+ 2376
54
+ 22
55
+ 51678
56
+ 2375
57
57
  ]
58
58
  }
59
59
  ],
@@ -79,11 +79,11 @@ Aws.config[:ecs] = {
79
79
  integer_value: 0,
80
80
  long_value: 0,
81
81
  string_set_value: %w[
82
- '2376',
83
- '22',
84
- '80',
85
- '51678',
86
- '2375'
82
+ 2376
83
+ 22
84
+ 80
85
+ 51678
86
+ 2375
87
87
  ]
88
88
  }
89
89
  ],
@@ -51,10 +51,10 @@ Aws.config[:ecs] = {
51
51
  integer_value: 0,
52
52
  long_value: 0,
53
53
  string_set_value: %w[
54
- '2376',
55
- '22',
56
- '51678',
57
- '2375'
54
+ 2376
55
+ 22
56
+ 51678
57
+ 2375
58
58
  ]
59
59
  }
60
60
  ],
@@ -80,11 +80,11 @@ Aws.config[:ecs] = {
80
80
  integer_value: 0,
81
81
  long_value: 0,
82
82
  string_set_value: %w[
83
- '2376',
84
- '22',
85
- '80',
86
- '51678',
87
- '2375'
83
+ 2376
84
+ 22
85
+ 80
86
+ 51678
87
+ 2375
88
88
  ]
89
89
  }
90
90
  ],