<commit_before>require 'openssl'
require 'base64'
require 'digest/md5'
require 'time'


def logentries_login(le_user, le_password, request)
  # https://logentries.com/doc/webhookalert/
  #
  
  
  payload_md5 = Base64.encode64(Digest::MD5.digest(request.body.read)).strip

  @auth ||= Rack::Auth::Basic::Request.new(request.env)

  return false unless @auth.provided? && @auth.credentials 
 
  request_signature = @auth.credentials[1] 
  request_user = @auth.credentials[0]

  return false unless request_user == le_user

  canonical  = [
    "POST",
    headers['Content-Type'],
    payload_md5,
    headers['Date'],
    path,
    headers["X-Le-Nonce"],
  ].join("n")

  dg = OpenSSL::Digest::Digest.new('sha1')
  signature = Base64.encode64(OpenSSL::HMAC.digest(dg, le_password, canonical)).strip

  (signature == request_signature)

end<commit_msg>Added more log info for logentries auth debugging<commit_after>require 'openssl'
require 'base64'
require 'digest/md5'
require 'time'


def logentries_login(le_user, le_password, request)
  # https://logentries.com/doc/webhookalert/
  #
  
  
  payload_md5 = Base64.encode64(Digest::MD5.digest(request.body.read)).strip

  @auth ||= Rack::Auth::Basic::Request.new(request.env)


  logger.info "No auth or credentials provided" unless (@auth.provided? && @auth.credentials)
  return false unless (@auth.provided? && @auth.credentials)
 
  request_signature = @auth.credentials[1] 
  request_user = @auth.credentials[0]
 

  logger.info "request_user != le_user" if request_user != le_user
  return false unless request_user == le_user

  canonical  = [
    "POST",
    headers['Content-Type'],
    payload_md5,
    headers['Date'],
    path,
    headers["X-Le-Nonce"],
  ].join("n")

  dg = OpenSSL::Digest::Digest.new('sha1')
  signature = Base64.encode64(OpenSSL::HMAC.digest(dg, le_password, canonical)).strip

  logger.info "signature #{signature}"
  logger.info "request_signature signature #{request_signature}"

  (signature == request_signature)

end
{'fraction_non_alphanumeric': 0.14292828685258965, 'fraction_numerical': 0.01693227091633466, 'mean_word_length': 4.5497237569060776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6297608', 'n_tokens_mistral': 709, 'n_tokens_neox': 659, 'n_words': 124}