mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #3501 from biomancer/temp-url-options
Host and port options support for create_temp_url
This commit is contained in:
commit
ecc0b278ae
4 changed files with 36 additions and 14 deletions
|
@ -158,7 +158,7 @@ module Fog
|
|||
# * response<~Excon::Response>:
|
||||
# * body<~String> - url for object
|
||||
def get_object_https_url(container, object, expires, options = {})
|
||||
create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https"))
|
||||
create_temp_url(container, object, expires, "GET", {:port => 443}.merge(options).merge(:scheme => "https"))
|
||||
end
|
||||
|
||||
# Get an expiring object http url
|
||||
|
@ -172,7 +172,7 @@ module Fog
|
|||
# * response<~Excon::Response>:
|
||||
# * body<~String> - url for object
|
||||
def get_object_http_url(container, object, expires, options = {})
|
||||
create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http"))
|
||||
create_temp_url(container, object, expires, "GET", {:port => 80}.merge(options).merge(:scheme => "http"))
|
||||
end
|
||||
|
||||
# Get an object http url expiring in the given amount of seconds
|
||||
|
@ -197,8 +197,10 @@ module Fog
|
|||
# * object<~String> - Name of object to get expiring url for
|
||||
# * expires<~Time> - An expiry time for this url
|
||||
# * method<~String> - The method to use for accessing the object (GET, PUT, HEAD)
|
||||
# * scheme<~String> - The scheme to use (http, https)
|
||||
# * options<~Hash> - An optional options hash
|
||||
# * 'scheme'<~String> - The scheme to use (http, https)
|
||||
# * 'host'<~String> - The host to use
|
||||
# * 'port'<~Integer> - The port to use
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -214,6 +216,8 @@ module Fog
|
|||
|
||||
expires = expires.to_i
|
||||
scheme = options[:scheme] || @scheme
|
||||
host = options[:host] || @host
|
||||
port = options[:port] || @port
|
||||
|
||||
# do not encode before signature generation, encode after
|
||||
sig_path = "#{@path}/#{container}/#{object}"
|
||||
|
@ -226,7 +230,7 @@ module Fog
|
|||
# HP uses a different strategy to create the signature that is passed to swift than OpenStack.
|
||||
# As the HP provider is broadly used by OpenStack users the OpenStack strategy is applied when
|
||||
# the @os_account_meta_temp_url_key is given.
|
||||
if @os_account_meta_temp_url_key then
|
||||
if @os_account_meta_temp_url_key
|
||||
hmac = OpenSSL::HMAC.new(@os_account_meta_temp_url_key, OpenSSL::Digest::SHA1.new)
|
||||
signature= hmac.update(string_to_sign).hexdigest
|
||||
else
|
||||
|
@ -247,7 +251,14 @@ module Fog
|
|||
end
|
||||
|
||||
# generate the temp url using the signature and expiry
|
||||
"#{scheme}://#{@host}#{encoded_path}?temp_url_sig=#{signature}&temp_url_expires=#{expires}"
|
||||
temp_url_options = {
|
||||
:scheme => scheme,
|
||||
:host => host,
|
||||
:port => port,
|
||||
:path => encoded_path,
|
||||
:query => "temp_url_sig=#{signature}&temp_url_expires=#{expires}"
|
||||
}
|
||||
URI::Generic.build(temp_url_options).to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -286,6 +297,15 @@ module Fog
|
|||
@hp_secret_key = options[:hp_secret_key]
|
||||
@hp_tenant_id = options[:hp_tenant_id]
|
||||
@os_account_meta_temp_url_key = options[:os_account_meta_temp_url_key]
|
||||
|
||||
@hp_storage_uri = options[:hp_auth_uri]
|
||||
|
||||
uri = URI.parse(@hp_storage_uri)
|
||||
@host = uri.host
|
||||
@path = uri.path
|
||||
@persistent = options[:persistent] || false
|
||||
@port = uri.port
|
||||
@scheme = uri.scheme
|
||||
end
|
||||
|
||||
def data
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
# * response<~Excon::Response>:
|
||||
# * body<~String> - url for object
|
||||
def get_object_http_url(container, object, expires, options = {})
|
||||
create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http"))
|
||||
create_temp_url(container, object, expires, "GET", {:port => 80}.merge(options).merge(:scheme => "http"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
# * response<~Excon::Response>:
|
||||
# * body<~String> - url for object
|
||||
def get_object_https_url(container, object, expires, options = {})
|
||||
create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https"))
|
||||
create_temp_url(container, object, expires, "GET", {:port => 443}.merge(options).merge(:scheme => "https"))
|
||||
end
|
||||
|
||||
# creates a temporary url
|
||||
|
@ -23,8 +23,10 @@ module Fog
|
|||
# * object<~String> - Name of object to get expiring url for
|
||||
# * expires<~Time> - An expiry time for this url
|
||||
# * method<~String> - The method to use for accessing the object (GET, PUT, HEAD)
|
||||
# * scheme<~String> - The scheme to use (http, https)
|
||||
# * options<~Hash> - An optional options hash
|
||||
# * 'scheme'<~String> - The scheme to use (http, https)
|
||||
# * 'host'<~String> - The host to use
|
||||
# * 'port'<~Integer> - The port to use
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -37,6 +39,8 @@ module Fog
|
|||
raise ArgumentError, "Storage must be instantiated with the :openstack_temp_url_key option" if @openstack_temp_url_key.nil?
|
||||
|
||||
scheme = options[:scheme] || @scheme
|
||||
host = options[:host] || @host
|
||||
port = options[:port] || @port
|
||||
|
||||
# POST not allowed
|
||||
allowed_methods = %w{GET PUT HEAD}
|
||||
|
@ -54,13 +58,10 @@ module Fog
|
|||
|
||||
temp_url_options = {
|
||||
:scheme => scheme,
|
||||
:host => @host,
|
||||
:port => @port,
|
||||
:host => host,
|
||||
:port => port,
|
||||
:path => object_path_escaped,
|
||||
:query => URI.encode_www_form(
|
||||
:temp_url_sig => sig,
|
||||
:temp_url_expires => expires
|
||||
)
|
||||
:query => "temp_url_sig=#{sig}&temp_url_expires=#{expires}"
|
||||
}
|
||||
URI::Generic.build(temp_url_options).to_s
|
||||
end
|
||||
|
|
|
@ -40,6 +40,7 @@ if Fog.mock?
|
|||
:hp_secret_key => 'hp_secret_key',
|
||||
:hp_tenant_id => 'hp_tenant_id',
|
||||
:hp_avl_zone => 'hp_avl_zone',
|
||||
:hp_auth_uri => 'http://hp/v2.0/tokens',
|
||||
:os_account_meta_temp_url_key => 'os_account_meta_temp_url_key',
|
||||
:ibm_username => 'ibm_username',
|
||||
:ibm_password => 'ibm_password',
|
||||
|
|
Loading…
Add table
Reference in a new issue