awspec 1.24.4 → 1.25.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03a271717bc3471b5109a4831bbb0941a1d2975b90ed04427fa304fb727c251b
4
- data.tar.gz: 3eff98cd7e63f51067739eebf9d8c94476b66469ea98b2148d96c9afec502c3d
3
+ metadata.gz: 5880815a36bbfbccb02df8a4977451509f8f44cbc641a844d07ac1b4d78b40d4
4
+ data.tar.gz: d85fa09ae26d042910cbb72faa602db6266dbe370af1e62b9fa06519ce77aa58
5
5
  SHA512:
6
- metadata.gz: 82d89949fa055cbcfda478ff3efa28259a70cf9dc37fba9ea2c9e861c6393e225c5d268b701acdd4c567b0878d4d06f3c2db692b554d41a9737cecac87cc6dab
7
- data.tar.gz: 9d5a864c8065cf512aabcb2c2dd8851510253d8486dc0d6653e5c53d4c50376ca9c53a4a7ad45db5c8841e38d6c210a6e14c90970fabb75e03a454f4730cdaf3
6
+ metadata.gz: 98528081727304b98a323c7469a79bd7876d185def31d3cfcf03b9ebc138df42d6126abe794cdaf00b138289209540b5a96a092ccd37c5482a579da95ae1a78c
7
+ data.tar.gz: 014e0bcfe3c67c4da754e2405e8545b0ed8d9544f1f9916f2adacb2c1cf7ec56b8f4d1227062d43ab4c44a942b9fcf1f6538930b84f694522ac2ad16e555a322
@@ -678,6 +678,15 @@ describe cloudwatch_logs('my-cloudwatch-logs-group') do
678
678
  it { should have_metric_filter('my-cloudwatch-logs-metric-filter') }
679
679
  end
680
680
  ```
681
+ or
682
+ ```ruby
683
+ describe cloudwatch_logs('my-cloudwatch-logs-group') do
684
+ it do
685
+ should have_metric_filter('my-cloudwatch-logs-metric-filter')
686
+ .filter_pattern('[date, error]')
687
+ end
688
+ end
689
+ ```
681
690
 
682
691
 
683
692
  ### have_subscription_filter
@@ -2222,7 +2231,7 @@ DOC
2222
2231
  end
2223
2232
  ```
2224
2233
 
2225
- ### its(:aws_account_id), its(:key_id), its(:arn), its(:creation_date), its(:enabled), its(:description), its(:key_usage), its(:key_state), its(:deletion_date), its(:valid_to), its(:origin), its(:custom_key_store_id), its(:cloud_hsm_cluster_id), its(:expiration_model), its(:key_manager), its(:customer_master_key_spec), its(:encryption_algorithms), its(:signing_algorithms), its(:multi_region), its(:multi_region_configuration), its(:pending_deletion_window_in_days)
2234
+ ### its(:aws_account_id), its(:key_id), its(:arn), its(:creation_date), its(:enabled), its(:description), its(:key_usage), its(:key_state), its(:deletion_date), its(:valid_to), its(:origin), its(:custom_key_store_id), its(:cloud_hsm_cluster_id), its(:expiration_model), its(:key_manager), its(:customer_master_key_spec), its(:key_spec), its(:encryption_algorithms), its(:signing_algorithms), its(:multi_region), its(:multi_region_configuration), its(:pending_deletion_window_in_days)
2226
2235
  ## <a name="lambda">lambda</a>
2227
2236
 
2228
2237
  Lambda resource type.
@@ -3559,7 +3568,7 @@ end
3559
3568
  ```
3560
3569
 
3561
3570
 
3562
- ### its(:availability_zone), its(:availability_zone_id), its(:available_ip_address_count), its(:cidr_block), its(:default_for_az), its(:map_public_ip_on_launch), its(:map_customer_owned_ip_on_launch), its(:customer_owned_ipv_4_pool), its(:state), its(:subnet_id), its(:vpc_id), its(:owner_id), its(:assign_ipv_6_address_on_creation), its(:ipv_6_cidr_block_association_set), its(:subnet_arn), its(:outpost_arn)
3571
+
3563
3572
  ### :unlock: Advanced use
3564
3573
 
3565
3574
  `subnet` can use `Aws::EC2::Subnet` resource (see http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Subnet.html).
@@ -1,29 +1,127 @@
1
+ require 'singleton'
2
+
1
3
  module Awspec::Helper
2
4
  module Finder
3
5
  module Subnet
4
- def find_subnet(subnet_id)
5
- res = ec2_client.describe_subnets({
6
- filters: [{ name: 'subnet-id', values: [subnet_id] }]
7
- })
8
- resource = res.subnets.single_resource(subnet_id)
9
- return resource if resource
10
- res = ec2_client.describe_subnets({
11
- filters: [{ name: 'tag:Name', values: [subnet_id] }]
12
- })
13
- resource = res.subnets.single_resource(subnet_id)
14
- return resource if resource
15
- res = ec2_client.describe_subnets({
16
- filters: [{ name: 'cidrBlock', values: [subnet_id] }]
17
- })
18
- res.subnets.single_resource(subnet_id)
6
+ # Implements in-memory cache for +AWS::Ec2::Client+ +describe_subnets+
7
+ # method.
8
+
9
+ # == Usage
10
+ # Includes {Singleton}[https://ruby-doc.org/stdlib-2.7.3/libdoc/singleton/rdoc/index.html]
11
+ # module, so use +instance+ instead of +new+ to get a instance.
12
+ #
13
+ # It is intended to be used internally by the +find_subnet+ function only.
14
+ #
15
+ # Many of the methods expect a symbol to search through the cache to
16
+ # avoid having to call +to_sym+ multiple times.
17
+
18
+ class SubnetCache
19
+ include Singleton
20
+
21
+ def initialize # :nodoc:
22
+ @by_tag_name = {}
23
+ @by_cidr = {}
24
+ @subnet_ids = {}
25
+ @ip_matcher = Regexp.new('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}$')
26
+ end
27
+
28
+ # Add a mapping of a CIDR to the respective subnet ID
29
+ def add_by_cidr(cidr, subnet_id)
30
+ key_sym = cidr.to_sym
31
+ @by_cidr[key_sym] = subnet_id.to_sym unless @by_cidr.key?(key_sym)
32
+ end
33
+
34
+ # Add a mapping of a tag to the respective subnet ID
35
+ def add_by_tag(tag, subnet_id)
36
+ key_sym = tag.to_sym
37
+ @by_tag_name[key_sym] = subnet_id.to_sym unless @by_tag_name.key?(key_sym)
38
+ end
39
+
40
+ # Add a +Aws::EC2::Types::Subnet+ instance to the cache, mapping it's ID
41
+ # to the instance itself.
42
+ def add_subnet(subnet)
43
+ key_sym = subnet.subnet_id.to_sym
44
+ @subnet_ids[key_sym] = subnet unless @subnet_ids.key?(key_sym)
45
+ end
46
+
47
+ # Check if a subnet ID (as a symbol) exists in the cache.
48
+ def has_subnet?(subnet_id_symbol)
49
+ @subnet_ids.key?(subnet_id_symbol)
50
+ end
51
+
52
+ # Return a +Aws::EC2::Types::Subnet+ that matches the given CIDR.
53
+ def subnet_by_cidr(cidr_symbol)
54
+ @subnet_ids[@by_cidr[cidr_symbol]]
55
+ end
56
+
57
+ # Return a +Aws::EC2::Types::Subnet+ that matches the given tag.
58
+ def subnet_by_tag(tag_symbol)
59
+ @subnet_ids[@by_tag_name[tag_symbol]]
60
+ end
61
+
62
+ # Return a +Aws::EC2::Types::Subnet+ that matches the given subnet ID.
63
+ def subnet_by_id(subnet_id_symbol)
64
+ @subnet_ids[subnet_id_symbol]
65
+ end
66
+
67
+ # Check if a given string looks like a IPv4 CIDR.
68
+ def is_cidr?(subnet_id)
69
+ @ip_matcher.match(subnet_id)
70
+ end
71
+
72
+ # Check if the cache was already initialized or not.
73
+ def empty?
74
+ @subnet_ids.empty?
75
+ end
76
+
77
+ # Return the cache as a string.
78
+ def to_s
79
+ "by tag name: #{@by_tag_name}, by CIDR: #{@by_cidr}"
80
+ end
19
81
  end
20
82
 
21
- def select_subnet_by_vpc_id(vpc_id)
22
- res = ec2_client.describe_subnets({
23
- filters: [{ name: 'vpc-id', values: [vpc_id] }]
24
- })
25
- res.subnets
83
+ # Try to locate a +Aws::EC2::Types::Subnet+ with a given subnet ID.
84
+ #
85
+ # A subnet ID might be multiple things, like the
86
+ # +Aws::EC2::Types::Subnet.subnet_id+, or a IPv4 CIDR or the value for the
87
+ # +Name+ tag associated with the subnet.
88
+ #
89
+ # Returns a instance of +Aws::EC2::Types::Subnet+ or +nil+.
90
+ def find_subnet(subnet_id)
91
+ cache = SubnetCache.instance
92
+
93
+ if cache.empty?
94
+ res = ec2_client.describe_subnets
95
+
96
+ res.subnets.each do |sub|
97
+ cache.add_by_cidr(sub.cidr_block, sub.subnet_id)
98
+ cache.add_subnet(sub)
99
+ next if sub.tags.empty?
100
+
101
+ sub.tags.each do |tag|
102
+ if tag[:key].eql?('Name')
103
+ cache.add_by_tag(tag[:value], sub.subnet_id)
104
+ break
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ id_key = subnet_id.to_sym
111
+ return cache.subnet_by_id(id_key) if subnet_id.start_with?('subnet-') && cache.has_subnet?(id_key)
112
+ return cache.subnet_by_cidr(id_key) if cache.is_cidr?(subnet_id) && cache.by_cidr.key?(id_key)
113
+ cache.subnet_by_tag(id_key)
26
114
  end
27
115
  end
116
+
117
+ # Search for the subnets associated with a given VPC ID.
118
+ #
119
+ # Returns an array of +Aws::EC2::Types::Subnet+ instances.
120
+ def select_subnet_by_vpc_id(vpc_id)
121
+ res = ec2_client.describe_subnets({
122
+ filters: [{ name: 'vpc-id', values: [vpc_id] }]
123
+ })
124
+ res.subnets
125
+ end
28
126
  end
29
127
  end
@@ -13,6 +13,14 @@ Aws.config[:rds] = {
13
13
  {
14
14
  parameter_name: 'max_allowed_packet',
15
15
  parameter_value: '16777216'
16
+ },
17
+ {
18
+ parameter_name: 'rds.logical_replication',
19
+ parameter_value: '1'
20
+ },
21
+ {
22
+ parameter_name: 'rds.accepted_password_auth_method',
23
+ parameter_value: 'md5+scram'
16
24
  }
17
25
  ]
18
26
  }
@@ -1,26 +1,33 @@
1
+ OWNER = '123456789'
2
+ REGION = 'us-east-1'
3
+ TOPIC_ARN = "arn:aws:sns:#{REGION}:#{OWNER}:foobar"
4
+ DISPLAY_NAME = 'Useless'
5
+ SUBSCRIBED = "arn:aws:sns:#{REGION}:#{OWNER}:Foobar:3dbf4999-b3e2-4345-bd11-c34c9784ecca"
6
+ ENDPOINT = "arn:aws:lambda:#{REGION}:#{OWNER}:function:foobar"
7
+
1
8
  Aws.config[:sns] = {
2
9
  stub_responses: {
3
10
  get_topic_attributes: {
4
11
  attributes: {
5
12
  # rubocop:disable LineLength
6
- 'Policy' => '{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:GetTopicAttributes\",\"SNS:SetTopicAttributes\",\"SNS:AddPermission\",\"SNS:RemovePermission\",\"SNS:DeleteTopic\",\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:Publish\",\"SNS:Receive\"],\"Resource\":\"arn:aws:sns:us-east-1:123456789:foobar-lambda-sample\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"123456789\"}}}]}',
7
- 'Owner' => '123456789',
13
+ 'Policy' => "{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:GetTopicAttributes\",\"SNS:SetTopicAttributes\",\"SNS:AddPermission\",\"SNS:RemovePermission\",\"SNS:DeleteTopic\",\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:Publish\",\"SNS:Receive\"],\"Resource\":\"arn:aws:sns:#{REGION}:#{OWNER}:foobar-lambda-sample\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"#{OWNER}\"}}}]}",
14
+ 'Owner' => OWNER,
8
15
  'SubscriptionsPending' => '0',
9
- 'TopicArn' => 'arn:aws:sns:us-east-1:123456789:foobar',
16
+ 'TopicArn' => TOPIC_ARN,
10
17
  'EffectiveDeliveryPolicy' => '{\"http\":{\"defaultHealthyRetryPolicy\":{\"minDelayTarget\":20,\"maxDelayTarget\":20,\"numRetries\":3,\"numMaxDelayRetries\":0,\"numNoDelayRetries\":0,\"numMinDelayRetries\":0,\"backoffFunction\":\"linear\"},\"disableSubscriptionOverrides\":false}}',
11
18
  'SubscriptionsConfirmed' => '1',
12
- 'DisplayName' => 'Useless',
19
+ 'DisplayName' => DISPLAY_NAME,
13
20
  'SubscriptionsDeleted' => '0'
14
21
  }
15
22
  },
16
23
  list_subscriptions_by_topic: {
17
24
  subscriptions: [
18
25
  {
19
- subscription_arn: 'arn:aws:sns:us-east-1:123456789:Foobar:3dbf4999-b3e2-4345-bd11-c34c9784ecca',
20
- owner: '123456789',
26
+ subscription_arn: SUBSCRIBED,
27
+ owner: OWNER,
21
28
  protocol: 'lambda',
22
- endpoint: 'arn:aws:lambda:us-east-1:123456789:function:foobar',
23
- topic_arn: 'arn:aws:sns:us-east-1:123456789:foobar'
29
+ endpoint: ENDPOINT,
30
+ topic_arn: TOPIC_ARN
24
31
  }
25
32
  ],
26
33
  next_token: nil
@@ -0,0 +1,13 @@
1
+ OWNER = '123456789'
2
+ REGION = 'us-east-1'
3
+ TOPIC_ARN = "arn:aws:sns:#{REGION}:#{OWNER}:invalid"
4
+ TOPIC_SUBS_ARN = "arn:aws:sns:us-east-1:#{OWNER}:Foobar:3dbf4999-b3e2-4345-bd11-c34c9784ecca"
5
+
6
+ Aws.config[:sns] = {
7
+ stub_responses: {
8
+ get_topic_attributes: Aws::SNS::Errors::NotFound.new(
9
+ TOPIC_ARN, 'no such topic'),
10
+ list_subscriptions_by_topic: Aws::SNS::Errors::NotFound.new(
11
+ TOPIC_SUBS_ARN, 'no such topic')
12
+ }
13
+ }
@@ -1,4 +1,39 @@
1
1
  module Awspec::Type
2
+ class InvalidRdsDbParameter < StandardError
3
+ ##
4
+ # Overrides the superclass initialize method to include more information
5
+ # and default error message.
6
+ # Expected parameters:
7
+ # - parameter_name: the name of the parameter.
8
+
9
+ def initialize(parameter_name)
10
+ @param_name = parameter_name
11
+ message = "There is no such parameter \"rds.#{parameter_name}\""
12
+ super message
13
+ end
14
+ end
15
+
16
+ class RdsDBParameters
17
+ ##
18
+ # Thanks to AWS for creating parameters names like
19
+ # 'rds.accepted_password_auth_method', which would be caught as method 'rds'
20
+ # by method_missing in RdsDbParameterGroup class, this class was created
21
+ # See https://github.com/k1LoW/awspec/issues/527 for more details
22
+ def initialize(params)
23
+ @params = params
24
+ end
25
+
26
+ def to_s
27
+ return "RdsDBParameters = #{@params}"
28
+ end
29
+
30
+ def method_missing(name)
31
+ param_name = name.to_sym
32
+ return @params[param_name] if @params.include?(param_name)
33
+ raise InvalidRdsDbParameter, name
34
+ end
35
+ end
36
+
2
37
  class RdsDbParameterGroup < ResourceBase
3
38
  def resource_via_client
4
39
  return @resource_via_client if @resource_via_client
@@ -11,11 +46,30 @@ module Awspec::Type
11
46
 
12
47
  def method_missing(name)
13
48
  param_name = name.to_s
49
+ return create_rds_params if param_name == 'rds'
50
+
14
51
  if resource_via_client.include?(param_name)
15
52
  resource_via_client[param_name].to_s
16
53
  else
17
54
  super
18
55
  end
19
56
  end
57
+
58
+ private
59
+
60
+ def create_rds_params
61
+ return @rds_params if @rds_params
62
+
63
+ rds_params_keys = resource_via_client.keys.select { |key| key.to_s.start_with?('rds.') }
64
+ rds_params = {}
65
+
66
+ rds_params_keys.each do |key|
67
+ new_key = key.split('.')[-1]
68
+ rds_params[new_key.to_sym] = resource_via_client[key]
69
+ end
70
+
71
+ @rds_params = RdsDBParameters.new(rds_params)
72
+ @rds_params
73
+ end
20
74
  end
21
75
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '1.24.4'
2
+ VERSION = '1.25.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.24.4
4
+ version: 1.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -645,6 +645,7 @@ files:
645
645
  - lib/awspec/stub/security_group.rb
646
646
  - lib/awspec/stub/ses_identity.rb
647
647
  - lib/awspec/stub/sns_topic.rb
648
+ - lib/awspec/stub/sns_topic_error.rb
648
649
  - lib/awspec/stub/sqs.rb
649
650
  - lib/awspec/stub/ssm_parameter.rb
650
651
  - lib/awspec/stub/subnet.rb