Module: TCellAgent::SensorEvents::Util

Defined in:
lib/tcell_agent/sensor_events/util/utils.rb,
lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb

Class Method Summary collapse

Class Method Details

.calculate_route_id(method, path) ⇒ Object



15
16
17
18
19
# 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_keyObject



18
19
20
21
22
23
# File 'lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb', line 18

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) ⇒ Object



10
11
12
13
14
15
16
# 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) ⇒ Object



9
10
11
12
13
# 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