diff --git a/lib/fog/internet_archive/models/storage/directory.rb b/lib/fog/internet_archive/models/storage/directory.rb index dd9843d1e..8359b52e4 100644 --- a/lib/fog/internet_archive/models/storage/directory.rb +++ b/lib/fog/internet_archive/models/storage/directory.rb @@ -1,6 +1,5 @@ require 'fog/core/model' require 'fog/internet_archive/models/storage/files' -require 'fog/internet_archive/models/storage/versions' module Fog module Storage @@ -61,21 +60,6 @@ module Fog @payer = new_payer end - def versioning? - requires :key - data = service.get_bucket_versioning(key) - data.body['VersioningConfiguration']['Status'] == 'Enabled' - end - - def versioning=(new_versioning) - requires :key - service.put_bucket_versioning(key, new_versioning ? 'Enabled' : 'Suspended') - end - - def versions - @versions ||= Fog::Storage::InternetArchive::Versions.new(:directory => self, :service => service) - end - def public=(new_public) self.acl = new_public ? 'public-read' : 'private' new_public diff --git a/lib/fog/internet_archive/models/storage/file.rb b/lib/fog/internet_archive/models/storage/file.rb index a22bd056d..96b37ea05 100644 --- a/lib/fog/internet_archive/models/storage/file.rb +++ b/lib/fog/internet_archive/models/storage/file.rb @@ -1,5 +1,4 @@ require 'fog/core/model' -require 'fog/internet_archive/models/storage/versions' module Fog module Storage @@ -29,11 +28,6 @@ module Fog attribute :metadata attribute :owner, :aliases => 'Owner' - # I don't think IA supports these recent S3 headers - # attribute :storage_class, :aliases => ['x-amz-storage-class', 'StorageClass'] - # attribute :encryption, :aliases => 'x-amz-server-side-encryption' - # attribute :version, :aliases => 'x-amz-version-id' - # treat these differently attribute :collections attribute :subjects @@ -145,12 +139,10 @@ module Fog # required attributes: directory, key # # @param options [Hash] - # @option options versionId [] # @return [Boolean] true if successful # def destroy(options = {}) requires :directory, :key - # attributes[:body] = nil if options['versionId'] == version service.delete_object(directory.key, key, options) true end @@ -286,19 +278,6 @@ module Fog collection.get_url(key, expires, options) end - - # File version if exists or creates new version. - # @return [Fog::Storage::InternetArchive::Version] - # - def versions - @versions ||= begin - Fog::Storage::InternetArchive::Versions.new( - :file => self, - :service => service - ) - end - end - private def directory=(new_directory) diff --git a/lib/fog/internet_archive/models/storage/version.rb b/lib/fog/internet_archive/models/storage/version.rb deleted file mode 100644 index 33038b524..000000000 --- a/lib/fog/internet_archive/models/storage/version.rb +++ /dev/null @@ -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 diff --git a/lib/fog/internet_archive/models/storage/versions.rb b/lib/fog/internet_archive/models/storage/versions.rb deleted file mode 100644 index b430ec6ea..000000000 --- a/lib/fog/internet_archive/models/storage/versions.rb +++ /dev/null @@ -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 diff --git a/lib/fog/internet_archive/parsers/storage/get_bucket_object_versions.rb b/lib/fog/internet_archive/parsers/storage/get_bucket_object_versions.rb deleted file mode 100644 index 3bbf2c4f0..000000000 --- a/lib/fog/internet_archive/parsers/storage/get_bucket_object_versions.rb +++ /dev/null @@ -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 diff --git a/lib/fog/internet_archive/parsers/storage/get_bucket_versioning.rb b/lib/fog/internet_archive/parsers/storage/get_bucket_versioning.rb deleted file mode 100644 index 31df2e399..000000000 --- a/lib/fog/internet_archive/parsers/storage/get_bucket_versioning.rb +++ /dev/null @@ -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 diff --git a/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb b/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb index 54bab9e94..f795fc99c 100644 --- a/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb +++ b/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb @@ -34,14 +34,9 @@ module Fog def delete_multiple_objects(bucket_name, object_names, options = {}) data = "" data << "true" if options.delete(:quiet) - version_ids = options.delete('versionId') object_names.each do |object_name| data << "" data << "#{CGI.escapeHTML(object_name)}" - object_version = version_ids.nil? ? nil : version_ids[object_name] - if object_version - data << "#{CGI.escapeHTML(object_version)}" - end data << "" end data << "" @@ -71,12 +66,9 @@ module Fog if bucket = self.data[:buckets][bucket_name] response.status = 200 response.body = { 'DeleteResult' => [] } - version_ids = options.delete('versionId') object_names.each do |object_name| - object_version = version_ids.nil? ? nil : version_ids[object_name] response.body['DeleteResult'] << delete_object_helper(bucket, - object_name, - object_version) + object_name) end else response.status = 404 @@ -87,79 +79,13 @@ module Fog private - def delete_object_helper(bucket, object_name, version_id) + def delete_object_helper(bucket, object_name) response = { 'Deleted' => {} } - if bucket[:versioning] - bucket[:objects][object_name] ||= [] - - if version_id - version = bucket[:objects][object_name].find { |object| object['VersionId'] == version_id} - - # S3 special cases the 'null' value to not error out if no such version exists. - if version || (version_id == 'null') - bucket[:objects][object_name].delete(version) - bucket[:objects].delete(object_name) if bucket[:objects][object_name].empty? - - response['Deleted'] = { 'Key' => object_name, - 'VersionId' => version_id, - 'DeleteMarker' => 'true', - 'DeleteMarkerVersionId' => version_id - } - else - response = delete_error_body(object_name, - version_id, - 'InvalidVersion', - 'Invalid version ID specified') - end - else - delete_marker = { - :delete_marker => true, - 'Key' => object_name, - 'VersionId' => bucket[:versioning] == 'Enabled' ? Fog::Mock.random_base64(32) : 'null', - 'Last-Modified' => Fog::Time.now.to_date_header - } - - # When versioning is suspended, a delete marker is placed if the last object ID is not the value 'null', - # otherwise the last object is replaced. - if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].first['VersionId'] == 'null' - bucket[:objects][object_name].shift - end - - bucket[:objects][object_name].unshift(delete_marker) - - response['Deleted'] = { 'Key' => object_name, - 'VersionId' => delete_marker['VersionId'], - 'DeleteMarkerVersionId' => - delete_marker['VersionId'], - 'DeleteMarker' => 'true', - } - end - else - if version_id && version_id != 'null' - response = delete_error_body(object_name, - version_id, - 'InvalidVersion', - 'Invalid version ID specified') - response = invalid_version_id_payload(version_id) - else - bucket[:objects].delete(object_name) - response['Deleted'] = { 'Key' => object_name } - end - end + bucket[:objects].delete(object_name) + response['Deleted'] = { 'Key' => object_name } response end - def delete_error_body(key, version_id, message, code) - { - 'Error' => { - 'Code' => code, - 'Message' => message, - 'VersionId' => version_id, - 'Key' => key, - } - } - end - end end end diff --git a/lib/fog/internet_archive/requests/storage/delete_object.rb b/lib/fog/internet_archive/requests/storage/delete_object.rb index 237053097..a5a6eb46f 100644 --- a/lib/fog/internet_archive/requests/storage/delete_object.rb +++ b/lib/fog/internet_archive/requests/storage/delete_object.rb @@ -14,11 +14,7 @@ module Fog # @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectDELETE.html def delete_object(bucket_name, object_name, options = {}) - if version_id = options.delete('versionId') - path = "#{CGI.escape(object_name)}?versionId=#{CGI.escape(version_id)}" - else - path = CGI.escape(object_name) - end + path = CGI.escape(object_name) headers = options request({ @@ -40,56 +36,7 @@ module Fog if bucket = self.data[:buckets][bucket_name] response.status = 204 - version_id = options.delete('versionId') - - if bucket[:versioning] - bucket[:objects][object_name] ||= [] - - if version_id - version = bucket[:objects][object_name].find { |object| object['VersionId'] == version_id} - - # S3 special cases the 'null' value to not error out if no such version exists. - if version || (version_id == 'null') - bucket[:objects][object_name].delete(version) - bucket[:objects].delete(object_name) if bucket[:objects][object_name].empty? - - response.headers['x-amz-delete-marker'] = 'true' if version[:delete_marker] - response.headers['x-amz-version-id'] = version_id - else - response.status = 400 - response.body = invalid_version_id_payload(version_id) - raise(Excon::Errors.status_error({:expects => 200}, response)) - end - else - delete_marker = { - :delete_marker => true, - 'Key' => object_name, - 'VersionId' => bucket[:versioning] == 'Enabled' ? Fog::Mock.random_base64(32) : 'null', - 'Last-Modified' => Fog::Time.now.to_date_header - } - - # When versioning is suspended, a delete marker is placed if the last object ID is not the value 'null', - # otherwise the last object is replaced. - if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].first['VersionId'] == 'null' - bucket[:objects][object_name].shift - end - - bucket[:objects][object_name].unshift(delete_marker) - - response.headers['x-amz-delete-marker'] = 'true' - response.headers['x-amz-version-id'] = delete_marker['VersionId'] - end - else - if version_id && version_id != 'null' - response.status = 400 - response.body = invalid_version_id_payload(version_id) - raise(Excon::Errors.status_error({:expects => 200}, response)) - else - bucket[:objects].delete(object_name) - - response.headers['x-amz-version-id'] = 'null' - end - end + bucket[:objects].delete(object_name) else response.status = 404 raise(Excon::Errors.status_error({:expects => 204}, response)) @@ -97,21 +44,6 @@ module Fog response end - private - - def invalid_version_id_payload(version_id) - { - 'Error' => { - 'Code' => 'InvalidArgument', - 'Message' => 'Invalid version id specified', - 'ArgumentValue' => version_id, - 'ArgumentName' => 'versionId', - 'RequestId' => Fog::Mock.random_hex(16), - 'HostId' => Fog::Mock.random_base64(65) - } - } - end - end end end diff --git a/lib/fog/internet_archive/requests/storage/get_bucket_object_versions.rb b/lib/fog/internet_archive/requests/storage/get_bucket_object_versions.rb deleted file mode 100644 index 2405daafe..000000000 --- a/lib/fog/internet_archive/requests/storage/get_bucket_object_versions.rb +++ /dev/null @@ -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 diff --git a/lib/fog/internet_archive/requests/storage/get_bucket_versioning.rb b/lib/fog/internet_archive/requests/storage/get_bucket_versioning.rb deleted file mode 100644 index cbb64ae8f..000000000 --- a/lib/fog/internet_archive/requests/storage/get_bucket_versioning.rb +++ /dev/null @@ -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 diff --git a/lib/fog/internet_archive/requests/storage/get_object.rb b/lib/fog/internet_archive/requests/storage/get_object.rb index 2d0d68fde..08da8e7ce 100644 --- a/lib/fog/internet_archive/requests/storage/get_object.rb +++ b/lib/fog/internet_archive/requests/storage/get_object.rb @@ -13,7 +13,6 @@ module Fog # @option options If-None-Match [String] Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified) # @option options If-Unmodified-Since [Time] Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed). # @option options Range [String] Range of object to download - # @option options versionId [String] specify a particular version to retrieve # # @return [Excon::Response] response: # * body [String]- Contents of object @@ -34,9 +33,6 @@ module Fog end params = { :headers => {} } - if version_id = options.delete('versionId') - params[:query] = {'versionId' => version_id} - end params[:headers].merge!(options) if options['If-Modified-Since'] params[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header @@ -63,7 +59,6 @@ module Fog class Mock # :nodoc:all def get_object(bucket_name, object_name, options = {}, &block) - version_id = options.delete('versionId') unless bucket_name raise ArgumentError.new('bucket_name is required') @@ -77,7 +72,7 @@ module Fog if (bucket = self.data[:buckets][bucket_name]) object = nil if bucket[:objects].has_key?(object_name) - object = version_id ? bucket[:objects][object_name].find { |object| object['VersionId'] == version_id} : bucket[:objects][object_name].first + object = bucket[:objects][object_name].first end if (object && !object[:delete_marker]) @@ -98,8 +93,6 @@ module Fog end end - response.headers['x-amz-version-id'] = object['VersionId'] if bucket[:versioning] - body = object[:body] if options['Range'] # since AWS S3 itself does not support multiple range headers, we will use only the first @@ -122,20 +115,6 @@ module Fog end end end - elsif version_id && !object - response.status = 400 - response.body = { - 'Error' => { - 'Code' => 'InvalidArgument', - 'Message' => 'Invalid version id specified', - 'ArgumentValue' => version_id, - 'ArgumentName' => 'versionId', - 'RequestId' => Fog::Mock.random_hex(16), - 'HostId' => Fog::Mock.random_base64(65) - } - } - - raise(Excon::Errors.status_error({:expects => 200}, response)) else response.status = 404 response.body = "...NoSuchKey<\/Code>..." diff --git a/lib/fog/internet_archive/requests/storage/get_object_acl.rb b/lib/fog/internet_archive/requests/storage/get_object_acl.rb index 7c2dfac21..485002779 100644 --- a/lib/fog/internet_archive/requests/storage/get_object_acl.rb +++ b/lib/fog/internet_archive/requests/storage/get_object_acl.rb @@ -10,7 +10,6 @@ module Fog # @param bucket_name [String] name of bucket containing object # @param object_name [String] name of object to get access control list for # @param options [Hash] - # @option options versionId [String] specify a particular version to retrieve # # @return [Excon::Response] response: # * body [Hash]: @@ -37,9 +36,6 @@ module Fog raise ArgumentError.new('object_name is required') end query = {'acl' => nil} - if version_id = options.delete('versionId') - query['versionId'] = version_id - end request({ :expects => 200, :headers => {}, diff --git a/lib/fog/internet_archive/requests/storage/head_object.rb b/lib/fog/internet_archive/requests/storage/head_object.rb index 147a2541c..d4289b5e7 100644 --- a/lib/fog/internet_archive/requests/storage/head_object.rb +++ b/lib/fog/internet_archive/requests/storage/head_object.rb @@ -13,7 +13,6 @@ module Fog # @option options [String] If-None-Match Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified) # @option options [Time] If-Unmodified-Since Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed). # @option options [String] Range Range of object to download - # @option options [String] versionId specify a particular version to retrieve # # @return [Excon::Response] response: # * body [String] Contents of object @@ -32,9 +31,6 @@ module Fog unless object_name raise ArgumentError.new('object_name is required') end - if version_id = options.delete('versionId') - query = {'versionId' => version_id} - end headers = {} headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since'] headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since'] diff --git a/lib/fog/internet_archive/requests/storage/put_bucket_versioning.rb b/lib/fog/internet_archive/requests/storage/put_bucket_versioning.rb deleted file mode 100644 index aae56ecb9..000000000 --- a/lib/fog/internet_archive/requests/storage/put_bucket_versioning.rb +++ /dev/null @@ -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 - - #{status} - -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 diff --git a/lib/fog/internet_archive/requests/storage/put_object.rb b/lib/fog/internet_archive/requests/storage/put_object.rb index 0a3b4d81e..7e1b7793e 100644 --- a/lib/fog/internet_archive/requests/storage/put_object.rb +++ b/lib/fog/internet_archive/requests/storage/put_object.rb @@ -67,30 +67,16 @@ module Fog 'Key' => object_name, 'Last-Modified' => Fog::Time.now.to_date_header, 'Content-Length' => options['Content-Length'] || data[:headers]['Content-Length'], - 'StorageClass' => options['x-amz-storage-class'] || 'STANDARD', - 'VersionId' => bucket[:versioning] == 'Enabled' ? Fog::Mock.random_base64(32) : 'null' } for key, value in options case key - when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-MD5', 'Expires', /^x-amz-meta-/ + when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-MD5', 'Expires', /^x-amz-meta-/, /^x-archive-/ object[key] = value end end - if bucket[:versioning] - bucket[:objects][object_name] ||= [] - - # When versioning is suspended, putting an object will create a new 'null' version if the latest version - # is a value other than 'null', otherwise it will replace the latest version. - if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].first['VersionId'] == 'null' - bucket[:objects][object_name].shift - end - - bucket[:objects][object_name].unshift(object) - else - bucket[:objects][object_name] = [object] - end + bucket[:objects][object_name] = [object] response.headers = { 'Content-Length' => object['Content-Length'], @@ -99,7 +85,6 @@ module Fog 'Last-Modified' => object['Last-Modified'], } - response.headers['x-amz-version-id'] = object['VersionId'] if object['VersionId'] != 'null' else response.status = 404 raise(Excon::Errors.status_error({:expects => 200}, response)) diff --git a/lib/fog/internet_archive/requests/storage/put_object_acl.rb b/lib/fog/internet_archive/requests/storage/put_object_acl.rb index c63bacdca..c7163039d 100644 --- a/lib/fog/internet_archive/requests/storage/put_object_acl.rb +++ b/lib/fog/internet_archive/requests/storage/put_object_acl.rb @@ -24,16 +24,11 @@ module Fog # * Permission [String] Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP] # @param acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read'] # @param options [Hash] - # @option options versionId [String] specify a particular version to retrieve # # @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUTacl.html def put_object_acl(bucket_name, object_name, acl, options = {}) query = {'acl' => nil} - if version_id = options.delete('versionId') - query['versionId'] = version_id - end - data = "" headers = {} diff --git a/lib/fog/internet_archive/storage.rb b/lib/fog/internet_archive/storage.rb index e81abd210..6824001b8 100644 --- a/lib/fog/internet_archive/storage.rb +++ b/lib/fog/internet_archive/storage.rb @@ -33,9 +33,7 @@ module Fog request :get_bucket_lifecycle request :get_bucket_location request :get_bucket_logging - request :get_bucket_object_versions request :get_bucket_policy - request :get_bucket_versioning request :get_bucket_website request :get_object request :get_object_acl @@ -56,7 +54,6 @@ module Fog request :put_bucket_lifecycle request :put_bucket_logging request :put_bucket_policy - request :put_bucket_versioning request :put_bucket_website request :put_object request :put_object_acl diff --git a/tests/internet_archive/models/storage/directory_tests.rb b/tests/internet_archive/models/storage/directory_tests.rb index 7bfc236c5..1ddb0a38b 100644 --- a/tests/internet_archive/models/storage/directory_tests.rb +++ b/tests/internet_archive/models/storage/directory_tests.rb @@ -6,45 +6,45 @@ Shindo.tests("Storage[:internet_archive] | directory", ["internet_archive"]) do model_tests(Fog::Storage[:internetarchive].directories, directory_attributes, Fog.mocking?) do - tests("#versioning=") do - tests("#versioning=(true)").succeeds do - @instance.versioning = true - end + # tests("#versioning=") do + # tests("#versioning=(true)").succeeds do + # @instance.versioning = true + # end - tests("#versioning=(true) sets versioning to 'Enabled'").returns('Enabled') do - @instance.versioning = true - @instance.connection.get_bucket_versioning(@instance.key).body['VersioningConfiguration']['Status'] - end + # tests("#versioning=(true) sets versioning to 'Enabled'").returns('Enabled') do + # @instance.versioning = true + # @instance.connection.get_bucket_versioning(@instance.key).body['VersioningConfiguration']['Status'] + # end - tests("#versioning=(false)").succeeds do - (@instance.versioning = false).equal? false - end + # tests("#versioning=(false)").succeeds do + # (@instance.versioning = false).equal? false + # end - tests("#versioning=(false) sets versioning to 'Suspended'").returns('Suspended') do - @instance.versioning = false - @instance.connection.get_bucket_versioning(@instance.key).body['VersioningConfiguration']['Status'] - end - end + # tests("#versioning=(false) sets versioning to 'Suspended'").returns('Suspended') do + # @instance.versioning = false + # @instance.connection.get_bucket_versioning(@instance.key).body['VersioningConfiguration']['Status'] + # end + # end end model_tests(Fog::Storage[:internetarchive].directories, directory_attributes, Fog.mocking?) do - tests("#versioning?") do - tests("#versioning? false if not enabled").returns(false) do - @instance.versioning? - end + # tests("#versioning?") do + # tests("#versioning? false if not enabled").returns(false) do + # @instance.versioning? + # end - tests("#versioning? true if enabled").returns(true) do - @instance.connection.put_bucket_versioning(@instance.key, 'Enabled') - @instance.versioning? - end + # tests("#versioning? true if enabled").returns(true) do + # @instance.connection.put_bucket_versioning(@instance.key, 'Enabled') + # @instance.versioning? + # end - tests("#versioning? false if suspended").returns(false) do - @instance.connection.put_bucket_versioning(@instance.key, 'Suspended') - @instance.versioning? - end - end + # tests("#versioning? false if suspended").returns(false) do + # @instance.connection.put_bucket_versioning(@instance.key, 'Suspended') + # @instance.versioning? + # end + # end end diff --git a/tests/internet_archive/models/storage/files_tests.rb b/tests/internet_archive/models/storage/files_tests.rb index 711351f85..bce7a0913 100644 --- a/tests/internet_archive/models/storage/files_tests.rb +++ b/tests/internet_archive/models/storage/files_tests.rb @@ -11,46 +11,46 @@ Shindo.tests("Storage[:internet_archive] | files", ["internet_archive"]) do } @directory = Fog::Storage[:internetarchive].directories.create(directory_attributes) - @directory.versioning = true + # @directory.versioning = true model_tests(@directory.files, file_attributes, Fog.mocking?) do v1 = @instance.version - v2 = @directory.connection.put_object(@directory.key, @instance.key, 'version 2 content').headers['x-amz-version-id'] - v3 = @directory.connection.delete_object(@directory.key, @instance.key).headers['x-amz-version-id'] - v4 = @directory.connection.put_object(@directory.key, @instance.key, 'version 3 content').headers['x-amz-version-id'] + # v2 = @directory.connection.put_object(@directory.key, @instance.key, 'version 2 content').headers['x-amz-version-id'] + # v3 = @directory.connection.delete_object(@directory.key, @instance.key).headers['x-amz-version-id'] + # v4 = @directory.connection.put_object(@directory.key, @instance.key, 'version 3 content').headers['x-amz-version-id'] - tests("#get") do - tests("#get without version fetches the latest version").returns(v4) do - @directory.files.get(@instance.key).version - end + # tests("#get") do + # tests("#get without version fetches the latest version").returns(v4) do + # @directory.files.get(@instance.key).version + # end - tests("#get with version fetches that exact version").returns(v2) do - @directory.files.get(@instance.key, 'versionId' => v2).version - end + # tests("#get with version fetches that exact version").returns(v2) do + # @directory.files.get(@instance.key, 'versionId' => v2).version + # end - tests("#get with a deleted version returns nil").returns(nil) do - @directory.files.get(@instance.key, 'versionId' => v3) - end - end + # tests("#get with a deleted version returns nil").returns(nil) do + # @directory.files.get(@instance.key, 'versionId' => v3) + # end + # end - tests("#head") do - tests("#head without version fetches the latest version").returns(v4) do - @directory.files.head(@instance.key).version - end + # tests("#head") do + # tests("#head without version fetches the latest version").returns(v4) do + # @directory.files.head(@instance.key).version + # end - tests("#head with version fetches that exact version").returns(v2) do - @directory.files.head(@instance.key, 'versionId' => v2).version - end + # tests("#head with version fetches that exact version").returns(v2) do + # @directory.files.head(@instance.key, 'versionId' => v2).version + # end - tests("#head with a deleted version returns nil").returns(nil) do - @directory.files.head(@instance.key, 'versionId' => v3) - end - end + # tests("#head with a deleted version returns nil").returns(nil) do + # @directory.files.head(@instance.key, 'versionId' => v3) + # end + # end end - @directory.versions.each(&:destroy) - @directory.destroy + # @directory.versions.each(&:destroy) + # @directory.destroy end diff --git a/tests/internet_archive/models/storage/version_tests.rb b/tests/internet_archive/models/storage/version_tests.rb deleted file mode 100644 index 5ab35f2dd..000000000 --- a/tests/internet_archive/models/storage/version_tests.rb +++ /dev/null @@ -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 diff --git a/tests/internet_archive/models/storage/versions_tests.rb b/tests/internet_archive/models/storage/versions_tests.rb deleted file mode 100644 index 00c9e67ba..000000000 --- a/tests/internet_archive/models/storage/versions_tests.rb +++ /dev/null @@ -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