Skip to content

Commit

Permalink
Merge pull request #548 from glasswalk3r/bugfix/issue_527
Browse files Browse the repository at this point in the history
Bugfix/issue 527
  • Loading branch information
k1LoW authored Sep 4, 2021
2 parents 343614d + be91bd2 commit 5676c92
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/awspec/stub/rds_db_parameter_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
{
parameter_name: 'max_allowed_packet',
parameter_value: '16777216'
},
{
parameter_name: 'rds.logical_replication',
parameter_value: '1'
},
{
parameter_name: 'rds.accepted_password_auth_method',
parameter_value: 'md5+scram'
}
]
}
Expand Down
54 changes: 54 additions & 0 deletions lib/awspec/type/rds_db_parameter_group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
module Awspec::Type
class InvalidRdsDbParameter < StandardError
##
# Overrides the superclass initialize method to include more information
# and default error message.
# Expected parameters:
# - parameter_name: the name of the parameter.

def initialize(parameter_name)
@param_name = parameter_name
message = "There is no such parameter \"rds.#{parameter_name}\""
super message
end
end

class RdsDBParameters
##
# Thanks to AWS for creating parameters names like
# 'rds.accepted_password_auth_method', which would be caught as method 'rds'
# by method_missing in RdsDbParameterGroup class, this class was created
# See https://github.com/k1LoW/awspec/issues/527 for more details
def initialize(params)
@params = params
end

def to_s
return "RdsDBParameters = #{@params}"
end

def method_missing(name)
param_name = name.to_sym
return @params[param_name] if @params.include?(param_name)
raise InvalidRdsDbParameter, name
end
end

class RdsDbParameterGroup < ResourceBase
def resource_via_client
return @resource_via_client if @resource_via_client
Expand All @@ -11,11 +46,30 @@ def id

def method_missing(name)
param_name = name.to_s
return create_rds_params if param_name == 'rds'

if resource_via_client.include?(param_name)
resource_via_client[param_name].to_s
else
super
end
end

private

def create_rds_params
return @rds_params if @rds_params

rds_params_keys = resource_via_client.keys.select { |key| key.to_s.start_with?('rds.') }
rds_params = {}

rds_params_keys.each do |key|
new_key = key.split('.')[-1]
rds_params[new_key.to_sym] = resource_via_client[key]
end

@rds_params = RdsDBParameters.new(rds_params)
@rds_params
end
end
end
3 changes: 3 additions & 0 deletions spec/type/rds_db_parameter_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
its(:basedir) { should eq '/rdsdbbin/mysql' }
its(:innodb_buffer_pool_size) { should eq '{DBInstanceClassMemory*3/4}' }
its(:max_allowed_packet) { should eq '16777216' }
its('rds.logical_replication') { should eq '1' }
its('rds.accepted_password_auth_method') { should eq 'md5+scram' }
its('rds.foobar') { will raise_error(Awspec::Type::InvalidRdsDbParameter) }
end

0 comments on commit 5676c92

Please sign in to comment.