diff --git a/lib/fog/openstack/models/storage/file.rb b/lib/fog/openstack/models/storage/file.rb index d2d0aa89a..6bf070610 100644 --- a/lib/fog/openstack/models/storage/file.rb +++ b/lib/fog/openstack/models/storage/file.rb @@ -65,15 +65,24 @@ module Fog new_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 + # + def url(expires, options = {}) + requires :directory, :key + self.service.create_temp_url_with_service_scheme(self.directory.key, self.key, expires, "GET", options = {}) + end + def public_url requires :key self.collection.get_url(self.key) end - def temp_signed_url(expires_secs, method) - requires :directory, :key - service.generate_object_temp_url(directory.key, key, expires_secs, method) - end def save(options = {}) requires :body, :directory, :key diff --git a/lib/fog/openstack/models/storage/files.rb b/lib/fog/openstack/models/storage/files.rb index 21d4f9589..1e6545996 100644 --- a/lib/fog/openstack/models/storage/files.rb +++ b/lib/fog/openstack/models/storage/files.rb @@ -71,6 +71,16 @@ module Fog end end + def get_http_url(key, expires, options = {}) + requires :directory + service.get_object_http_url(directory.key, key, expires, options) + end + + def get_https_url(key, expires, options = {}) + requires :directory + service.get_object_https_url(directory.key, key, expires, options) + end + def head(key, options = {}) requires :directory data = service.head_object(directory.key, key) diff --git a/lib/fog/openstack/requests/storage/get_object_https_url.rb b/lib/fog/openstack/requests/storage/get_object_https_url.rb index 10f224fad..d1a1f5dcf 100644 --- a/lib/fog/openstack/requests/storage/get_object_https_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_https_url.rb @@ -14,21 +14,33 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~String> - url for object - # - # ==== See Also - # http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html def get_object_https_url(container, object, expires, options = {}) create_temp_url(container, object, expires, "GET", "https", options) end - # Get an expiring object url from Cloud Files - # The function uses the scheme used by the storage object (http or https) + # Get an expiring object http url # # ==== Parameters # * container<~String> - Name of container containing object # * object<~String> - Name of object to get expiring url for - # * expires_secs<~Time> - The duration in seconds of the validity for the generated url - # * method<~String> - The name of the method to be accessible via the url ("GET", "PUT" or "HEAD") + # * expires<~Time> - An expiry time for this url + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~String> - url for object + def get_object_http_url(container, object, expires, options = {}) + create_temp_url(container, object, expires, "GET", "http", options) + end + + # creates a temporary url + # + # ==== 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 + # * 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 # # ==== Returns # * response<~Excon::Response>: @@ -36,21 +48,6 @@ module Fog # # ==== See Also # http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html - def generate_object_temp_url(container, object, expires_secs, method, options = {}) - expires = (Time.now + expires_secs.to_i).to_i - create_temp_url(container, object, expires, method, @scheme, options) - end - - private - - def sig_to_hex(str) - str.unpack("C*").map { |c| - c.to_s(16) - }.map { |h| - h.size == 1 ? "0#{h}" : h - }.join - end - def create_temp_url(container, object, expires, method, scheme, options = {}) raise ArgumentError, "Insufficient parameters specified." unless (container && object && expires && method) raise ArgumentError, "Storage must my instantiated with the :openstack_temp_url_key option" if @openstack_temp_url_key.nil? @@ -73,6 +70,21 @@ module Fog "#{scheme}://#{@host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}" end + + # Creates a temporary url using the scheme specified in the service configuration + def create_temp_url_with_service_scheme(container, object, expires, method, options = {}) + create_temp_url(container, object, expires, method, @scheme, options) + end + + private + + def sig_to_hex(str) + str.unpack("C*").map { |c| + c.to_s(16) + }.map { |h| + h.size == 1 ? "0#{h}" : h + }.join + end end