1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[s3] rough first cut of get_bucket_object_versions

This commit is contained in:
geemus 2010-05-12 18:40:00 -07:00
parent 8e3464ebad
commit 51b8e4df58
4 changed files with 179 additions and 5 deletions

View file

@ -0,0 +1,88 @@
module Fog
module Parsers
module AWS
module S3
class GetBucketObjectVersions < Fog::Parsers::Base
def reset
@delete_marker = { 'Owner' => {} }
@version = { 'Owner' => {} }
@in_delete_marke = false
@in_version = false
@response = { 'Versions' => [] }
end
def start_element(name, attrs = [])
super
case name
when 'DeleteMarker'
@in_delete_marker = true
when 'Version'
@in_version = true
end
end
def end_element(name)
case name
when 'DeleteMarker'
@response['Versions'] << {'DeleteMarker' => @delete_marker }
@delete_marker = { 'Owner' => {} }
@in_delete_marker = false
when 'Version'
@response['Versions'] << {'Version' => @version }
@version = { 'Owner' => {} }
@in_version = false
when 'DisplayName', 'ID'
if @in_delete_marker
@delete_marker
elsif @in_version
@version
end['Owner'][name] = @value
when 'ETag'
@version[name] = @value.gsub('"', '')
when 'IsLatest'
if @in_delete_marker
@delete_marker
elsif @in_version
@version
end['IsLatest'] = if @value == 'true'
true
else
false
end
when 'IsTruncated'
if @value == 'true'
@response['IsTruncated'] = true
else
@response['IsTruncated'] = false
end
when 'LastModified'
if @in_delete_marker
@delete_marker
elsif @in_version
@version
end['LastModified'] = Time.parse(@value)
when 'KeyMarker', 'Name', 'Prefix', 'VersionIdMarker'
@response[name] = @value
when 'MaxKeys'
@response['MaxKeys'] = @value.to_i
when 'Size'
@version['Size'] = @value.to_i
when 'Key', 'Name', 'StorageClass', 'VersionId'
if @in_delete_marker
@delete_marker
elsif @in_version
@version
end[name] = @value
end
end
end
end
end
end
end

View file

@ -8,17 +8,18 @@ module Fog
# ==== Parameters
# * bucket_name<~String> - name of bucket to list object keys from
# * options<~Hash> - config arguments for list. Defaults to {}.
# * 'prefix'<~String> - limits object keys to those beginning with its value.
# * 'delimiter'<~String> - causes keys with the same string between the prefix
# value and the first occurence of delimiter to be rolled up
# * 'marker'<~String> - limits object keys to only those that appear
# lexicographically after its value.
# * 'max-keys'<~Integer> - limits number of object keys returned
# * 'delimiter'<~String> - causes keys with the same string between the prefix
# value and the first occurence of delimiter to be rolled up
# * 'prefix'<~String> - limits object keys to those beginning with its value.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'Delimeter'<~String> - Delimiter specified for query
# * 'IsTruncated'<~Boolean> - Whether or not the listing is truncated
# * 'Marker'<~String> - Marker specified for query
# * 'MaxKeys'<~Integer> - Maximum number of keys specified for query
# * 'Name'<~String> - Name of the bucket
@ -32,14 +33,14 @@ module Fog
# * 'ID'<~String> - Id of object owner
# * 'Size'<~Integer> - Size of object
# * 'StorageClass'<~String> - Storage class of object
#
def get_bucket(bucket_name, options = {})
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
options.reject! {|key, value| !['prefix', 'marker', 'max-keys', 'delimiter'].include?(key)}
query = ''
for key, value in options
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')};"
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
end
query.chop!
request({

View file

@ -0,0 +1,83 @@
module Fog
module AWS
module S3
class Real
# List information about object versions in an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to list object keys from
# * options<~Hash> - config arguments for list. Defaults to {}.
# * 'delimiter'<~String> - causes keys with the same string between the prefix
# value and the first occurence of delimiter to be rolled up
# * 'key-marker'<~String> - limits object keys to only those that appear
# lexicographically after its value.
# * 'max-keys'<~Integer> - limits number of object keys returned
# * 'prefix'<~String> - limits object keys to those beginning with its value.
# * 'version-id-marker'<~String> - limits object versions to only those that
# appear lexicographically after its value
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'Delimeter'<~String> - Delimiter specified for query
# * 'KeyMarker'<~String> - Key marker specified for query
# * 'MaxKeys'<~Integer> - Maximum number of keys specified for query
# * 'Name'<~String> - Name of the bucket
# * 'Prefix'<~String> - Prefix specified for query
# * 'VersionIdMarker'<~String> - Version id marker specified for query
# * 'IsTruncated'<~Boolean> - Whether or not this is the totality of the bucket
# * 'Versions'<~Array>:
# * 'DeleteMarker'<~Hash>:
# * 'IsLatest'<~Boolean> - Whether or not this is the latest version
# * 'Key'<~String> - Name of object
# * 'LastModified'<~String>: Timestamp of last modification of object
# * 'Owner'<~Hash>:
# * 'DisplayName'<~String> - Display name of object owner
# * 'ID'<~String> - Id of object owner
# * 'VersionId'<~String> - The id of this version
# or
# * 'Version'<~Hash>:
# * 'ETag'<~String>: Etag of object
# * 'IsLatest'<~Boolean> - Whether or not this is the latest version
# * 'Key'<~String> - Name of object
# * 'LastModified'<~String>: Timestamp of last modification of object
# * 'Owner'<~Hash>:
# * 'DisplayName'<~String> - Display name of object owner
# * 'ID'<~String> - Id of object owner
# * 'Size'<~Integer> - Size of object
# * 'StorageClass'<~String> - Storage class of object
# * 'VersionId'<~String> - The id of this version
#
def get_bucket_object_versions(bucket_name, options = {})
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
query = ''
for key, value in options
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
end
query.chop!
request({
:expects => 200,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketObjectVersions.new,
:query => query
})
end
end
class Mock
def get_bucket_object_versions(bucket_name, options = {})
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end
end

View file

@ -14,6 +14,7 @@ module Fog
require 'fog/aws/parsers/s3/get_bucket'
require 'fog/aws/parsers/s3/get_bucket_location'
require 'fog/aws/parsers/s3/get_bucket_logging'
require 'fog/aws/parsers/s3/get_bucket_object_versions'
require 'fog/aws/parsers/s3/get_bucket_versioning'
require 'fog/aws/parsers/s3/get_request_payment'
require 'fog/aws/parsers/s3/get_service'
@ -24,6 +25,7 @@ module Fog
require 'fog/aws/requests/s3/get_bucket_acl'
require 'fog/aws/requests/s3/get_bucket_location'
require 'fog/aws/requests/s3/get_bucket_logging'
require 'fog/aws/requests/s3/get_bucket_object_versions'
require 'fog/aws/requests/s3/get_bucket_versioning'
require 'fog/aws/requests/s3/get_object'
require 'fog/aws/requests/s3/get_object_acl'