lib/fog/storage/aws.rb in fog-0.4.1 vs lib/fog/storage/aws.rb in fog-0.5.0

- old
+ new

@@ -19,11 +19,11 @@ class Storage < Fog::Service 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 collection :files model :file @@ -77,77 +77,96 @@ :headers => {} } 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 end def url(params, expires) params[:headers]['Date'] = expires.to_i + params[:path] = CGI.escape(params[:path]).gsub('%2F', '/') query = [params[:query]].compact query << "AWSAccessKeyId=#{@aws_access_key_id}" query << "Signature=#{CGI.escape(signature(params))}" query << "Expires=#{params[:headers]['Date']}" bucket = params[:host].split('.').first - path = CGI.escape(params[:path]).gsub('%2F', '/') - "https://#{@host}/#{path}?#{query.join('&')}" + "https://#{@host}/#{params[:path]}?#{query.join('&')}" end end class Mock include Utils def self.acls(type) case type when 'private' - @private ||= { + { "AccessControlList" => [ { "Permission" => "FULL_CONTROL", "Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"} } ], "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 def self.data @data ||= Hash.new do |hash, region|