Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add MFA authentication to S3 multiple object deletions. #79

Merged
merged 1 commit into from

3 participants

@ohookins

Self-explanatory. As discussed on the AWS forums - implementation is more or less identical to that suggested, and of course spec tests have been included.

Tests succeed and I have functionally tested that the behaviour is as expected.

@trevorrowe trevorrowe merged commit 2444349 into aws:master
@lsegal
Owner

Thank you for helping to improve the AWS SDK, @ohookins!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  lib/aws/s3/client.rb
@@ -1078,8 +1078,9 @@ def self.object_method(method_name, verb, *args, &block)
# @option options [required,String] :bucket_name
# @option options [required,Array<String>] :keys
# @option options [Boolean] :quiet (true)
+ # @option options [String] :mfa
# @return [Core::Response]
- bucket_method(:delete_objects, :post, 'delete', XML::DeleteObjects) do
+ bucket_method(:delete_objects, :post, 'delete', XML::DeleteObjects, :header_options => { :mfa => "x-amz-mfa" }) do
configure_request do |req, options|
super(req, options)
View
32 lib/aws/s3/object_collection.rb
@@ -116,13 +116,21 @@ def with_prefix prefix, mode = :replace
#
# bucket.objects.delete(to_delete)
#
- # @param [Mixed] objects One or more objects to delete. Each object
- # can be one of the following:
+ # @overload delete(objects)
+ # @param [Mixed] objects One or more objects to delete. Each object
+ # can be one of the following:
#
- # * An object key (string)
- # * A hash with :key and :version_id (for versioned objects)
- # * An {S3Object} instance
- # * An {ObjectVersion} instance
+ # * An object key (string)
+ # * A hash with :key and :version_id (for versioned objects)
+ # * An {S3Object} instance
+ # * An {ObjectVersion} instance
+ #
+ # @overload delete(objects, options)
+ # Deletes multiple objects, with additional options. The array can
+ # contain any of the types of objects the first method invocation style
+ # accepts.
+ # @param [Array] objects One or more objects to delete.
+ # @param [Hash] options Optional headers to pass on.
#
# @raise [BatchDeleteError] If any of the objects failed to delete,
# a BatchDeleteError will be raised with a summary of the errors.
@@ -131,6 +139,17 @@ def with_prefix prefix, mode = :replace
#
def delete *objects
+ # Detect and retrieve options from the end of the splat.
+ if
+ objects.size == 2 and
+ objects[0].is_a?(Array) and
+ objects[1].is_a?(Hash)
+ then
+ client_opts = objects.pop
+ else
+ client_opts = {}
+ end
+
objects = objects.flatten.collect do |obj|
case obj
when String then { :key => obj }
@@ -146,7 +165,6 @@ def delete *objects
end
batch_helper = BatchHelper.new(1000) do |batch|
- client_opts = {}
client_opts[:bucket_name] = bucket.name
client_opts[:quiet] = true
client_opts[:objects] = batch
View
2  spec/aws/s3/client_spec.rb
@@ -1568,6 +1568,8 @@ def should_determine_content_length_for data, length
it_should_behave_like "requires bucket_name"
+ it_should_behave_like "accepts mfa credentials"
+
#it_should_behave_like "an s3 http request", 'POST'
end
View
16 spec/aws/s3/object_collection_spec.rb
@@ -228,6 +228,22 @@ def stub_members(resp, quantity)
end
+ it 'uses an array of objects and hash of options when present' do
+
+ objects = ['key1','key2']
+ mfa = '123456 7890'
+
+ client.should_receive(:delete_objects).with(
+ :bucket_name => bucket.name,
+ :quiet => true,
+ :objects => [{:key => 'key1'}, {:key => 'key2'}],
+ :mfa => mfa).
+ and_return(delete_response)
+
+ collection.delete(objects, {:mfa => mfa})
+
+ end
+
end
context '#delete_if' do
Something went wrong with that request. Please try again.