Sha256: ab7675ff9323552331fd2c412d252f0f7e3082048b57eb9483d235a0737b5e71

Contents?: true

Size: 994 Bytes

Versions: 2

Compression:

Stored size: 994 Bytes

Contents

module Massive
  module Authenticators
    class S3
      def initialize(filename)
        @filename = filename
      end

      def url
        "https://#{Massive.storage_config[:directory]}.s3.amazonaws.com/#{@filename}#{authentication_params}"
      end

      private

      def authentication_params
        if Massive.storage_config[:key] && Massive.storage_config[:secret]
          "?Expires=#{expiration}&AWSAccessKeyId=#{Massive.storage_config[:key]}&Signature=#{signature}"
        end
      end

      def expiration
        @expiration ||= Time.now.to_i + Massive.storage_config[:expiration]
      end

      def signature
        CGI.escape(
          Base64.encode64(
            OpenSSL::HMAC.digest(
              OpenSSL::Digest.new('sha1'),
              Massive.storage_config[:secret],
              "GET\n\n\n#{expiration}\n/#{Massive.storage_config[:directory]}/#{@filename}".encode("UTF-8")
            )
          ).gsub("\n", "")
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
massive-0.4.0 lib/massive/authenticators/s3.rb
massive-0.3.0 lib/massive/authenticators/s3.rb