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
@@ -1,4 +1,6 @@
1
1
  module Awspec
2
2
  class DuplicatedResourceTypeError < StandardError
3
3
  end
4
+ class InvalidAccountError < StandardError
5
+ end
4
6
  end
@@ -1,2 +1,3 @@
1
+ require 'awspec/ext/hash'
1
2
  require 'awspec/ext/struct'
2
3
  require 'awspec/ext/array'
@@ -0,0 +1,10 @@
1
+ class Hash
2
+ def to_struct
3
+ st = Struct.new(*self.keys)
4
+ maps = self.values.map do |s|
5
+ next s.to_struct if s.is_a?(Hash)
6
+ s
7
+ end
8
+ st.new(*maps)
9
+ end
10
+ end
@@ -26,9 +26,15 @@ require 'awspec/generator/spec/iam_role'
26
26
  # Doc
27
27
  require 'awspec/generator/doc/type'
28
28
  require 'awspec/generator/doc/type/base'
29
+ require 'awspec/generator/doc/type/account_attribute_base'
29
30
  Awspec::Helper::Type::TYPES.each do |type|
30
31
  require 'awspec/generator/doc/type/' + type
31
32
  end
33
+ Awspec::Helper::Type::ACCOUNT_ATTRIBUTES.each do |type|
34
+ require 'awspec/generator/doc/type/' + type
35
+ end
36
+ require 'awspec/generator/doc/type/account'
37
+ require 'awspec/generator/doc/type/account_attribute'
32
38
 
33
39
  # Template
34
40
  require 'awspec/generator/template'
@@ -1,13 +1,15 @@
1
1
  module Awspec::Generator
2
2
  module Doc
3
3
  module Type
4
+ # rubocop:disable Metrics/MethodLength
4
5
  def self.generate_doc
5
6
  Aws.config[:stub_responses] = true
6
7
  types = Awspec::Helper::Type::TYPES
7
8
  types.delete('base')
8
- links = types.map do |type|
9
+ links = types.sort.map do |type|
9
10
  '[' + type + '](#' + type + ')'
10
11
  end
12
+ links.push('[account](#account)') # add account
11
13
  header = <<-'EOF'
12
14
  # Resource Types
13
15
 
@@ -19,6 +21,38 @@ EOF
19
21
  types.map do |type|
20
22
  doc += eval "Awspec::Generator::Doc::Type::#{type.camelize}.new.generate_doc"
21
23
  end
24
+
25
+ # account and attributes
26
+ attributes = Awspec::Helper::Type::ACCOUNT_ATTRIBUTES
27
+
28
+ doc += <<-'EOF'
29
+ # Account and Attributes
30
+
31
+ EOF
32
+ doc += Awspec::Generator::Doc::Type::Account.new.generate_doc
33
+
34
+ doc += <<-'EOF'
35
+ ## :unlock: Another way: Test with account_attribute type
36
+
37
+ EOF
38
+
39
+ doc += Awspec::Generator::Doc::Type::AccountAttribute.new.generate_doc
40
+
41
+ doc += <<-'EOF'
42
+ ## :unlock: Another way: Test with separated resource types
43
+
44
+ EOF
45
+
46
+ links = attributes.map do |type|
47
+ '[' + type + '](#' + type + ')'
48
+ end
49
+
50
+ doc += links.join("\n| ") + "\n"
51
+
52
+ attributes.map do |type|
53
+ doc += eval "Awspec::Generator::Doc::Type::#{type.camelize}.new.generate_doc"
54
+ end
55
+
22
56
  doc.sub(/\n*\z/, '')
23
57
  end
24
58
  end
@@ -0,0 +1,71 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class Account < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'Account'
8
+ @type = Awspec::Type::Account.new
9
+ @ret = @type.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+
15
+ def generate_doc
16
+ @account_spec = ERB.new(account_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
17
+ super
18
+ end
19
+
20
+ def account_spec_template
21
+ template = <<-'EOF'
22
+ describe account do
23
+ <% @ret.members.each do |key| %>
24
+ <%- if @ret[key].is_a?(String) -%>
25
+ its(:<%= key %>) { should eq '<%= @ret[key] %>' }
26
+ <%- else -%>
27
+ <% @ret[key].members.each do |attribute| %>
28
+ <%- if @ret[key][attribute].is_a?(Array) -%>
29
+ its('<%= key %>.<%= attribute %>') { should eq <%= @ret[key][attribute] %> }
30
+ <%- elsif @ret[key][attribute].is_a?(String) -%>
31
+ its('<%= key %>.<%= attribute %>') { should eq '<%= @ret[key][attribute] %>' }
32
+ <%- elsif @ret[key][attribute].is_a?(Struct) -%>
33
+ <% @ret[key][attribute].members.each do |k| %>
34
+ its('<%= key %>.<%= attribute %>.<%= k %>') { should eq <%= @ret[key][attribute][k] %> }
35
+ <% end %>
36
+ <%- else -%>
37
+ its('<%= key %>.<%= attribute %>') { should eq <%= @ret[key][attribute] %> }
38
+ <%- end -%>
39
+ <% end %>
40
+ <% end %>
41
+ <%- end -%>
42
+ end
43
+ EOF
44
+ template
45
+ end
46
+
47
+ def doc_template
48
+ template = <<-'EOF'
49
+ ## <a name="<%= @type_name.gsub(/ /, '_').underscore %>"><%= @type_name.gsub(/ /, '_').underscore %></a>
50
+
51
+ <%= @type_name %> resource type.
52
+ <%- if @descriptions.include?('first') -%><%= @descriptions['first'] %><%- end -%>
53
+
54
+ ```ruby
55
+ <%= @account_spec %>```
56
+
57
+ <% @matchers.each do |matcher| %>
58
+ ### <%= matcher %>
59
+ <%- if @descriptions.include?(matcher) -%><%= @descriptions[matcher] %><%- end -%>
60
+ <% end %>
61
+ <%- if @descriptions.include?('advanced') -%>
62
+
63
+ ### :unlock: Advanced use
64
+ <%= @descriptions['advanced'] %><%- end -%>
65
+ EOF
66
+ template
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,69 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class AccountAttribute < Base
5
+ def initialize
6
+ Awspec::Stub.load 'account'
7
+ @type_name = 'Account Attribute'
8
+ @type = Awspec::Type::Account.new
9
+ @ret = Awspec::Type::Account.new.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+
15
+ def generate_doc
16
+ @account_attribute_spec = ERB.new(account_attribute_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
17
+ super
18
+ end
19
+
20
+ def account_attribute_spec_template
21
+ template = <<-'EOF'
22
+ <% @ret.members.each do |key| %>
23
+ <%- next if @ret[key].is_a?(String) -%>
24
+ describe account_attribute('<%= key %>') do
25
+ <% @ret[key].members.each do |attribute| %>
26
+ <%- if @ret[key][attribute].is_a?(Array) -%>
27
+ its('<%= attribute %>') { should eq <%= @ret[key][attribute] %> }
28
+ <%- elsif @ret[key][attribute].is_a?(String) -%>
29
+ its('<%= attribute %>') { should eq '<%= @ret[key][attribute] %>' }
30
+ <%- elsif @ret[key][attribute].is_a?(Struct) -%>
31
+ <% @ret[key][attribute].members.each do |k| %>
32
+ its('<%= attribute %>.<%= k %>') { should eq <%= @ret[key][attribute][k] %> }
33
+ <% end %>
34
+ <%- else -%>
35
+ its('<%= attribute %>') { should eq <%= @ret[key][attribute] %> }
36
+ <%- end -%>
37
+ <% end %>
38
+ end
39
+ <%= ' ' %>
40
+ <% end %>
41
+ EOF
42
+ template
43
+ end
44
+
45
+ def doc_template
46
+ template = <<-'EOF'
47
+ ## <a name="<%= @type_name.gsub(/ /, '_').underscore %>"><%= @type_name.gsub(/ /, '_').underscore %></a>
48
+
49
+ <%= @type_name %> resource type.
50
+ <%- if @descriptions.include?('first') -%><%= @descriptions['first'] %><%- end -%>
51
+
52
+ ```ruby
53
+ <%= @account_attribute_spec %>```
54
+
55
+ <% @matchers.each do |matcher| %>
56
+ ### <%= matcher %>
57
+ <%- if @descriptions.include?(matcher) -%><%= @descriptions[matcher] %><%- end -%>
58
+ <% end %>
59
+ <%- if @descriptions.include?('advanced') -%>
60
+
61
+ ### :unlock: Advanced use
62
+ <%= @descriptions['advanced'] %><%- end -%>
63
+ EOF
64
+ template
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class AccountAttributeBase < Base
5
+ def initialize
6
+ Awspec::Stub.load 'account'
7
+ @type_name = type_name
8
+ end
9
+
10
+ def doc_template
11
+ template = <<-'EOF'
12
+ ## <a name="<%= @type_name.gsub(/ /, '_').underscore %>"><%= @type_name.gsub(/ /, '_').underscore %></a>
13
+
14
+ <%= @type_name %> account attributes.
15
+ <%- if @descriptions.include?('first') -%><%= @descriptions['first'] %><%- end -%>
16
+ <% @matchers.each do |matcher| %>
17
+ ### <%= matcher %>
18
+ <%- if @descriptions.include?(matcher) -%><%= @descriptions[matcher] %><%- end -%>
19
+ <% end %>
20
+ <%- unless its.empty? -%>### <%= its.join(', ') %><%- end -%>
21
+ <%- if @descriptions.include?('advanced') -%>
22
+
23
+ ### :unlock: Advanced use
24
+ <%= @descriptions['advanced'] %><%- end -%>
25
+
26
+ EOF
27
+ template
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -11,6 +11,7 @@ module Awspec::Generator
11
11
  self.class.to_s.split('::').last
12
12
  end
13
13
 
14
+ # rubocop:disable Metrics/MethodLength
14
15
  def generate_doc
15
16
  @matchers += collect_matchers - @ignore_matchers
16
17
  @matchers.sort! do |a, b|
@@ -18,9 +19,15 @@ module Awspec::Generator
18
19
  next ret if ret != 0
19
20
  a.casecmp(b)
20
21
  end
21
- @describes += @ret.members.select do |describe|
22
- next true unless @ret[describe].is_a?(Array) || @ret[describe].is_a?(Hash) || @ret[describe].is_a?(Struct)
23
- end if @ret.respond_to?(:members)
22
+ if @ret.respond_to?(:members)
23
+ @describes += @ret.members.select do |describe|
24
+ if @ret[describe].is_a?(Array)
25
+ next true unless @ret[describe].first.is_a?(Array) || @ret[describe].first.is_a?(Hash) || @ret[describe].first.is_a?(Struct) # rubocop:disable Metrics/LineLength
26
+ else
27
+ next true unless @ret[describe].is_a?(Hash) || @ret[describe].is_a?(Struct)
28
+ end
29
+ end
30
+ end
24
31
  its = @describes.map do |describe|
25
32
  'its(:' + describe.to_s + ')'
26
33
  end
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class CloudwatchLogs < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'CloudwatchLogs'
8
+ @type = Awspec::Type::CloudwatchLogs.new('my-cloudwatch-logs-group')
9
+ @ret = @type.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class Ec2AccountAttributes < AccountAttributeBase
5
+ def initialize
6
+ super
7
+ @type_name = 'Ec2AccountAttributes'
8
+ @type = Awspec::Type::Ec2AccountAttributes.new
9
+ @ret = @type.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class LambdaAccountSettings < AccountAttributeBase
5
+ def initialize
6
+ super
7
+ @type_name = 'LambdaAccountSettings'
8
+ @type = Awspec::Type::LambdaAccountSettings.new
9
+ @ret = @type.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class RdsAccountAttributes < AccountAttributeBase
5
+ def initialize
6
+ super
7
+ @type_name = 'RdsAccountAttributes'
8
+ @type = Awspec::Type::RdsAccountAttributes.new
9
+ @ret = @type.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class SesSendQuota < AccountAttributeBase
5
+ def initialize
6
+ super
7
+ @type_name = 'SesSendQuota'
8
+ @type = Awspec::Type::SesSendQuota.new
9
+ @ret = @type.resource_via_client
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,7 +1,9 @@
1
1
  module Awspec::Generator
2
+ # rubocop:disable Metrics/ClassLength
2
3
  class Template
3
4
  def self.generate(type)
4
5
  @type = type
6
+ @account_attribute = false
5
7
  @root_path = File.dirname(__FILE__) + '/../../../'
6
8
  generate_stub
7
9
  generate_type
@@ -11,11 +13,22 @@ module Awspec::Generator
11
13
  put_message
12
14
  end
13
15
 
16
+ def self.generate_account_attribute(type)
17
+ @type = type
18
+ @account_attribute = true
19
+ @root_path = File.dirname(__FILE__) + '/../../../'
20
+ generate_type
21
+ generate_account_attribute_generator_doc
22
+ generate_resource_type_doc
23
+ put_message
24
+ end
25
+
14
26
  def self.generate_type
15
27
  path = 'lib/awspec/type/' + @type.underscore + '.rb'
28
+ base = @account_attribute ? 'AccountAttributeBase' : 'ResourceBase'
16
29
  content = <<-"EOF"
17
30
  module Awspec::Type
18
- class #{@type.camelize} < Base
31
+ class #{@type.camelize} < #{base}
19
32
  def resource_via_client
20
33
  @resource_via_client ||= # FIXME
21
34
  end
@@ -76,6 +89,30 @@ EOF
76
89
  self.file_check_and_puts(path, content)
77
90
  end
78
91
 
92
+ def self.generate_account_attribute_generator_doc
93
+ path = 'lib/awspec/generator/doc/type/' + @type.underscore + '.rb'
94
+ content = <<-"EOF"
95
+ module Awspec::Generator
96
+ module Doc
97
+ module Type
98
+ class #{@type.camelize} < AccountAttributeBase
99
+ def initialize
100
+ super
101
+ @type_name = '#{@type.camelize}'
102
+ @type = Awspec::Type::#{@type.camelize}.new
103
+ @ret = @type.resource_via_client
104
+ @matchers = []
105
+ @ignore_matchers = []
106
+ @describes = []
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ EOF
113
+ self.file_check_and_puts(path, content)
114
+ end
115
+
79
116
  def self.generate_resource_type_doc
80
117
  path = 'doc/_resource_types/' + @type.underscore + '.md'
81
118
  content = <<-"EOF"