Sha256: cd9ad4edc50be50ab0e52a9729236a5e4456373e4406248d537d608066c3fbde
Contents?: true
Size: 803 Bytes
Versions: 7
Compression:
Stored size: 803 Bytes
Contents
module S3Relay class PrivateUrl < S3Relay::Base attr_reader :expires, :path def initialize(uuid, file, options={}) filename = Addressable::URI.escape(file).gsub("+", "%2B") @path = [uuid, filename].join("/") @expires = (options[:expires] || 10.minutes.from_now).to_i end def generate "#{public_url}?#{params}" end def public_url "#{endpoint}/#{path}" 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
7 entries across 7 versions & 2 rubygems