module TCellAgent::SensorEvents::Util

Public Class Methods

calculate_route_id(method, path) click to toggle source
# File lib/tcell_agent/sensor_events/util/utils.rb, line 15
def self.calculate_route_id(method, path)
  route_id = jhash("#{(method || '').downcase}|#{path}")
  route_id = route_id.to_s if route_id
  route_id
end
get_hmac_key() click to toggle source
# File lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb, line 35
def self.get_hmac_key
  return TCellAgent.configuration.hmac_key if TCellAgent.configuration.hmac_key
  return TCellAgent.configuration.app_id if TCellAgent.configuration.app_id

  'tcell_hmac_key'
end
hmac(data) click to toggle source
# File lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb, line 10
def self.hmac(data)
  hmac_key = Util.get_hmac_key

  h = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), hmac_key.to_s, data)

  h[0...h.length / 2]
end
jhash(str) click to toggle source
# File lib/tcell_agent/sensor_events/util/utils.rb, line 9
def self.jhash(str)
  str.each_char.reduce(0) do |result, char|
    [((result << 5) - result) + char.ord].pack('L').unpack('l').first
  end
end
strip_uri_values(uri_string) click to toggle source
# File lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb, line 28
def self.strip_uri_values(uri_string)
  uri = URI(uri_string)
  query = uri.query
  uri.query = strip_values_query_string(query) if query
  uri.to_s
end
strip_values_query_string(query) click to toggle source
# File lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb, line 18
def self.strip_values_query_string(query)
  params = CGI.parse(query)
  params.each do |param_name, param_values|
    next if param_values.nil? || param_values.empty?

    params[param_name] = ['']
  end
  params.map { |k, v| "#{k}=#{v.join(',')}" }.join('&')
end