Sha256: 0189db707558d08029c0b1a93c9b28ec4d303f8d25ca6e0483cd90c4caa82a32

Contents?: true

Size: 1.62 KB

Versions: 25

Compression:

Stored size: 1.62 KB

Contents

module Fog
  module Storage
    class OpenStack

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

25 entries across 25 versions & 7 rubygems

Version Path
cifrado-0.2.1 vendor/fog/lib/fog/openstack/requests/storage/get_object_https_url.rb
cifrado-0.2.0 vendor/fog/lib/fog/openstack/requests/storage/get_object_https_url.rb
gapinc-fog-1.12.1.2.1 lib/fog/openstack/requests/storage/get_object_https_url.rb
gapinc-fog-1.14.0 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-maestrodev-1.14.0.20130806165225 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.14.0 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.13.0 lib/fog/openstack/requests/storage/get_object_https_url.rb
gapinc-fog-1.12.1.2 lib/fog/openstack/requests/storage/get_object_https_url.rb
gapinc-fog-1.12.1.1 lib/fog/openstack/requests/storage/get_object_https_url.rb
gapinc-fog-1.12.1a lib/fog/openstack/requests/storage/get_object_https_url.rb
gapinc-fog-1.12.1 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.12.1 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.12.0 lib/fog/openstack/requests/storage/get_object_https_url.rb
hpfog-0.0.20 lib/fog/openstack/requests/storage/get_object_https_url.rb
vagrant-shell-0.2.6 vendor/bundle/gems/fog-1.10.1/lib/fog/openstack/requests/storage/get_object_https_url.rb
vagrant-shell-0.2.5 vendor/bundle/gems/fog-1.10.1/lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.11.1 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.11.0 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-1.10.1 lib/fog/openstack/requests/storage/get_object_https_url.rb
fog-test-me-1.10.0 lib/fog/openstack/requests/storage/get_object_https_url.rb