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



35
36
37
38
39
40
# 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) ⇒ 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

.strip_uri_values(uri_string) ⇒ Object



28
29
30
31
32
33
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
# 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