Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add some basic versioning support

  • Loading branch information...
commit 12abdff5c4e54414b87ecc4cd6930a826ab7d832 1 parent 44b38f5
@dudeman authored
Showing with 49 additions and 0 deletions.
  1. +14 −0 lib/s3/right_s3.rb
  2. +35 −0 lib/s3/right_s3_interface.rb
View
14 lib/s3/right_s3.rb
@@ -170,6 +170,20 @@ def location
@location ||= @s3.interface.bucket_location(@name)
end
+ def versions
+ @s3.interface.bucket_versions(@name)
+ end
+
+ def versioning
+ @s3.interface.bucket_versioning(@name)
+ end
+
+ def versioning=(bool)
+ xmldoc = %Q{<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Status>#{bool ? 'Enabled' : 'Suspended'}</Status></VersioningConfiguration>}
+ @s3.interface.put_versioning(:bucket => @name, :xmldoc => xmldoc)
+ end
+
+
# Retrieves the logging configuration for a bucket.
# Returns a hash of {:enabled, :targetbucket, :targetprefix}
#
View
35 lib/s3/right_s3_interface.rb
@@ -111,6 +111,8 @@ def canonical_string(method, path, headers={}, expires=nil) # :nodoc:
out_string << '?torrent' if path[/[&?]torrent($|&|=)/]
out_string << '?location' if path[/[&?]location($|&|=)/]
out_string << '?logging' if path[/[&?]logging($|&|=)/] # this one is beta, no support for now
+ out_string << '?versioning' if path[/[&?]versioning($|&|=)/] # this one is beta, no support for now
+ out_string << '?versions' if path[/[&?]versions($|&|=)/] # this one is beta, no support for now
out_string
end
@@ -235,6 +237,39 @@ def bucket_location(bucket, headers={})
on_exception
end
+ # Retrieve bucket versioning
+ def bucket_versions(bucket, headers={})
+ req_hash = generate_rest_request('GET', headers.merge(:url=>"#{bucket}?versions"))
+ request_info(req_hash, S3HttpResponseBodyParser.new)
+ rescue
+ on_exception
+ end
+
+ # Retrieve bucket versioning
+ def bucket_versioning(bucket, headers={})
+ req_hash = generate_rest_request('GET', headers.merge(:url=>"#{bucket}?versioning"))
+ request_info(req_hash, S3HttpResponseBodyParser.new)
+ rescue
+ on_exception
+ end
+
+ # Sets versioning configuration for a bucket from the XML configuration document.
+ # params:
+ # :bucket
+ # :xmldoc
+ def put_versioning(params)
+ AwsUtils.mandatory_arguments([:bucket,:xmldoc], params)
+ AwsUtils.allow_only([:bucket,:xmldoc, :headers], params)
+ params[:headers] = {} unless params[:headers]
+ req_hash = generate_rest_request('PUT', params[:headers].merge(:url=>"#{params[:bucket]}?versioning", :data => params[:xmldoc]))
+ request_info(req_hash, S3HttpResponseBodyParser.new)
+ rescue
+ on_exception
+ end
+
+
+
+
# Retrieves the logging configuration for a bucket.
# Returns a hash of {:enabled, :targetbucket, :targetprefix}
#
Please sign in to comment.
Something went wrong with that request. Please try again.