mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2325 from rackspace/get_http_url
[rackspace|storage] implement get_http_url and get_https_url.
This commit is contained in:
commit
d0a3a3934f
8 changed files with 151 additions and 7 deletions
|
@ -160,6 +160,25 @@ module Fog
|
|||
directory.public?
|
||||
end
|
||||
|
||||
|
||||
# Get a url for file.
|
||||
#
|
||||
# required attributes: key
|
||||
#
|
||||
# @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires
|
||||
# @param options [Hash]
|
||||
# @return [String] url
|
||||
# @note This URL does not use the Rackspace CDN
|
||||
#
|
||||
def url(expires, options = {})
|
||||
requires :key
|
||||
if service.ssl?
|
||||
service.get_object_https_url(directory.key, key, expires, options)
|
||||
else
|
||||
service.get_object_http_url(directory.key, key, expires, options)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the public url for the file.
|
||||
# If the file has not been published to the CDN, this method will return nil as it is not publically accessible. This method will return the approprate
|
||||
# url in the following order:
|
||||
|
|
|
@ -137,6 +137,31 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
# Get a temporary http url for a file.
|
||||
#
|
||||
# required attributes: key
|
||||
# @param key [String] the key of the file within the directory
|
||||
# @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires
|
||||
# @param options [Hash]
|
||||
# @return [String] url
|
||||
# @note This URL does not use the Rackspace CDN
|
||||
def get_http_url(key, expires, options = {})
|
||||
requires :directory
|
||||
service.get_object_http_url(directory.key, key, expires, options)
|
||||
end
|
||||
|
||||
# Get a temporary https url for a file.
|
||||
#
|
||||
# required attributes: key
|
||||
# @param key [String] the key of the file within the directory
|
||||
# @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires
|
||||
# @param options [Hash]
|
||||
# @return [String] url
|
||||
# @note This URL does not use the Rackspace CDN
|
||||
def get_https_url(key, expires, options = {})
|
||||
service.get_object_https_url(directory.key, key, expires, options)
|
||||
end
|
||||
|
||||
# View directory detail without loading file contents
|
||||
# @param key of the object
|
||||
# @param options Required for compatibility with other Fog providers. Not Used.
|
||||
|
|
30
lib/fog/rackspace/requests/storage/get_object_http_url.rb
Normal file
30
lib/fog/rackspace/requests/storage/get_object_http_url.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class Rackspace
|
||||
|
||||
class Real
|
||||
|
||||
# Get an expiring object http url from Cloud Files
|
||||
#
|
||||
# ==== Parameters
|
||||
# * container<~String> - Name of container containing object
|
||||
# * object<~String> - Name of object to get expiring url for
|
||||
# * expires<~Time> - An expiry time for this url
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~String> - url for object
|
||||
# @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404
|
||||
# @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Storage::Rackspace::ServiceError]
|
||||
# ==== See Also
|
||||
# http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html
|
||||
def get_object_http_url(container, object, expires, options = {})
|
||||
get_object_https_url(container, object, expires, options.merge(:scheme => 'http'))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -34,7 +34,8 @@ module Fog
|
|||
hmac = Fog::HMAC.new('sha1', @rackspace_temp_url_key)
|
||||
sig = sig_to_hex(hmac.sign(string_to_sign))
|
||||
|
||||
"https://#{@uri.host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
|
||||
scheme = options[:scheme] ? options[:scheme] : @uri.scheme
|
||||
"#{scheme}://#{@uri.host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -31,6 +31,7 @@ module Fog
|
|||
request :get_containers
|
||||
request :get_object
|
||||
request :get_object_https_url
|
||||
request :get_object_http_url
|
||||
request :head_container
|
||||
request :head_containers
|
||||
request :head_object
|
||||
|
|
|
@ -56,10 +56,8 @@ Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
|||
:key => "fogfilestests-#{rand(65536)}"
|
||||
}
|
||||
|
||||
@directory = Fog::Storage[:rackspace].
|
||||
directories.
|
||||
create(directory_attributes)
|
||||
|
||||
@service = Fog::Storage.new :provider => 'rackspace', :rackspace_temp_url_key => "my_secret"
|
||||
@directory = @service.directories.create(directory_attributes)
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
|
@ -126,13 +124,28 @@ Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
|||
tests('urls') do
|
||||
tests('no CDN') do
|
||||
|
||||
tests('url') do
|
||||
tests('http').succeeds do
|
||||
expire_time = Time.now + 3600
|
||||
url = @instance.url(expire_time)
|
||||
url =~ /^http:/
|
||||
end
|
||||
tests('https').succeeds do
|
||||
@directory.service.instance_variable_set "@rackspace_cdn_ssl", true
|
||||
expire_time = Time.now + 3600
|
||||
url = @instance.url(expire_time)
|
||||
url =~ /^https:/
|
||||
end
|
||||
@directory.service.instance_variable_set "@rackspace_cdn_ssl", false
|
||||
end
|
||||
|
||||
tests('#public_url') do
|
||||
|
||||
tests('http').returns(nil) do
|
||||
@instance.public_url
|
||||
end
|
||||
|
||||
@directory.cdn_cname = "my_cname.com"
|
||||
@directory.cdn_cname = "my_cname.com"
|
||||
tests('cdn_cname').returns(nil) do
|
||||
@instance.public_url
|
||||
end
|
||||
|
@ -142,7 +155,7 @@ Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
|||
tests('ssl').returns(nil) do
|
||||
@instance.public_url
|
||||
end
|
||||
@directory.service.instance_variable_set "@rackspace_cdn_ssl", nil
|
||||
@directory.service.instance_variable_set "@rackspace_cdn_ssl", nil
|
||||
end
|
||||
|
||||
tests('#ios_url').returns(nil) do
|
||||
|
|
44
tests/rackspace/models/storage/files_tests.rb
Normal file
44
tests/rackspace/models/storage/files_tests.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
Shindo.tests("Fog::Rackspace::Storage | files", ['rackspace', 'storage']) do
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_files_tests',
|
||||
:body => lorem_file
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
:key => 'fogfilestests',
|
||||
:public => true
|
||||
}
|
||||
|
||||
|
||||
tests('success') do
|
||||
pending if Fog.mocking?
|
||||
collection_tests(Fog::Storage[:rackspace].directories.create(directory_attributes).files, file_attributes, false)
|
||||
|
||||
@service = Fog::Storage.new :provider => 'rackspace', :rackspace_temp_url_key => "my_secret"
|
||||
|
||||
@directory = @service.directories.create(directory_attributes)
|
||||
@file = @directory.files.create(file_attributes)
|
||||
|
||||
tests("#get_url('#{@directory.key}')").succeeds do
|
||||
@directory.files.get_url(@directory.key)
|
||||
end
|
||||
|
||||
tests("#get_http_url('#{@directory.key}')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
expire_time = Time.now + 3600
|
||||
@directory.files.get_http_url(@file.key, expire_time)
|
||||
end
|
||||
|
||||
tests("#get_https_url('#{@directory.key}', '#{@file.key}')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
expire_time = Time.now + 3600
|
||||
@directory.files.get_https_url(@file.key, expire_time)
|
||||
end
|
||||
|
||||
@file.destroy
|
||||
@directory.destroy
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -41,6 +41,17 @@ Shindo.tests('Fog::Storage[:rackspace] | object requests', ["rackspace"]) do
|
|||
Fog::Storage[:rackspace].delete_object('fogobjecttests', 'fog_object')
|
||||
end
|
||||
|
||||
# an object key with no special characters
|
||||
tests("#get_object_http_url('fogobjecttests', 'fog_object','expiration timestamp')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
|
||||
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
|
||||
storage.extend RackspaceStorageHelpers
|
||||
storage.override_path('/fake_version/fake_tenant')
|
||||
object_url = storage.get_object_http_url('fogobjecttests', 'fog_object', expires_at)
|
||||
object_url =~ /http:\/\/.*clouddrive.com\/[^\/]+\/[^\/]+\/fogobjecttests\/fog_object\?temp_url_sig=7e69a73092e333095a70b3be826a7350fcbede86&temp_url_expires=1344149532/
|
||||
end
|
||||
|
||||
# an object key with no special characters
|
||||
tests("#get_object_https_url('fogobjecttests', 'fog_object','expiration timestamp')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
|
|
Loading…
Add table
Reference in a new issue