mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Making it easier to get pre-signed head requests
Very similar to get_url. https://github.com/fog/fog-aws/issues/47
This commit is contained in:
parent
268a25ffe6
commit
2b677d4dbd
4 changed files with 52 additions and 0 deletions
|
@ -92,6 +92,11 @@ module Fog
|
||||||
service.get_object_https_url(directory.key, key, expires, options)
|
service.get_object_https_url(directory.key, key, expires, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def head_url(key, expires, options = {})
|
||||||
|
requires :directory
|
||||||
|
service.head_object_url(directory.key, key, expires, options)
|
||||||
|
end
|
||||||
|
|
||||||
def head(key, options = {})
|
def head(key, options = {})
|
||||||
requires :directory
|
requires :directory
|
||||||
data = service.head_object(directory.key, key, options)
|
data = service.head_object(directory.key, key, options)
|
||||||
|
|
40
lib/fog/aws/requests/storage/head_object_url.rb
Normal file
40
lib/fog/aws/requests/storage/head_object_url.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
module Fog
|
||||||
|
module Storage
|
||||||
|
class AWS
|
||||||
|
module HeadObjectUrl
|
||||||
|
def head_object_url(bucket_name, object_name, expires, options = {})
|
||||||
|
unless bucket_name
|
||||||
|
raise ArgumentError.new('bucket_name is required')
|
||||||
|
end
|
||||||
|
unless object_name
|
||||||
|
raise ArgumentError.new('object_name is required')
|
||||||
|
end
|
||||||
|
signed_url(options.merge({
|
||||||
|
:bucket_name => bucket_name,
|
||||||
|
:object_name => object_name,
|
||||||
|
:method => 'HEAD'
|
||||||
|
}), expires)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Real
|
||||||
|
# An expiring head request url from S3
|
||||||
|
#
|
||||||
|
# @param bucket_name [String] Name of bucket containing object
|
||||||
|
# @param object_name [String] Name of object to get expiring url for
|
||||||
|
# @param expires [Time] An expiry time for this url
|
||||||
|
#
|
||||||
|
# @return [Excon::Response] response:
|
||||||
|
# * body [String] - url for object
|
||||||
|
#
|
||||||
|
# @see http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
|
||||||
|
|
||||||
|
include HeadObjectUrl
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock # :nodoc:all
|
||||||
|
include HeadObjectUrl
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -88,6 +88,7 @@ module Fog
|
||||||
request :get_service
|
request :get_service
|
||||||
request :head_bucket
|
request :head_bucket
|
||||||
request :head_object
|
request :head_object
|
||||||
|
request :head_object_url
|
||||||
request :initiate_multipart_upload
|
request :initiate_multipart_upload
|
||||||
request :list_multipart_uploads
|
request :list_multipart_uploads
|
||||||
request :list_parts
|
request :list_parts
|
||||||
|
|
|
@ -118,6 +118,12 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do
|
||||||
(object_url =~ /http:\/\/#{Regexp.quote(@directory.identity)}\.s3\.amazonaws\.com\/fog_object/) != nil
|
(object_url =~ /http:\/\/#{Regexp.quote(@directory.identity)}\.s3\.amazonaws\.com\/fog_object/) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tests("#head_object_url('#{@directory.identity}', 'fog_object', expiration timestamp)").returns(true) do
|
||||||
|
object_url = Fog::Storage[:aws].head_object_url(@directory.identity, 'fog_object', (Time.now + 60))
|
||||||
|
puts object_url
|
||||||
|
(object_url =~ /https:\/\/#{Regexp.quote(@directory.identity)}\.s3\.amazonaws\.com\/fog_object/) != nil
|
||||||
|
end
|
||||||
|
|
||||||
tests("delete_multiple_objects('#{@directory.identity}', ['fog_object', 'fog_other_object'])").formats(@multiple_delete_format) do
|
tests("delete_multiple_objects('#{@directory.identity}', ['fog_object', 'fog_other_object'])").formats(@multiple_delete_format) do
|
||||||
Fog::Storage[:aws].delete_multiple_objects(@directory.identity, ['fog_object', 'fog_other_object']).body
|
Fog::Storage[:aws].delete_multiple_objects(@directory.identity, ['fog_object', 'fog_other_object']).body
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue