lib/rack/simple_auth/hmac.rb in rack-simple_auth-0.1.3 vs lib/rack/simple_auth/hmac.rb in rack-simple_auth-0.1.4

- old
+ new

@@ -81,12 +81,14 @@ # @param [Fixnum] delay [delay in timestamp format] # @return [Hash] message [message which will be encrypted] def message(delay = 0) date = @date + delay date = date.to_i if delay.eql?(0.0) - puts "Delay: #{delay}, Timestamp: #{date}" + # Print out Delay and Timestamp for each range step in development environment + puts "Delay: #{delay}, Timestamp: #{date}" if ENV['RACK_ENV'].eql?('development') + case @request.request_method when 'GET' return { 'method' => @request.request_method, 'date' => date, 'data' => request_data(@config) }.to_json when 'POST' return { 'method' => @request.request_method, 'date' => date, 'data' => request_data(@config) }.to_json @@ -116,26 +118,24 @@ # - time when request was made # - type of request # - requested path def log(hash_array) if @logpath - log = "#{Time.new} - #{@request.request_method} #{@request.path} - 400 Unauthorized\n" - log << "HTTP_AUTHORIZATION: #{@request.env['HTTP_AUTHORIZATION']}\n" - log << "Auth Message Config: #{@config[@request.request_method]}\n" + msg = "#{Time.new} - #{@request.request_method} #{@request.path} - 400 Unauthorized\n" + msg << "HTTP_AUTHORIZATION: #{@request.env['HTTP_AUTHORIZATION']}\n" + msg << "Auth Message Config: #{@config[@request.request_method]}\n" if hash_array - log << "Allowed Encrypted Messages:\n" + msg << "Allowed Encrypted Messages:\n" hash_array.each do |hash| - log << "#{hash}\n" + msg << "#{hash}\n" end end - log << "Auth Signature: #{@signature}" + msg << "Auth Signature: #{@signature}" - open("#{@logpath}/#{ENV['RACK_ENV']}_error.log", 'a') do |f| - f << "#{log}\n" - end + Rack::SimpleAuth::Logger.log(@logpath, ENV['RACK_ENV'], msg) end end # Check if Stepsize is valid, if > min ensure stepsize is min stepsize # @param [float] min [minimum allowed stepsize] @@ -149,8 +149,8 @@ def valid_tolerance? if @tolerance < @steps fail "Tolerance must be greater than stepsize - Tolerance: #{@tolerance}, Stepsize: #{@steps}" end end - end - end -end + end # HMAC + end # SimpleAuth +end # Rack