Sha256: f7c6405a93f3eb23cf8b915740e414d0c24a940801ce8589fba97143b4a68951

Contents?: true

Size: 1.95 KB

Versions: 32

Compression:

Stored size: 1.95 KB

Contents

module Fog
  module Storage
    class Rackspace

      class Real

        # Get an expiring object https 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_https_url(container, object, expires, options = {})
          if @rackspace_temp_url_key.nil?
            raise ArgumentError, "Storage must my instantiated with the :rackspace_temp_url_key option"
          end

          method         = 'GET'
          expires        = expires.to_i
          object_path_escaped   = "#{@uri.path}/#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object,"/")}"
          object_path_unescaped = "#{@uri.path}/#{Fog::Rackspace.escape(container)}/#{object}"
          string_to_sign = "#{method}\n#{expires}\n#{object_path_unescaped}"

          hmac = Fog::HMAC.new('sha1', @rackspace_temp_url_key)
          sig  = sig_to_hex(hmac.sign(string_to_sign))

          scheme = options[:scheme] ? options[:scheme] : @uri.scheme
          "#{scheme}://#{@uri.host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
        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

    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
fog-maestrodev-1.19.0.20140212012611 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-1.19.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131209090811 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131206115947 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131205181604 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131127194823 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.18.0.20131126183714 lib/fog/rackspace/requests/storage/get_object_https_url.rb