class Bosh::Cpi::Redactor

Constants

REDACTED

Public Class Methods

clone_and_redact(hash, *paths) click to toggle source
# File lib/bosh/cpi/redactor.rb, line 6
def self.clone_and_redact(hash, *paths)
  begin
    hash = JSON.parse(hash.to_json)
  rescue
    return nil
  end

  redact!(hash, *paths)
end
fetch_property() click to toggle source
# File lib/bosh/cpi/redactor.rb, line 28
def self.fetch_property
  -> (hash, property) { hash.fetch(property, {})}
end
redact!(hash, *json_paths) click to toggle source
# File lib/bosh/cpi/redactor.rb, line 16
def self.redact!(hash, *json_paths)
  json_paths.each do |json_path|
    properties = json_path.split('.')
    property_to_redact = properties.pop

    target_hash = properties.reduce(hash, &fetch_property)
    target_hash[property_to_redact] = REDACTED if target_hash.has_key? property_to_redact
  end

  hash
end