Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rds snapshot improvements #269

Merged
merged 8 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/fog/aws/parsers/rds/modify_db_snapshot_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Fog
module Parsers
module AWS
module RDS
class ModifyDbSnapshotAttribute < Fog::Parsers::Base
def reset
@response = { 'ModifyDbSnapshotAttributeResult' => {}, 'ResponseMetadata' => {} }
end

def start_element(name, attrs = [])
super
end

def end_element(name)
case name
when 'RequestId'
@response['ResponseMetadata'][name] = value
end
end
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/fog/aws/rds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class AuthorizationAlreadyExists < Fog::Errors::Error; end
request :describe_db_snapshots
request :create_db_snapshot
request :delete_db_snapshot
request :modify_db_snapshot_attribute
request :copy_db_snapshot

request :create_db_parameter_group
request :delete_db_parameter_group
Expand Down
53 changes: 53 additions & 0 deletions lib/fog/aws/requests/rds/copy_db_snapshot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Fog
module AWS
class RDS
class Real
require 'fog/aws/parsers/rds/create_db_snapshot'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to re-use create parser, or should it have it's own?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your right it should have its own.


# Copy a db snapshot
#
# ==== Parameters
# * source_db_snapshot_identifier<~String> - Id of db snapshot
# * target_db_snapshot_identifier<~String> - Desired Id of the db snapshot copy
# * 'copy_tags'<~Boolean> - true to copy all tags from the source DB snapshot to the target DB snapshot; otherwise false.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
#
# {Amazon API Reference}[http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CopyDBSnapshot.html]
def copy_db_snapshot(source_db_snapshot_identifier, target_db_snapshot_identifier, copy_tags = false)
request(
'Action' => 'CopyDBSnapshot',
'SourceDBSnapshotIdentifier' => source_db_snapshot_identifier,
'TargetDBSnapshotIdentifier' => target_db_snapshot_identifier,
'CopyTags' => copy_tags,
:parser => Fog::Parsers::AWS::RDS::CreateDBSnapshot.new
)
end
end

class Mock
#
# Usage
#
# Fog::AWS[:rds].copy_db_snapshot("snap-original-id", "snap-backup-id", true)
#

def copy_db_snapshot(source_db_snapshot_identifier, target_db_snapshot_identifier, copy_tags = false)
response = Excon::Response.new
response.status = 200
snapshot_id = Fog::AWS::Mock.snapshot_id
data = {
'snapshotId' => snapshot_id,
}
self.data[:snapshots][snapshot_id] = data
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}.merge!(data)
response
end
end
end
end
end
32 changes: 32 additions & 0 deletions lib/fog/aws/requests/rds/modify_db_snapshot_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Fog
module AWS
class RDS
class Real
require 'fog/aws/parsers/rds/modify_db_snapshot_attribute'

# Modify db snapshot attributes
#
# ==== Parameters
# * db_snapshot_identifier<~String> - Id of snapshot to modify
# * attributes<~Hash>:
# * 'Add.MemberId'<~Array> - One or more account ids to grant rds create permission to
# * 'Remove.MemberId'<~Array> - One or more account ids to revoke rds create permission from
#
# {Amazon API Reference}[http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBSnapshotAttribute.html]
#
def modify_db_snapshot_attribute(db_snapshot_identifier, attributes)
params = {}
params.merge!(Fog::AWS.indexed_param('ValuesToAdd.member.%d', attributes['Add.MemberId'] || []))
params.merge!(Fog::AWS.indexed_param('ValuesToRemove.member.%d', attributes['Remove.MemberId'] || []))
request({
'Action' => 'ModifyDBSnapshotAttribute',
'DBSnapshotIdentifier' => db_snapshot_identifier,
:idempotent => true,
'AttributeName' => "restore",
:parser => Fog::Parsers::AWS::RDS::ModifyDbSnapshotAttribute.new
}.merge!(params))
end
end
end
end
end