Sha256: 816b4e1e47e4450341e84c46070e2a4db813d458f193ad9c34256a401cdb1472

Contents?: true

Size: 1.62 KB

Versions: 16

Compression:

Stored size: 1.62 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
        #
        # ==== 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   = "#{@path}/#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object,"/")}"
          object_path_unescaped = "#{@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))

          "https://#{@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

16 entries across 16 versions & 7 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-nirvanix-1.8.1 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-parser-fix-1.6.1 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-test-again-1.6.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-parser-fix-1.6.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-1.10.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-1.9.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.8.0.20130114204828 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.8.0.20130111070250 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.8.0.20130109172219 lib/fog/rackspace/requests/storage/get_object_https_url.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-sgonyea-1.8.1 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-1.8.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-1.7.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb
fog-1.6.0 lib/fog/rackspace/requests/storage/get_object_https_url.rb