module Sensu::Utilities

Public Instance Methods

deep_merge(hash_one, hash_two) click to toggle source
# File lib/sensu/utilities.rb, line 19
def deep_merge(hash_one, hash_two)
  merged = hash_one.dup
  hash_two.each do |key, value|
    merged[key] = case
    when hash_one[key].is_a?(Hash) && value.is_a?(Hash)
      deep_merge(hash_one[key], value)
    when hash_one[key].is_a?(Array) && value.is_a?(Array)
      hash_one[key].concat(value).uniq
    else
      value
    end
  end
  merged
end
random_uuid() click to toggle source
# File lib/sensu/utilities.rb, line 34
def random_uuid
  UUIDTools::UUID.random_create.to_s
end
redact_sensitive(hash, keys=nil) click to toggle source
# File lib/sensu/utilities.rb, line 38
def redact_sensitive(hash, keys=nil)
  keys ||= %w[
    password passwd pass
    api_key api_token
    access_key secret_key private_key
    secret
  ]
  hash = hash.dup
  hash.each do |key, value|
    if keys.include?(key.to_s)
      hash[key] = "REDACTED"
    elsif value.is_a?(Hash)
      hash[key] = redact_sensitive(value, keys)
    elsif value.is_a?(Array)
      hash[key] = value.map do |item|
        item.is_a?(Hash) ? redact_sensitive(item, keys) : item
      end
    end
  end
  hash
end
retry_until_true(wait=0.5, &block) click to toggle source
# File lib/sensu/utilities.rb, line 11
def retry_until_true(wait=0.5, &block)
  EM::Timer.new(wait) do
    unless block.call
      retry_until_true(wait, &block)
    end
  end
end
testing?() click to toggle source
# File lib/sensu/utilities.rb, line 7
def testing?
  File.basename($0) == 'rspec'
end