From eaae0d6b6c4c8a0c277f7ada396000a549859e3a Mon Sep 17 00:00:00 2001 From: Sandip Vavhal Date: Wed, 4 May 2022 18:45:12 +0530 Subject: [PATCH 1/2] Fixed rds and RDS Snapshot tags issue for AWS GovCloud Account regions. --- .../aws/requests/rds/add_tags_to_resource.rb | 35 +++++++++++++------ .../requests/rds/list_tags_for_resource.rb | 27 ++++++++++---- .../requests/rds/remove_tags_from_resource.rb | 17 ++++----- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/lib/fog/aws/requests/rds/add_tags_to_resource.rb b/lib/fog/aws/requests/rds/add_tags_to_resource.rb index 4ee57ddc9..bc27cfcfb 100644 --- a/lib/fog/aws/requests/rds/add_tags_to_resource.rb +++ b/lib/fog/aws/requests/rds/add_tags_to_resource.rb @@ -12,28 +12,43 @@ 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 + + def add_tags_to_dbsnapshot(snapshot_name, tags) + keys = tags.keys.sort + values = keys.map { |key| tags[key] } + resource_name = "arn:aws:rds:#{@region}:#{owner_id}:snapshot:#{snapshot_name}" + %w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name + request({ + '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 diff --git a/lib/fog/aws/requests/rds/list_tags_for_resource.rb b/lib/fog/aws/requests/rds/list_tags_for_resource.rb index c02d1e29c..0dc8849b2 100644 --- a/lib/fog/aws/requests/rds/list_tags_for_resource.rb +++ b/lib/fog/aws/requests/rds/list_tags_for_resource.rb @@ -11,27 +11,40 @@ 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 + + def list_tags_for_snapshot(snapshot_name) + resource_name = "arn:aws:rds:#{@region}:#{owner_id}:snapshot:#{snapshot_name}" + %w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name + request({ + 'Action' => 'ListTagsForResource', + 'ResourceName' => resource_name, + :parser => Fog::Parsers::AWS::RDS::TagListParser.new + }) + end end 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 diff --git a/lib/fog/aws/requests/rds/remove_tags_from_resource.rb b/lib/fog/aws/requests/rds/remove_tags_from_resource.rb index be84c17d9..9470367cf 100644 --- a/lib/fog/aws/requests/rds/remove_tags_from_resource.rb +++ b/lib/fog/aws/requests/rds/remove_tags_from_resource.rb @@ -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 From 6e66a3336eb132baa971136816da5b2175a9121c Mon Sep 17 00:00:00 2001 From: Sandip Vavhal Date: Thu, 5 May 2022 12:06:39 +0530 Subject: [PATCH 2/2] Removed rds snapshot changes. --- lib/fog/aws/requests/rds/add_tags_to_resource.rb | 13 ------------- lib/fog/aws/requests/rds/list_tags_for_resource.rb | 10 ---------- 2 files changed, 23 deletions(-) diff --git a/lib/fog/aws/requests/rds/add_tags_to_resource.rb b/lib/fog/aws/requests/rds/add_tags_to_resource.rb index bc27cfcfb..0a28fef0b 100644 --- a/lib/fog/aws/requests/rds/add_tags_to_resource.rb +++ b/lib/fog/aws/requests/rds/add_tags_to_resource.rb @@ -22,19 +22,6 @@ module Fog }.merge(Fog::AWS.indexed_param('Tags.member.%d.Key', keys)) .merge(Fog::AWS.indexed_param('Tags.member.%d.Value', values))) end - - def add_tags_to_dbsnapshot(snapshot_name, tags) - keys = tags.keys.sort - values = keys.map { |key| tags[key] } - resource_name = "arn:aws:rds:#{@region}:#{owner_id}:snapshot:#{snapshot_name}" - %w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name - request({ - '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 diff --git a/lib/fog/aws/requests/rds/list_tags_for_resource.rb b/lib/fog/aws/requests/rds/list_tags_for_resource.rb index 0dc8849b2..f46541c46 100644 --- a/lib/fog/aws/requests/rds/list_tags_for_resource.rb +++ b/lib/fog/aws/requests/rds/list_tags_for_resource.rb @@ -21,16 +21,6 @@ module Fog :parser => Fog::Parsers::AWS::RDS::TagListParser.new ) end - - def list_tags_for_snapshot(snapshot_name) - resource_name = "arn:aws:rds:#{@region}:#{owner_id}:snapshot:#{snapshot_name}" - %w[us-gov-west-1 us-gov-east-1].include?(@region) ? resource_name.insert(7, '-us-gov') : resource_name - request({ - 'Action' => 'ListTagsForResource', - 'ResourceName' => resource_name, - :parser => Fog::Parsers::AWS::RDS::TagListParser.new - }) - end end class Mock