Sha256: 804e3df8ec6ea81075ff029fa0093dab725199fbe321a87a29f375b60758db01

Contents?: true

Size: 740 Bytes

Versions: 12

Compression:

Stored size: 740 Bytes

Contents

module S3Relay
  class PrivateUrl < S3Relay::Base

    attr_reader :expires, :path

    def initialize(uuid, file, options={})
      filename = URI.encode(file).gsub("+", "%2B")
      @path    = [uuid, filename].join("/")
      @expires = (options[:expires] || 10.minutes.from_now).to_i
    end

    def generate
      "#{endpoint}/#{path}?#{params}"
    end

    private

    def params
      [
        "AWSAccessKeyId=#{access_key_id}",
        "Expires=#{expires}",
        "Signature=#{signature}"
      ].join("&")
    end

    def signature
      string = "GET\n\n\n#{expires}\n/#{bucket}/#{path}"
      hmac   = OpenSSL::HMAC.digest(digest, secret_access_key, string)
      CGI.escape(Base64.encode64(hmac).strip)
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
s3_relay-0.5.1 lib/s3_relay/private_url.rb
s3_relay-0.5.0 lib/s3_relay/private_url.rb
s3_relay-0.4.2 lib/s3_relay/private_url.rb
s3_relay-0.4.1 lib/s3_relay/private_url.rb
s3_relay-0.4.0 lib/s3_relay/private_url.rb
s3_relay-0.3.2 lib/s3_relay/private_url.rb
s3_relay-0.3.1 lib/s3_relay/private_url.rb
s3_relay-0.3.0 lib/s3_relay/private_url.rb
s3_relay-0.2.0 lib/s3_relay/private_url.rb
s3_relay-0.1.0 lib/s3_relay/private_url.rb
s3_relay-0.0.3 lib/s3_relay/private_url.rb
s3_relay-0.0.2 lib/s3_relay/private_url.rb