awspec 0.69.1 → 0.70.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -30,10 +30,10 @@ Aws.config[:ecs] = {
30
30
  integer_value: 0,
31
31
  long_value: 0,
32
32
  string_set_value: %w[
33
- '2376',
34
- '22',
35
- '51678',
36
- '2375'
33
+ 2376
34
+ 22
35
+ 51678
36
+ 2375
37
37
  ]
38
38
  }
39
39
  ],
@@ -59,11 +59,11 @@ Aws.config[:ecs] = {
59
59
  integer_value: 0,
60
60
  long_value: 0,
61
61
  string_set_value: %w[
62
- '2376',
63
- '22',
64
- '80',
65
- '51678',
66
- '2375'
62
+ 2376
63
+ 22
64
+ 80
65
+ 51678
66
+ 2375
67
67
  ]
68
68
  }
69
69
  ],
@@ -6,8 +6,13 @@ module Awspec
6
6
  end
7
7
 
8
8
  desc 'template [resource_type_name]', 'Generate template files'
9
+ option :account_attribute, type: :boolean, default: false, aliases: :a
9
10
  def template(type)
10
- puts Awspec::Generator::Template.generate(type)
11
+ if options[:account_attribute]
12
+ puts Awspec::Generator::Template.generate_account_attribute(type)
13
+ else
14
+ puts Awspec::Generator::Template.generate(type)
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -0,0 +1,35 @@
1
+ module Awspec::Type
2
+ class Account < Base
3
+ REMOVE_SUFFIX_RE = /
4
+ _account_attributes|_account_settings|_send_quota
5
+ /ix
6
+
7
+ def resource_via_client
8
+ attributes = sts_client.get_caller_identity.to_h
9
+ Awspec::Helper::Type::ACCOUNT_ATTRIBUTES.each do |type|
10
+ key = type.gsub(REMOVE_SUFFIX_RE, '').to_sym
11
+ if key == 'ses'
12
+ # https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html
13
+ next unless ['us-east-1', 'us-west-2', 'eu-west-1'].include?(Aws.config[:region])
14
+ end
15
+ eval "attributes[key] = Awspec::Type::#{type.camelize}.new.resource_via_client"
16
+ end
17
+ @resource_via_client ||= attributes.to_struct
18
+ end
19
+
20
+ def id
21
+ @id ||= sts_client.get_caller_identity.account
22
+ end
23
+
24
+ def lambda
25
+ resource_via_client[:lambda]
26
+ end
27
+
28
+ def method_missing(name)
29
+ name = name.to_s if name.class == Symbol
30
+ describe = name.tr('-', '_').to_sym
31
+ super unless resource_via_client.members.include?(describe)
32
+ resource_via_client[describe]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ module Awspec::Type
2
+ class AccountAttribute < Base
3
+ def initialize(key = nil)
4
+ @key = key.to_sym
5
+ end
6
+
7
+ def resource_via_client
8
+ attributes = nil
9
+ Awspec::Helper::Type::ACCOUNT_ATTRIBUTES.each do |type|
10
+ key = type.gsub(Awspec::Type::Account::REMOVE_SUFFIX_RE, '').to_sym
11
+ next unless key == @key
12
+ if key == 'ses'
13
+ # https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html
14
+ next unless ['us-east-1', 'us-west-2', 'eu-west-1'].include?(Aws.config[:region])
15
+ end
16
+ eval "attributes = Awspec::Type::#{type.camelize}.new.resource_via_client"
17
+ end
18
+ @resource_via_client ||= attributes
19
+ end
20
+
21
+ def method_missing(name)
22
+ name = name.to_s if name.class == Symbol
23
+ describe = name.tr('-', '_').to_sym
24
+ super unless resource_via_client.members.include?(describe)
25
+ resource_via_client[describe]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module Awspec::Type
2
+ class AccountAttributeBase < Base
3
+ end
4
+ end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Acm < Base
2
+ class Acm < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_certificate(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Alb < Base
2
+ class Alb < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_alb(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Ami < Base
2
+ class Ami < ResourceBase
3
3
  aws_resource Aws::EC2::Image
4
4
 
5
5
  def resource_via_client
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class AutoscalingGroup < Base
2
+ class AutoscalingGroup < ResourceBase
3
3
  aws_resource Aws::AutoScaling::AutoScalingGroup
4
4
  tags_allowed
5
5
 
@@ -19,9 +19,10 @@ module Awspec::Type
19
19
 
20
20
  def has_ec2?(id)
21
21
  ec2 = find_ec2(id)
22
+ return nil unless ec2
22
23
  resource_via_client.instances.find do |instance|
23
24
  instance.instance_id = ec2.instance_id
24
- end if ec2
25
+ end
25
26
  end
26
27
  end
27
28
  end
@@ -6,12 +6,10 @@ module Awspec::Type
6
6
  class Base
7
7
  include Awspec::Helper::Finder
8
8
  include Awspec::BlackListForwardable
9
+ attr_accessor :account
9
10
 
10
- attr_reader :id, :resource_via_client
11
-
12
- def initialize(display_name = nil)
13
- @display_name = display_name
14
- @id = nil
11
+ def resource_via_client
12
+ raise 'this method must be override!'
15
13
  end
16
14
 
17
15
  def to_s
@@ -23,24 +21,6 @@ module Awspec::Type
23
21
  to_s
24
22
  end
25
23
 
26
- def exists?
27
- id
28
- end
29
-
30
- def id
31
- raise 'this method must be override!'
32
- end
33
-
34
- def resource_via_client
35
- raise 'this method must be override!'
36
- end
37
-
38
- def self.aws_resource(resource)
39
- define_method :resource do
40
- @resource ||= Awspec::ResourceReader.new(resource.new(id))
41
- end
42
- end
43
-
44
24
  def self.tags_allowed
45
25
  define_method :has_tag? do |key, value|
46
26
  begin
@@ -54,8 +34,9 @@ module Awspec::Type
54
34
  end
55
35
 
56
36
  def method_missing(name)
57
- describe = name.to_sym
58
- if resource_via_client.members.include?(describe)
37
+ name_str = name.to_s if name.class == Symbol
38
+ describe = name_str.tr('-', '_').to_sym
39
+ if !resource_via_client.nil? && resource_via_client.members.include?(describe)
59
40
  resource_via_client[describe]
60
41
  else
61
42
  super unless self.respond_to?(:resource)
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class CloudfrontDistribution < Base
2
+ class CloudfrontDistribution < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_cloudfront_distribution(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Cloudtrail < Base
2
+ class Cloudtrail < ResourceBase
3
3
  aws_resource Aws::CloudTrail
4
4
 
5
5
  def resource_via_client
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class CloudwatchAlarm < Base
2
+ class CloudwatchAlarm < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_cloudwatch_alarm(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class CloudwatchEvent < Base
2
+ class CloudwatchEvent < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_cloudwatch_event(@display_name)
5
5
  end
@@ -0,0 +1,27 @@
1
+ module Awspec::Type
2
+ class CloudwatchLogs < ResourceBase
3
+ def resource_via_client
4
+ @resource_via_client ||= find_cloudwatch_logs_group(@display_name)
5
+ end
6
+
7
+ def id
8
+ @id ||= resource_via_client.log_group_name if resource_via_client
9
+ end
10
+
11
+ def has_log_stream?(stream_name)
12
+ ret = find_cloudwatch_logs_stream_by_log_group_name(@id).log_stream_name
13
+ return true if ret == stream_name
14
+ end
15
+
16
+ def has_metric_filter?(filter_name)
17
+ ret = find_cloudwatch_logs_metric_fileter_by_log_group_name(@id, filter_name).filter_name
18
+ return true if ret == filter_name
19
+ end
20
+
21
+ def has_subscription_filter?(filter_name, pattern = nil)
22
+ ret = find_cloudwatch_logs_subscription_fileter_by_log_group_name(@id, filter_name)
23
+ return false unless ret.filter_pattern == pattern
24
+ return true if ret.filter_name == filter_name
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class CustomerGateway < Base
2
+ class CustomerGateway < ResourceBase
3
3
  tags_allowed
4
4
 
5
5
  def initialize(name)
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class DirectconnectVirtualInterface < Base
2
+ class DirectconnectVirtualInterface < ResourceBase
3
3
  def initialize(name)
4
4
  super
5
5
  @display_name = name
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Ebs < Base
2
+ class Ebs < ResourceBase
3
3
  aws_resource Aws::EC2::Volume
4
4
  tags_allowed
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Ec2 < Base
2
+ class Ec2 < ResourceBase
3
3
  aws_resource Aws::EC2::Instance
4
4
  tags_allowed
5
5
 
@@ -0,0 +1,7 @@
1
+ module Awspec::Type
2
+ class Ec2AccountAttributes < AccountAttributeBase
3
+ def resource_via_client
4
+ @resource_via_client ||= find_ec2_account_attributes
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class EcrRepository < Base
2
+ class EcrRepository < ResourceBase
3
3
  aws_resource Aws::ECR::Types::Repository
4
4
 
5
5
  def initialize(repository_name)
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class EcsCluster < Base
2
+ class EcsCluster < ResourceBase
3
3
  def initialize(name)
4
4
  super
5
5
  @display_name = name
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class EcsContainerInstance < Base
2
+ class EcsContainerInstance < ResourceBase
3
3
  attr_accessor :cluster
4
4
 
5
5
  def initialize(container_instance)
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class EcsService < Base
2
+ class EcsService < ResourceBase
3
3
  def initialize(service)
4
4
  super
5
5
  @display_name = service
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class EcsTaskDefinition < Base
2
+ class EcsTaskDefinition < ResourceBase
3
3
  def initialize(taskdef)
4
4
  super
5
5
  @display_name = taskdef
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Efs < Base
2
+ class Efs < ResourceBase
3
3
  def initialize(file_system_id)
4
4
  super
5
5
  @display_name = file_system_id
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Elasticache < Base
2
+ class Elasticache < ResourceBase
3
3
  def initialize(name)
4
4
  super
5
5
  @display_name = name
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class ElasticacheCacheParameterGroup < Base
2
+ class ElasticacheCacheParameterGroup < ResourceBase
3
3
  def initialize(name)
4
4
  super
5
5
  @display_name = name
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Elasticsearch < Base
2
+ class Elasticsearch < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_elasticsearch_domain(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class ElastictranscoderPipeline < Base
2
+ class ElastictranscoderPipeline < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_pipeline(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class Elb < Base
2
+ class Elb < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_elb(@display_name)
5
5
  end
@@ -21,9 +21,10 @@ module Awspec::Type
21
21
 
22
22
  def has_ec2?(id)
23
23
  ec2 = find_ec2(id)
24
+ return nil unless ec2
24
25
  resource_via_client.instances.find do |instance|
25
26
  instance.instance_id = ec2.instance_id
26
- end if ec2
27
+ end
27
28
  end
28
29
 
29
30
  def has_security_group?(sg_id)
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class IamGroup < Base
2
+ class IamGroup < ResourceBase
3
3
  aws_resource Aws::IAM::Group
4
4
 
5
5
  def resource_via_client
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class IamPolicy < Base
2
+ class IamPolicy < ResourceBase
3
3
  def resource_via_client
4
4
  @resource_via_client ||= find_iam_policy(@display_name)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class IamRole < Base
2
+ class IamRole < ResourceBase
3
3
  aws_resource Aws::IAM::Role
4
4
 
5
5
  def resource_via_client
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class IamUser < Base
2
+ class IamUser < ResourceBase
3
3
  aws_resource Aws::IAM::User
4
4
 
5
5
  def resource_via_client