mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Remove some files that were added during merge.
This commit is contained in:
parent
00e7b5c7e0
commit
625d5634b6
10 changed files with 0 additions and 858 deletions
|
@ -1,36 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
|
||||
class Version < Fog::Model
|
||||
|
||||
identity :version, :aliases => 'VersionId'
|
||||
|
||||
attribute :key, :aliases => 'Key'
|
||||
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified']
|
||||
attribute :latest, :aliases => 'IsLatest', :type => :boolean
|
||||
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
|
||||
attribute :delete_marker, :type => :boolean
|
||||
|
||||
def file
|
||||
@file ||= if collection.file
|
||||
collection.file.directory.files.get(key, 'versionId' => version)
|
||||
else
|
||||
collection.directory.files.get(key, 'versionId' => version)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if collection.file
|
||||
collection.service.delete_object(collection.file.directory.key, key, 'versionId' => version)
|
||||
else
|
||||
collection.service.delete_object(collection.directory.key, key, 'versionId' => version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/internet_archive/models/storage/version'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
|
||||
class Versions < Fog::Collection
|
||||
|
||||
attribute :file
|
||||
attribute :directory
|
||||
|
||||
model Fog::Storage::InternetArchive::Version
|
||||
|
||||
def all(options = {})
|
||||
data = if file
|
||||
service.get_bucket_object_versions(file.directory.key, options.merge('prefix' => file.key)).body['Versions']
|
||||
else
|
||||
service.get_bucket_object_versions(directory.key, options).body['Versions']
|
||||
end
|
||||
|
||||
load(data)
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
version_type = attributes.keys.first
|
||||
|
||||
model = super(attributes[version_type])
|
||||
model.delete_marker = version_type == 'DeleteMarker'
|
||||
|
||||
model
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,88 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Storage
|
||||
module InternetArchive
|
||||
|
||||
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 'MaxKeys'
|
||||
@response['MaxKeys'] = value.to_i
|
||||
when 'Size'
|
||||
@version['Size'] = value.to_i
|
||||
when 'Key', 'KeyMarker', 'Name', 'NextKeyMarker', 'NextVersionIdMarker', 'Prefix', 'StorageClass', 'VersionId', 'VersionIdMarker'
|
||||
if @in_delete_marker
|
||||
@delete_marker
|
||||
elsif @in_version
|
||||
@version
|
||||
else
|
||||
@response
|
||||
end[name] = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Storage
|
||||
module InternetArchive
|
||||
|
||||
class GetBucketVersioning < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'VersioningConfiguration' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Status', 'MfaDelete'
|
||||
@response['VersioningConfiguration'][name] = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,162 +0,0 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
class Real
|
||||
|
||||
require 'fog/internet_archive/parsers/storage/get_bucket_object_versions'
|
||||
|
||||
# List information about object versions in an S3 bucket
|
||||
#
|
||||
# @param bucket_name [String] name of bucket to list object keys from
|
||||
# @param options [Hash] config arguments for list
|
||||
# @option options delimiter [String] causes keys with the same string between the prefix value and the first occurence of delimiter to be rolled up
|
||||
# @option options key-marker [String] limits object keys to only those that appear lexicographically after its value.
|
||||
# @option options max-keys [Integer] limits number of object keys returned
|
||||
# @option options prefix [String] limits object keys to those beginning with its value.
|
||||
# @option options version-id-marker [String] limits object versions to only those that appear lexicographically after its value
|
||||
#
|
||||
# @return [Excon::Response] 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
|
||||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETVersion.html
|
||||
|
||||
def get_bucket_object_versions(bucket_name, options = {})
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Storage::InternetArchive::GetBucketObjectVersions.new,
|
||||
:query => {'versions' => nil}.merge!(options) })
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_bucket_object_versions(bucket_name, options = {})
|
||||
delimiter, key_marker, max_keys, prefix, version_id_marker = \
|
||||
options['delimiter'], options['key-marker'], options['max-keys'],options['prefix'],options['version-id-marker']
|
||||
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
# Invalid arguments.
|
||||
if version_id_marker && !key_marker
|
||||
response.status = 400
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'InvalidArgument',
|
||||
'Message' => 'A version-id marker cannot be specified without a key marker.',
|
||||
'ArgumentValue' => version_id_marker,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
# Valid case.
|
||||
# TODO: (nirvdrum 12/15/11) It's not clear to me how to actually use version-id-marker, so I didn't implement it below.
|
||||
elsif bucket = self.data[:buckets][bucket_name]
|
||||
# We need to order results by S3 key, but since our data store is key => [versions], we want to ensure the integrity
|
||||
# of the versions as well. So, sort the keys, then fetch the versions, and then combine them all as a sorted list by
|
||||
# flattening the results.
|
||||
contents = bucket[:objects].keys.sort.collect { |key| bucket[:objects][key] }.flatten.reject do |object|
|
||||
(prefix && object['Key'][0...prefix.length] != prefix) ||
|
||||
(key_marker && object['Key'] <= key_marker) ||
|
||||
(delimiter && object['Key'][(prefix ? prefix.length : 0)..-1].include?(delimiter) \
|
||||
&& common_prefixes << object['Key'].sub(/^(#{prefix}[^#{delimiter}]+.).*/, '\1'))
|
||||
end.map do |object|
|
||||
if object.has_key?(:delete_marker)
|
||||
tag_name = 'DeleteMarker'
|
||||
extracted_attrs = ['Key', 'VersionId']
|
||||
else
|
||||
tag_name = 'Version'
|
||||
extracted_attrs = ['ETag', 'Key', 'StorageClass', 'VersionId']
|
||||
end
|
||||
|
||||
data = {}
|
||||
data[tag_name] = object.reject { |key, value| !extracted_attrs.include?(key) }
|
||||
data[tag_name].merge!({
|
||||
'LastModified' => Time.parse(object['Last-Modified']),
|
||||
'Owner' => bucket['Owner'],
|
||||
'IsLatest' => object == bucket[:objects][object['Key']].first
|
||||
})
|
||||
|
||||
data[tag_name]['Size'] = object['Content-Length'].to_i if tag_name == 'Version'
|
||||
data
|
||||
end
|
||||
|
||||
max_keys = max_keys || 1000
|
||||
size = [max_keys, 1000].min
|
||||
truncated_contents = contents[0...size]
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'Versions' => truncated_contents,
|
||||
'IsTruncated' => truncated_contents.size != contents.size,
|
||||
'KeyMarker' => key_marker,
|
||||
'VersionIdMarker' => version_id_marker,
|
||||
'MaxKeys' => max_keys,
|
||||
'Name' => bucket['Name'],
|
||||
'Prefix' => prefix
|
||||
}
|
||||
if max_keys && max_keys < response.body['Versions'].length
|
||||
response.body['IsTruncated'] = true
|
||||
response.body['Versions'] = response.body['Versions'][0...max_keys]
|
||||
end
|
||||
|
||||
# Missing bucket case.
|
||||
else
|
||||
response.status = 404
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'NoSuchBucket',
|
||||
'Message' => 'The specified bucket does not exist',
|
||||
'BucketName' => bucket_name,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,69 +0,0 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
class Real
|
||||
|
||||
require 'fog/internet_archive/parsers/storage/get_bucket_versioning'
|
||||
|
||||
# Get versioning status for an S3 bucket
|
||||
#
|
||||
# @param bucket_name [String] name of bucket to get versioning status for
|
||||
#
|
||||
# @return [Excon::Response] response:
|
||||
# * body [Hash]:
|
||||
# * VersioningConfiguration [Hash]:
|
||||
# * Status [String] - Versioning status in ['Enabled', 'Suspended', nil]
|
||||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETversioningStatus.html
|
||||
|
||||
def get_bucket_versioning(bucket_name)
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Storage::InternetArchive::GetBucketVersioning.new,
|
||||
:query => {'versioning' => nil}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_bucket_versioning(bucket_name)
|
||||
response = Excon::Response.new
|
||||
bucket = self.data[:buckets][bucket_name]
|
||||
|
||||
if bucket
|
||||
response.status = 200
|
||||
|
||||
if bucket[:versioning]
|
||||
response.body = { 'VersioningConfiguration' => { 'Status' => bucket[:versioning] } }
|
||||
else
|
||||
response.body = { 'VersioningConfiguration' => {} }
|
||||
end
|
||||
|
||||
else
|
||||
response.status = 404
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'NoSuchBucket',
|
||||
'Message' => 'The specified bucket does not exist',
|
||||
'BucketName' => bucket_name,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,75 +0,0 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
class Real
|
||||
|
||||
# Change versioning status for an S3 bucket
|
||||
#
|
||||
# @param bucket_name [String] name of bucket to modify
|
||||
# @param status [String] Status to change to in ['Enabled', 'Suspended']
|
||||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTVersioningStatus.html
|
||||
|
||||
def put_bucket_versioning(bucket_name, status)
|
||||
data =
|
||||
<<-DATA
|
||||
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Status>#{status}</Status>
|
||||
</VersioningConfiguration>
|
||||
DATA
|
||||
|
||||
request({
|
||||
:body => data,
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'PUT',
|
||||
:query => {'versioning' => nil}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def put_bucket_versioning(bucket_name, status)
|
||||
response = Excon::Response.new
|
||||
bucket = self.data[:buckets][bucket_name]
|
||||
|
||||
if bucket
|
||||
if ['Enabled', 'Suspended'].include?(status)
|
||||
bucket[:versioning] = status
|
||||
|
||||
response.status = 200
|
||||
else
|
||||
response.status = 400
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'MalformedXML',
|
||||
'Message' => 'The XML you provided was not well-formed or did not validate against our published schema',
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
else
|
||||
response.status = 404
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'NoSuchBucket',
|
||||
'Message' => 'The specified bucket does not exist',
|
||||
'BucketName' => bucket_name,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,52 +0,0 @@
|
|||
Shindo.tests("Storage[:internet_archive] | version", ["internet_archive"]) do
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_file_tests',
|
||||
:body => lorem_file,
|
||||
:public => true
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
:key => 'fogfilestests'
|
||||
}
|
||||
|
||||
@directory = Fog::Storage[:internetarchive].directories.create(directory_attributes)
|
||||
@directory.versioning = true
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
@version_instance = @instance.versions.first
|
||||
@directory.connection.put_object(@directory.key, @instance.key, 'second version content')
|
||||
|
||||
tests("#file") do
|
||||
tests("#file should return the object associated with the version").returns(@version_instance.version) do
|
||||
@version_instance.file.version
|
||||
end
|
||||
end
|
||||
|
||||
tests("#delete_marker") do
|
||||
tests("#delete_marker should be false if the version isn't a DeleteMarker'").returns(false) do
|
||||
@version_instance.delete_marker
|
||||
end
|
||||
|
||||
tests("#delete_marker should be true if the version is a DeleteMarker'").returns(true) do
|
||||
@instance.destroy
|
||||
|
||||
@instance.versions.all.first.delete_marker
|
||||
end
|
||||
end
|
||||
|
||||
tests("#destroy") do
|
||||
tests("#destroy removes the specific version").returns(false) do
|
||||
@version_instance.destroy
|
||||
|
||||
@instance.versions.all.collect(&:version).include?(@version_instance.version)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@directory.versions.each(&:destroy)
|
||||
@directory.destroy
|
||||
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
Shindo.tests("Storage[:internet_archive] | versions", ["internet_archive"]) do
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_file_tests',
|
||||
:body => lorem_file,
|
||||
:public => true
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
:key => 'fogfilestests'
|
||||
}
|
||||
|
||||
model_tests(Fog::Storage[:internetarchive].directories, directory_attributes, Fog.mocking?) do
|
||||
@instance.versioning = true
|
||||
|
||||
versions = []
|
||||
versions << @instance.connection.put_object(@instance.key, 'one', 'abcde').headers['x-amz-version-id']
|
||||
|
||||
puts versions.first
|
||||
|
||||
versions << @instance.connection.put_object(@instance.key, 'one', '32423').headers['x-amz-version-id']
|
||||
versions << @instance.connection.delete_object(@instance.key, 'one').headers['x-amz-version-id']
|
||||
versions.reverse!
|
||||
|
||||
puts versions.first
|
||||
|
||||
versions << @instance.connection.put_object(@instance.key, 'two', 'aoeu').headers['x-amz-version-id']
|
||||
|
||||
tests('#versions') do
|
||||
tests('#versions.size includes versions (including DeleteMarkers) for all keys').returns(4) do
|
||||
@instance.versions.all.size
|
||||
end
|
||||
|
||||
tests('#versions returns the correct versions').returns(versions) do
|
||||
@instance.versions.all.collect(&:version)
|
||||
end
|
||||
end
|
||||
|
||||
tests("#all") do
|
||||
tests("#all for a directory returns all versions, regardless of key").returns(versions) do
|
||||
@instance.versions.all.collect(&:version)
|
||||
end
|
||||
|
||||
tests("#all for file returns only versions for that file").returns(1) do
|
||||
@instance.files.get('two').versions.all.collect(&:version).size
|
||||
end
|
||||
|
||||
tests("#all for file returns only versions for that file").returns(versions.last) do
|
||||
@instance.files.get('two').versions.all.collect(&:version).first
|
||||
end
|
||||
end
|
||||
|
||||
@instance.versions.each(&:destroy)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,258 +0,0 @@
|
|||
def clear_bucket
|
||||
Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name).body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, object['Key'], 'versionId' => object['VersionId'])
|
||||
end
|
||||
end
|
||||
|
||||
def create_versioned_bucket
|
||||
@ia_bucket_name = 'fogbuckettests-' + Fog::Mock.random_hex(16)
|
||||
Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Enabled')
|
||||
end
|
||||
|
||||
def delete_bucket
|
||||
Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name).body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, object['Key'], 'versionId' => object['VersionId'])
|
||||
end
|
||||
|
||||
Fog::Storage[:internetarchive].delete_bucket(@ia_bucket_name)
|
||||
end
|
||||
|
||||
Shindo.tests('Fog::Storage[:internetarchive] | versioning', ["internet_archive"]) do
|
||||
tests('success') do
|
||||
tests("#put_bucket_versioning") do
|
||||
@ia_bucket_name = 'fogbuckettests-' + Fog::Mock.random_hex(16)
|
||||
Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
|
||||
|
||||
tests("#put_bucket_versioning('#{@ia_bucket_name}', 'Enabled')").succeeds do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Enabled')
|
||||
end
|
||||
|
||||
tests("#put_bucket_versioning('#{@ia_bucket_name}', 'Suspended')").succeeds do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Suspended')
|
||||
end
|
||||
|
||||
delete_bucket
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}')") do
|
||||
@ia_bucket_name = 'fogbuckettests-' + Fog::Mock.random_hex(16)
|
||||
Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}') without versioning").returns({}) do
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning(@ia_bucket_name).body['VersioningConfiguration']
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}') with versioning enabled").returns('Enabled') do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Enabled')
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning(@ia_bucket_name).body['VersioningConfiguration']['Status']
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}') with versioning suspended").returns('Suspended') do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Suspended')
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning(@ia_bucket_name).body['VersioningConfiguration']['Status']
|
||||
end
|
||||
|
||||
delete_bucket
|
||||
end
|
||||
|
||||
tests("#get_bucket_object_versions('#{@ia_bucket_name}')") do
|
||||
|
||||
create_versioned_bucket
|
||||
|
||||
before do
|
||||
@versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
end
|
||||
|
||||
v1 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
v2 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'ab', :key => v1.key)
|
||||
v3 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'abc', :key => v1.key)
|
||||
v4 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'abcd', :key => v1.key)
|
||||
|
||||
tests("versions").returns([v4.version, v3.version, v2.version, v1.version]) do
|
||||
@versions.body['Versions'].collect {|v| v['Version']['VersionId']}
|
||||
end
|
||||
|
||||
tests("version sizes").returns([4, 3, 2, 1]) do
|
||||
@versions.body['Versions'].collect {|v| v['Version']['Size']}
|
||||
end
|
||||
|
||||
tests("latest version").returns(v4.version) do
|
||||
latest = @versions.body['Versions'].find {|v| v['Version']['IsLatest']}
|
||||
latest['Version']['VersionId']
|
||||
end
|
||||
end
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', 'file')") do
|
||||
clear_bucket
|
||||
|
||||
v1 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
v2 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'ab', :key => v1.key)
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', '#{v2.key}') returns the latest version").returns(v2.version) do
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, v2.key)
|
||||
res.headers['x-amz-version-id']
|
||||
end
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', '#{v1.key}', 'versionId' => '#{v1.version}') returns the specified version").returns(v1.version) do
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, v1.key, 'versionId' => v1.version)
|
||||
res.headers['x-amz-version-id']
|
||||
end
|
||||
|
||||
v2.destroy
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', '#{v2.key}') raises exception if delete marker is latest version").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].get_object(@ia_bucket_name, v2.key)
|
||||
end
|
||||
end
|
||||
|
||||
tests("delete_object('#{@ia_bucket_name}', 'file')") do
|
||||
clear_bucket
|
||||
|
||||
file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
|
||||
tests("deleting an object just stores a delete marker").returns(true) do
|
||||
file.destroy
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
versions.body['Versions'].first.has_key?('DeleteMarker')
|
||||
end
|
||||
|
||||
tests("there are two versions: the original and the delete marker").returns(2) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
versions.body['Versions'].size
|
||||
end
|
||||
|
||||
tests("deleting the delete marker makes the object available again").returns(file.version) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
delete_marker = versions.body['Versions'].find { |v| v.has_key?('DeleteMarker') }
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, file.key, 'versionId' => delete_marker['DeleteMarker']['VersionId'])
|
||||
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, file.key)
|
||||
res.headers['x-amz-version-id']
|
||||
end
|
||||
end
|
||||
|
||||
tests("deleting_multiple_objects('#{@ia_bucket_name}", 'file') do
|
||||
clear_bucket
|
||||
|
||||
bucket = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name)
|
||||
|
||||
file_count = 5
|
||||
file_names = []
|
||||
files = {}
|
||||
file_count.times do |id|
|
||||
file_names << "file_#{id}"
|
||||
files[file_names.last] = bucket.files.create(:body => 'a',
|
||||
:key => file_names.last)
|
||||
end
|
||||
|
||||
tests("deleting an object just stores a delete marker").returns(true) do
|
||||
Fog::Storage[:internetarchive].delete_multiple_objects(@ia_bucket_name,
|
||||
file_names)
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(
|
||||
@ia_bucket_name)
|
||||
all_versions = {}
|
||||
versions.body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
next if file_names.index(object['Key']).nil?
|
||||
if !all_versions.has_key?(object['Key'])
|
||||
all_versions[object['Key']] = version.has_key?('DeleteMarker')
|
||||
else
|
||||
all_versions[object['Key']] |= version.has_key?('DeleteMarker')
|
||||
end
|
||||
end
|
||||
all_true = true
|
||||
all_versions.values.each do |marker|
|
||||
all_true = false if !marker
|
||||
end
|
||||
all_true
|
||||
end
|
||||
|
||||
tests("there are two versions: the original and the delete marker").
|
||||
returns(file_count*2) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(
|
||||
@ia_bucket_name)
|
||||
versions.body['Versions'].size
|
||||
end
|
||||
|
||||
tests("deleting the delete marker makes the object available again").
|
||||
returns(true) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(
|
||||
@ia_bucket_name)
|
||||
delete_markers = []
|
||||
file_versions = {}
|
||||
versions.body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
next if object['VersionId'] == files[object['Key']].version
|
||||
file_versions[object['Key']] = object['VersionId']
|
||||
end
|
||||
|
||||
Fog::Storage[:internetarchive].delete_multiple_objects(@ia_bucket_name,
|
||||
file_names,
|
||||
'versionId' => file_versions)
|
||||
all_true = true
|
||||
file_names.each do |file|
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, file)
|
||||
all_true = false if res.headers['x-amz-version-id'] !=
|
||||
files[file].version
|
||||
end
|
||||
all_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests("get_bucket('#{@ia_bucket_name}'") do
|
||||
clear_bucket
|
||||
|
||||
file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
|
||||
tests("includes a non-DeleteMarker object").returns(1) do
|
||||
Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name).body['Contents'].size
|
||||
end
|
||||
|
||||
file.destroy
|
||||
|
||||
tests("does not include a DeleteMarker object").returns(0) do
|
||||
Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name).body['Contents'].size
|
||||
end
|
||||
end
|
||||
|
||||
delete_bucket
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
create_versioned_bucket
|
||||
|
||||
tests("#put_bucket_versioning('#{@ia_bucket_name}', 'bad_value')").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'bad_value')
|
||||
end
|
||||
|
||||
tests("#put_bucket_versioning('fognonbucket', 'Enabled')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning('fognonbucket', 'Enabled')
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('fognonbucket')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning('fognonbucket')
|
||||
end
|
||||
|
||||
tests("#get_bucket_object_versions('fognonbucket')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].get_bucket_object_versions('fognonbucket')
|
||||
end
|
||||
|
||||
file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'y', :key => 'x')
|
||||
|
||||
tests("#get_object('#{@ia_bucket_name}', '#{file.key}', 'versionId' => 'bad_version'").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:internetarchive].get_object(@ia_bucket_name, file.key, 'versionId' => '-1')
|
||||
end
|
||||
|
||||
tests("#delete_object('#{@ia_bucket_name}', '#{file.key}', 'versionId' => 'bad_version'").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, file.key, 'versionId' => '-1')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# don't keep the bucket around
|
||||
delete_bucket
|
||||
end
|
Loading…
Reference in a new issue