Sha256: f5dbb0c048738d9c89ad5ff1f9444711d2814e69afb6d91c77e80d15ffb43f50

Contents?: true

Size: 904 Bytes

Versions: 6

Compression:

Stored size: 904 Bytes

Contents

require 'base64'
require 'openssl'
require 'kanoko/errors'

module Kanoko
  class Configure
    attr_accessor :digest_func, :secret_key, :hash_proc

    # digest_func expect String
    # secret_key expect String
    # hash_proc expect Proc
    #
    # example:
    #   Kanoko.configure do |c|
    #     c.digest_func = "sha1"
    #     c.secret_key = "secret"
    #   end
    #   Kanoko.path_for(:resize, "100x100") #=> "/hashing_value/resize/100x100"
    def initialize
      @digest_func = ENV['KANOKO_DIGEST_FUNC']
      @secret_key = ENV['KANOKO_SECRET_KEY']
      @hash_proc = ->(*args){
        if @digest_func.nil? || @secret_key.nil?
          fail ConfigureError, "`digest_func' and `secret_key' must be set"
        end
        Base64.urlsafe_encode64(
          OpenSSL::HMAC.digest @digest_func,
          @secret_key,
          args.map(&:to_s).join(',')
        )
      }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kanoko-0.2.0 lib/kanoko/configure.rb
kanoko-0.1.3 lib/kanoko/configure.rb
kanoko-0.1.2 lib/kanoko/configure.rb
kanoko-0.1.1 lib/kanoko/configure.rb
kanoko-0.1.0 lib/kanoko/configure.rb
kanoko-0.0.4 lib/kanoko/configure.rb