2010-03-13 16:37:24 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-08 17:40:02 -04:00
|
|
|
class Storage
|
2010-03-13 16:37:24 -05:00
|
|
|
class Real
|
2009-08-08 15:31:32 -04:00
|
|
|
|
|
|
|
# Create an object in an S3 bucket
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * bucket_name<~String> - Name of bucket to create object in
|
|
|
|
# * object_name<~String> - Name of object to create
|
2009-09-09 23:44:28 -04:00
|
|
|
# * data<~File> - File or String to create object from
|
2009-08-08 15:31:32 -04:00
|
|
|
# * options<~Hash>:
|
|
|
|
# * 'Cache-Control'<~String> - Caching behaviour
|
|
|
|
# * 'Content-Disposition'<~String> - Presentational information for the object
|
|
|
|
# * 'Content-Encoding'<~String> - Encoding of object data
|
|
|
|
# * 'Content-Length'<~String> - Size of object in bytes (defaults to object.read.length)
|
|
|
|
# * 'Content-MD5'<~String> - Base64 encoded 128-bit MD5 digest of message (defaults to Base64 encoded MD5 of object.read)
|
|
|
|
# * 'Content-Type'<~String> - Standard MIME type describing contents (defaults to MIME::Types.of.first)
|
|
|
|
# * 'x-amz-acl'<~String> - Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
|
|
|
# * "x-amz-meta-#{name}" - Headers to be returned with object, note total size of request without body must be less than 8 KB.
|
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-08 15:31:32 -04:00
|
|
|
# * headers<~Hash>:
|
|
|
|
# * 'ETag'<~String> - etag of new object
|
2010-10-29 21:05:59 -04:00
|
|
|
#
|
|
|
|
# ==== See Also
|
|
|
|
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html
|
|
|
|
|
2009-09-08 23:33:37 -04:00
|
|
|
def put_object(bucket_name, object_name, data, options = {})
|
2010-06-12 18:31:17 -04:00
|
|
|
data = parse_data(data)
|
2009-09-08 23:33:37 -04:00
|
|
|
headers = data[:headers].merge!(options)
|
2009-08-08 15:31:32 -04:00
|
|
|
request({
|
2009-12-04 00:39:04 -05:00
|
|
|
:body => data[:body],
|
|
|
|
:expects => 200,
|
|
|
|
:headers => headers,
|
|
|
|
:host => "#{bucket_name}.#{@host}",
|
|
|
|
:idempotent => true,
|
|
|
|
:method => 'PUT',
|
|
|
|
:path => CGI.escape(object_name)
|
2009-08-08 15:31:32 -04:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
|
2010-03-13 16:37:24 -05:00
|
|
|
class Mock
|
2009-08-08 15:31:32 -04:00
|
|
|
|
2009-09-08 23:33:37 -04:00
|
|
|
def put_object(bucket_name, object_name, data, options = {})
|
2010-06-12 18:31:17 -04:00
|
|
|
data = parse_data(data)
|
2010-05-25 13:37:14 -04:00
|
|
|
unless data[:body].is_a?(String)
|
|
|
|
data[:body] = data[:body].read
|
|
|
|
end
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2010-03-13 16:37:24 -05:00
|
|
|
if (bucket = @data[:buckets][bucket_name])
|
2009-08-08 15:31:32 -04:00
|
|
|
response.status = 200
|
2009-08-16 14:45:52 -04:00
|
|
|
bucket[:objects][object_name] = {
|
2009-09-08 23:33:37 -04:00
|
|
|
:body => data[:body],
|
2009-08-14 12:18:55 -04:00
|
|
|
'ETag' => Fog::AWS::Mock.etag,
|
2009-08-08 15:31:32 -04:00
|
|
|
'Key' => object_name,
|
|
|
|
'LastModified' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000"),
|
2009-09-08 23:33:37 -04:00
|
|
|
'Size' => data[:headers]['Content-Length'],
|
2009-08-08 15:31:32 -04:00
|
|
|
'StorageClass' => 'STANDARD'
|
|
|
|
}
|
2009-09-08 23:33:37 -04:00
|
|
|
bucket[:objects][object_name]['Content-Type'] = data[:headers]['Content-Type']
|
2009-08-08 15:31:32 -04:00
|
|
|
else
|
2009-08-16 14:45:52 -04:00
|
|
|
response.status = 404
|
2009-11-20 14:08:08 -05:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-08-08 15:31:32 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|