diff --git a/lib/fog/storage/aws.rb b/lib/fog/storage/aws.rb index 065c6b3ff..abec06608 100644 --- a/lib/fog/storage/aws.rb +++ b/lib/fog/storage/aws.rb @@ -21,7 +21,7 @@ module Fog requires :aws_access_key_id, :aws_secret_access_key recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent recognizes :provider # remove post deprecation - + model_path 'fog/storage/models/aws' collection :directories model :directory @@ -79,14 +79,14 @@ module Fog if data.is_a?(String) metadata[:body] = data - metadata[:headers]['Content-Length'] = metadata[:body].size.to_s + metadata[:headers]['Content-Length'] = metadata[:body].size else filename = ::File.basename(data.path) unless (mime_types = MIME::Types.of(filename)).empty? metadata[:headers]['Content-Type'] = mime_types.first.content_type end metadata[:body] = data - metadata[:headers]['Content-Length'] = ::File.size(data.path).to_s + metadata[:headers]['Content-Length'] = ::File.size(data.path) end # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip metadata @@ -111,7 +111,7 @@ module Fog def self.acls(type) case type when 'private' - @private ||= { + { "AccessControlList" => [ { "Permission" => "FULL_CONTROL", @@ -121,32 +121,51 @@ module Fog "Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} } when 'public-read' - @public_read ||= begin - public_read = self.acls('private').dup - public_read['AccessControlList'] << { - "Permission" => "READ", - "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"} - } - public_read - end + { + "AccessControlList" => [ + { + "Permission" => "FULL_CONTROL", + "Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + }, + { + "Permission" => "READ", + "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"} + } + ], + "Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + } when 'public-read-write' - @public_read_write ||= begin - public_read_write = self.acls('public-read').dup - public_read_write['AccessControlList'] << { - "Permission" => "WRITE", - "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"} - } - public_read_write - end + { + "AccessControlList" => [ + { + "Permission" => "FULL_CONTROL", + "Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + }, + { + "Permission" => "READ", + "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"} + }, + { + "Permission" => "WRITE", + "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"} + } + ], + "Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + } when 'authenticated-read' - @authenticated_read ||= begin - authenticated_read = self.acls('private').dup - authenticated_read['AccessControlList'] << { - "Permission" => "READ", - "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"} - } - authenticated_read - end + { + "AccessControlList" => [ + { + "Permission" => "FULL_CONTROL", + "Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + }, + { + "Permission" => "READ", + "Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"} + } + ], + "Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + } end end diff --git a/lib/fog/storage/google.rb b/lib/fog/storage/google.rb index cb1473883..79dfe49f4 100644 --- a/lib/fog/storage/google.rb +++ b/lib/fog/storage/google.rb @@ -39,14 +39,14 @@ module Fog if data.is_a?(String) metadata[:body] = data - metadata[:headers]['Content-Length'] = metadata[:body].size.to_s + metadata[:headers]['Content-Length'] = metadata[:body].size else filename = ::File.basename(data.path) unless (mime_types = MIME::Types.of(filename)).empty? metadata[:headers]['Content-Type'] = mime_types.first.content_type end metadata[:body] = data - metadata[:headers]['Content-Length'] = ::File.size(data.path).to_s + metadata[:headers]['Content-Length'] = ::File.size(data.path) end # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip metadata @@ -70,7 +70,7 @@ module Fog def self.acls(type) case type when 'private' - @private ||= { + { "AccessControlList"=> [ { "Permission" => "FULL_CONTROL", @@ -80,32 +80,51 @@ module Fog "Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} } when 'public-read' - @public_read ||= begin - public_read = self.acls('private').dup - public_read['AccessControlList'] << { - "Permission" => "READ", - "Scope" => {"type" => "AllUsers"} - } - public_read - end + { + "AccessControlList"=> [ + { + "Permission" => "FULL_CONTROL", + "Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"} + }, + { + "Permission" => "READ", + "Scope" => {"type" => "AllUsers"} + } + ], + "Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + } when 'public-read-write' - @public_read_write ||= begin - public_read_write = self.acls('private').dup - public_read_write['AccessControlList'] << { - "Permission" => "WRITE", - "Scope" => {"type" => "AllUsers"} - } - public_read_write - end + { + "AccessControlList"=> [ + { + "Permission" => "FULL_CONTROL", + "Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"} + }, + { + "Permission" => "READ", + "Scope" => {"type" => "AllUsers"} + }, + { + "Permission" => "WRITE", + "Scope" => {"type" => "AllUsers"} + } + ], + "Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + } when 'authenticated-read' - @authenticated_read ||= begin - authenticated_read = self.acls('private').dup - authenticated_read['AccessControlList'] << { - "Permission" => "READ", - "Scope" => {"type" => "AllAuthenticatedUsers"} - } - authenticated_read - end + { + "AccessControlList"=> [ + { + "Permission" => "FULL_CONTROL", + "Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"} + }, + { + "Permission" => "READ", + "Scope" => {"type" => "AllAuthenticatedUsers"} + } + ], + "Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} + } end end diff --git a/lib/fog/storage/requests/aws/put_bucket.rb b/lib/fog/storage/requests/aws/put_bucket.rb index 604ab4ad1..30c3d91c1 100644 --- a/lib/fog/storage/requests/aws/put_bucket.rb +++ b/lib/fog/storage/requests/aws/put_bucket.rb @@ -44,13 +44,13 @@ DATA class Mock # :nodoc:all def put_bucket(bucket_name, options = {}) - if options['x-amz-acl'] - unless ['private', 'public-read', 'public-read-write', 'authenticated-read'] - raise Excon::Errors::BadRequest.new('invalid x-amz-acl') - else - @data[:acls][:bucket][bucket_name] = self.class.acls(options['x-amz-acl']) - end + acl = options['x-amz-acl'] || 'private' + if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl) + raise Excon::Errors::BadRequest.new('invalid x-amz-acl') + else + @data[:acls][:bucket][bucket_name] = self.class.acls(acl) end + response = Excon::Response.new response.status = 200 bucket = { diff --git a/lib/fog/storage/requests/aws/put_object.rb b/lib/fog/storage/requests/aws/put_object.rb index f96d96a7d..c2fc8d884 100644 --- a/lib/fog/storage/requests/aws/put_object.rb +++ b/lib/fog/storage/requests/aws/put_object.rb @@ -47,14 +47,14 @@ module Fog class Mock # :nodoc:all def put_object(bucket_name, object_name, data, options = {}) - if options['x-amz-acl'] - unless ['private', 'public-read', 'public-read-write', 'authenticated-read'] - raise Excon::Errors::BadRequest.new('invalid x-amz-acl') - else - @data[:acls][:object][bucket_name] ||= {} - @data[:acls][:object][bucket_name][object_name] = self.class.acls(options['x-amz-acl']) - end + acl = options['x-amz-acl'] || 'private' + if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl) + raise Excon::Errors::BadRequest.new('invalid x-amz-acl') + else + @data[:acls][:object][bucket_name] ||= {} + @data[:acls][:object][bucket_name][object_name] = self.class.acls(acl) end + data = parse_data(data) unless data[:body].is_a?(String) data[:body] = data[:body].read diff --git a/lib/fog/storage/requests/google/put_bucket.rb b/lib/fog/storage/requests/google/put_bucket.rb index c2efd067a..622fd2131 100644 --- a/lib/fog/storage/requests/google/put_bucket.rb +++ b/lib/fog/storage/requests/google/put_bucket.rb @@ -40,12 +40,11 @@ DATA class Mock def put_bucket(bucket_name, options = {}) - if options['x-goog-acl'] - unless ['private', 'public-read', 'public-read-write', 'authenticated-read'] - raise Excon::Errors::BadRequest.new('invalid x-goog-acl') - else - @data[:acls][:bucket][bucket_name] = self.class.acls(options['x-goog-acl']) - end + acl = options['x-goog-acl'] || 'private' + if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl) + raise Excon::Errors::BadRequest.new('invalid x-goog-acl') + else + @data[:acls][:bucket][bucket_name] = self.class.acls(options[acl]) end response = Excon::Response.new response.status = 200 diff --git a/lib/fog/storage/requests/google/put_object.rb b/lib/fog/storage/requests/google/put_object.rb index b79ab7f39..4296208f6 100644 --- a/lib/fog/storage/requests/google/put_object.rb +++ b/lib/fog/storage/requests/google/put_object.rb @@ -42,14 +42,14 @@ module Fog class Mock def put_object(bucket_name, object_name, data, options = {}) - if options['x-goog-acl'] - unless ['private', 'public-read', 'public-read-write', 'authenticated-read'] - raise Excon::Errors::BadRequest.new('invalid x-goog-acl') - else - @data[:acls][:object][bucket_name] ||= {} - @data[:acls][:object][bucket_name][object_name] = self.class.acls(options['x-goog-acl']) - end + acl = options['x-goog-acl'] || 'private' + if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl) + raise Excon::Errors::BadRequest.new('invalid x-goog-acl') + else + @data[:acls][:object][bucket_name] ||= {} + @data[:acls][:object][bucket_name][object_name] = self.class.acls(acl) end + data = parse_data(data) unless data[:body].is_a?(String) data[:body] = data[:body].read