1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

Merge pull request #643 from svavhal/us-gov-regions-rds-tags-fix

RDD tags issue in AWS GovCloud Account regions.
This commit is contained in:
Wesley Beary 2022-05-05 20:08:37 -05:00 committed by GitHub
commit d3dbe3a63a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 25 deletions

View file

@ -12,28 +12,30 @@ module Fog
# * body<~Hash>:
def add_tags_to_resource(rds_id, tags)
keys = tags.keys.sort
values = keys.map {|key| tags[key]}
values = keys.map { |key| tags[key] }
resource_name = "arn:aws:rds:#{@region}:#{owner_id}:db:#{rds_id}"
%w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name
request({
'Action' => 'AddTagsToResource',
'ResourceName' => "arn:aws:rds:#{@region}:#{owner_id}:db:#{rds_id}",
:parser => Fog::Parsers::AWS::RDS::Base.new,
}.merge(Fog::AWS.indexed_param('Tags.member.%d.Key', keys)).
merge(Fog::AWS.indexed_param('Tags.member.%d.Value', values)))
'Action' => 'AddTagsToResource',
'ResourceName' => resource_name,
:parser => Fog::Parsers::AWS::RDS::Base.new
}.merge(Fog::AWS.indexed_param('Tags.member.%d.Key', keys))
.merge(Fog::AWS.indexed_param('Tags.member.%d.Value', values)))
end
end
class Mock
def add_tags_to_resource(rds_id, tags)
response = Excon::Response.new
if server = self.data[:servers][rds_id]
self.data[:tags][rds_id].merge! tags
if server = data[:servers][rds_id]
data[:tags][rds_id].merge! tags
response.status = 200
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
else
raise Fog::AWS::RDS::NotFound.new("DBInstance #{rds_id} not found")
raise Fog::AWS::RDS::NotFound, "DBInstance #{rds_id} not found"
end
end
end

View file

@ -11,11 +11,14 @@ module Fog
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
def list_tags_for_resource(rds_id)
resource_name = "arn:aws:rds:#{@region}:#{owner_id}:db:#{rds_id}"
%w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name
request(
'Action' => 'ListTagsForResource',
'ResourceName' => "arn:aws:rds:#{@region}:#{owner_id}:db:#{rds_id}",
:parser => Fog::Parsers::AWS::RDS::TagListParser.new
'Action' => 'ListTagsForResource',
'ResourceName' => resource_name,
:parser => Fog::Parsers::AWS::RDS::TagListParser.new
)
end
end
@ -23,15 +26,15 @@ module Fog
class Mock
def list_tags_for_resource(rds_id)
response = Excon::Response.new
if server = self.data[:servers][rds_id]
if server = data[:servers][rds_id]
response.status = 200
response.body = {
"ListTagsForResourceResult" =>
{"TagList" => self.data[:tags][rds_id]}
'ListTagsForResourceResult' =>
{ 'TagList' => data[:tags][rds_id] }
}
response
else
raise Fog::AWS::RDS::NotFound.new("DBInstance #{rds_id} not found")
raise Fog::AWS::RDS::NotFound, "DBInstance #{rds_id} not found"
end
end
end

View file

@ -11,11 +11,12 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>:
def remove_tags_from_resource(rds_id, keys)
resource_name = "arn:aws:rds:#{@region}:#{owner_id}:db:#{rds_id}"
%w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name
request(
{ 'Action' => 'RemoveTagsFromResource',
'ResourceName' => "arn:aws:rds:#{@region}:#{owner_id}:db:#{rds_id}",
:parser => Fog::Parsers::AWS::RDS::Base.new,
}.merge(Fog::AWS.indexed_param('TagKeys.member.%d', keys))
{ 'Action' => 'RemoveTagsFromResource',
'ResourceName' => resource_name,
:parser => Fog::Parsers::AWS::RDS::Base.new }.merge(Fog::AWS.indexed_param('TagKeys.member.%d', keys))
)
end
end
@ -23,15 +24,15 @@ module Fog
class Mock
def remove_tags_from_resource(rds_id, keys)
response = Excon::Response.new
if server = self.data[:servers][rds_id]
keys.each {|key| self.data[:tags][rds_id].delete key}
if server = data[:servers][rds_id]
keys.each { |key| data[:tags][rds_id].delete key }
response.status = 200
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
else
raise Fog::AWS::RDS::NotFound.new("DBInstance #{rds_id} not found")
raise Fog::AWS::RDS::NotFound, "DBInstance #{rds_id} not found"
end
end
end