Skip to content
Browse files

Merge pull request #74 from ohookins/s3_mfa_delete_versions

Add MFA credential support to S3 object version delete methods.
  • Loading branch information...
2 parents 455766c + 4df9ce5 commit 9efc7f7f921252bbd38b85bcdfad33dd682ec628 @trevorrowe trevorrowe committed Oct 8, 2012
View
3 lib/aws/s3/client.rb
@@ -953,8 +953,9 @@ def self.object_method(method_name, verb, *args, &block)
# @option options [required,String] :bucket_name
# @option options [required,String] :key
# @option options [String] :version_id
+ # @option options [String] :mfa
# @return [Core::Response]
- object_method(:delete_object, :delete) do
+ object_method(:delete_object, :delete, :header_options => { :mfa => "x-amz-mfa" }) do
configure_request do |req, options|
super(req, options)
View
9 lib/aws/s3/object_version.rb
@@ -94,9 +94,14 @@ def read options = {}, &block
end
# Deletes this object version from S3.
+ # @option options [String] :mfa The serial number and current token code of
+ # the Multi-Factor Authentication (MFA) device for the user. Format
+ # is "SERIAL TOKEN" - with a space between the serial and token.
# @return (see S3Object#delete)
- def delete
- object.delete(:version_id => @version_id)
+ def delete(options = {})
+ object.delete(:version_id => @version_id,
+ :mfa => options[:mfa]
+ )
end
# @return [Boolean] Returns this if this is the latest version of
View
5 lib/aws/s3/s3_object.rb
@@ -361,9 +361,12 @@ def server_side_encryption?
# if you use client-side encryption and the encryption materials
# were stored in a separate object in S3 (key.instruction).
#
+ # @option [String] :mfa The serial number and current token code of
+ # the Multi-Factor Authentication (MFA) device for the user. Format
+ # is "SERIAL TOKEN" - with a space between the serial and token.
+ #
# @return [nil]
def delete options = {}
-
client.delete_object(options.merge(
:bucket_name => bucket.name,
:key => key))
View
22 spec/aws/s3/client_spec.rb
@@ -341,6 +341,27 @@ def stub_response method, params, resp_data
end
+ shared_examples_for "accepts mfa credentials" do
+
+ it 'adds no header when mfa is nil' do
+ req_headers = nil
+ opts.delete(:mfa)
+ client.with_http_handler do |req, resp|
+ req_headers = req.headers
+ end.send(method, opts)
+ req_headers['x-amz-mfa'].should == nil
+ end
+
+ it 'adds a header when mfa is passed' do
+ req_headers = nil
+ client.with_http_handler do |req, resp|
+ req_headers = req.headers
+ end.send(method, opts.merge(:mfa => '123456 7890'))
+ req_headers['x-amz-mfa'].should == '123456 7890'
+ end
+
+ end
+
shared_examples_for "accepts version id" do
it 'adds no param wheren version_id is nil' do
@@ -1536,6 +1557,7 @@ def should_determine_content_length_for data, length
it_should_behave_like "accepts version id"
+ it_should_behave_like "accepts mfa credentials"
end
context '#delete_objects' do
View
6 spec/aws/s3/object_version_spec.rb
@@ -170,6 +170,12 @@ class S3
version.delete
end
+ it 'should call delete on the object with mfa credentials if specified' do
+ object.should_receive(:delete).
+ with(hash_including(:mfa => '123456 7890'))
+ version.delete(:mfa => '123456 7890')
+ end
+
end
context '#read' do

0 comments on commit 9efc7f7

Please sign in to comment.
Something went wrong with that request. Please try again.