Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/share/ruby/vendor_r...
File: hiera.rb
require 'yaml'
[0] Fix | Delete
[1] Fix | Delete
class Hiera
[2] Fix | Delete
require "hiera/error"
[3] Fix | Delete
require "hiera/version"
[4] Fix | Delete
require "hiera/config"
[5] Fix | Delete
require "hiera/util"
[6] Fix | Delete
require "hiera/util/win32"
[7] Fix | Delete
require "hiera/backend"
[8] Fix | Delete
require "hiera/console_logger"
[9] Fix | Delete
require "hiera/puppet_logger"
[10] Fix | Delete
require "hiera/noop_logger"
[11] Fix | Delete
require "hiera/fallback_logger"
[12] Fix | Delete
require "hiera/filecache"
[13] Fix | Delete
[14] Fix | Delete
class << self
[15] Fix | Delete
attr_reader :logger
[16] Fix | Delete
[17] Fix | Delete
# Loggers are pluggable, just provide a class called
[18] Fix | Delete
# Hiera::Foo_logger and respond to :warn and :debug
[19] Fix | Delete
#
[20] Fix | Delete
# See hiera-puppet for an example that uses the Puppet
[21] Fix | Delete
# loging system instead of our own
[22] Fix | Delete
def logger=(logger)
[23] Fix | Delete
require "hiera/#{logger}_logger"
[24] Fix | Delete
[25] Fix | Delete
@logger = Hiera::FallbackLogger.new(
[26] Fix | Delete
Hiera.const_get("#{logger.capitalize}_logger"),
[27] Fix | Delete
Hiera::Console_logger)
[28] Fix | Delete
rescue Exception => e
[29] Fix | Delete
@logger = Hiera::Console_logger
[30] Fix | Delete
warn("Failed to load #{logger} logger: #{e.class}: #{e}")
[31] Fix | Delete
end
[32] Fix | Delete
[33] Fix | Delete
def warn(msg); @logger.warn(msg); end
[34] Fix | Delete
def debug(msg); @logger.debug(msg); end
[35] Fix | Delete
end
[36] Fix | Delete
[37] Fix | Delete
attr_reader :options, :config
[38] Fix | Delete
[39] Fix | Delete
# If the config option is a string its assumed to be a filename,
[40] Fix | Delete
# else a hash of what would have been in the YAML config file
[41] Fix | Delete
def initialize(options={})
[42] Fix | Delete
config = options[:config]
[43] Fix | Delete
if config.nil?
[44] Fix | Delete
# Look in codedir first, then confdir
[45] Fix | Delete
config = File.join(Util.code_dir, 'hiera.yaml')
[46] Fix | Delete
config = File.join(Util.config_dir, 'hiera.yaml') unless File.exist?(config)
[47] Fix | Delete
end
[48] Fix | Delete
@config = Config.load(config)
[49] Fix | Delete
[50] Fix | Delete
Config.load_backends
[51] Fix | Delete
end
[52] Fix | Delete
[53] Fix | Delete
# Calls the backends to do the actual lookup.
[54] Fix | Delete
#
[55] Fix | Delete
# The _scope_ can be anything that responds to `[]`, if you have input
[56] Fix | Delete
# data like a Puppet Scope that does not you can wrap that data in a
[57] Fix | Delete
# class that has a `[]` method that fetches the data from your source.
[58] Fix | Delete
# See hiera-puppet for an example of this.
[59] Fix | Delete
#
[60] Fix | Delete
# The order-override will insert as first in the hierarchy a data source
[61] Fix | Delete
# of your choice.
[62] Fix | Delete
#
[63] Fix | Delete
# Possible values for the _resolution_type_ parameter:
[64] Fix | Delete
#
[65] Fix | Delete
# - _:priority_ - This is the default. First found value is returned and no merge is performed
[66] Fix | Delete
# - _:array_ - An array merge lookup assembles a value from every matching level of the hierarchy. It retrieves all
[67] Fix | Delete
# of the (string or array) values for a given key, then flattens them into a single array of unique values.
[68] Fix | Delete
# If _priority_ lookup can be thought of as a “default with overrides” pattern, _array_ merge lookup can be though
[69] Fix | Delete
# of as “default with additions.”
[70] Fix | Delete
# - _:hash_ - A hash merge lookup assembles a value from every matching level of the hierarchy. It retrieves all of
[71] Fix | Delete
# the (hash) values for a given key, then merges the hashes into a single hash. Hash merge lookups will fail with
[72] Fix | Delete
# an error if any of the values found in the data sources are strings or arrays. It only works when every value
[73] Fix | Delete
# found is a hash. The actual merge behavior is determined by looking up the keys `:merge_behavior` and
[74] Fix | Delete
# `:deep_merge_options` in the Hiera config. `:merge_behavior` can be set to `:deep`, :deeper` or `:native`
[75] Fix | Delete
# (explained in detail below).
[76] Fix | Delete
# - _{ deep merge options }_ - Configured values for `:merge_behavior` and `:deep_merge_options`will be completely
[77] Fix | Delete
# ignored. Instead the _resolution_type_ will be a `:hash` merge where the `:merge_behavior` will be the value
[78] Fix | Delete
# keyed by `:behavior` in the given hash and the `:deep_merge_options` will be the remaining top level entries of
[79] Fix | Delete
# that same hash.
[80] Fix | Delete
#
[81] Fix | Delete
# Valid behaviors for the _:hash_ resolution type:
[82] Fix | Delete
#
[83] Fix | Delete
# - _native_ - Performs a simple hash-merge by overwriting keys of lower lookup priority.
[84] Fix | Delete
# - _deeper_ - In a deeper hash merge, Hiera recursively merges keys and values in each source hash. For each key,
[85] Fix | Delete
# if the value is:
[86] Fix | Delete
# - only present in one source hash, it goes into the final hash.
[87] Fix | Delete
# - a string/number/boolean and exists in two or more source hashes, the highest priority value goes into
[88] Fix | Delete
# the final hash.
[89] Fix | Delete
# - an array and exists in two or more source hashes, the values from each source are merged into a single
[90] Fix | Delete
# array and de-duplicated (but not automatically flattened, as in an array merge lookup).
[91] Fix | Delete
# - a hash and exists in two or more source hashes, the values from each source are recursively merged, as
[92] Fix | Delete
# though they were source hashes.
[93] Fix | Delete
# - mismatched between two or more source hashes, we haven’t validated the behavior. It should act as
[94] Fix | Delete
# described in the deep_merge gem documentation.
[95] Fix | Delete
# - _deep_ - In a deep hash merge, Hiera behaves the same as for _deeper_, except that when a string/number/boolean
[96] Fix | Delete
# exists in two or more source hashes, the lowest priority value goes into the final hash. This is considered
[97] Fix | Delete
# largely useless and should be avoided. Use _deeper_ instead.
[98] Fix | Delete
#
[99] Fix | Delete
# The _merge_ can be given as a hash with the mandatory key `:strategy` to denote the actual strategy. This
[100] Fix | Delete
# is useful for the `:deeper` and `:deep` strategy since they can use additional options to control the behavior.
[101] Fix | Delete
# The options can be passed as top level keys in the `merge` parameter when it is a given as a hash. Recognized
[102] Fix | Delete
# options are:
[103] Fix | Delete
#
[104] Fix | Delete
# - 'knockout_prefix' Set to string value to signify prefix which deletes elements from existing element. Defaults is _undef_
[105] Fix | Delete
# - 'sort_merged_arrays' Set to _true_ to sort all arrays that are merged together. Default is _false_
[106] Fix | Delete
# - 'merge_hash_arrays' Set to _true_ to merge hashes within arrays. Default is _false_
[107] Fix | Delete
#
[108] Fix | Delete
# @param key [String] The key to lookup
[109] Fix | Delete
# @param default [Object,nil] The value to return when there is no match for _key_
[110] Fix | Delete
# @param scope [#[],nil] The scope to use for the lookup
[111] Fix | Delete
# @param order_override [#[]] An override that will considered the first source of lookup
[112] Fix | Delete
# @param resolution_type [String,Hash<Symbol,String>] Symbolic resolution type or deep merge configuration
[113] Fix | Delete
# @return [Object] The found value or the given _default_ value
[114] Fix | Delete
def lookup(key, default, scope, order_override=nil, resolution_type=:priority)
[115] Fix | Delete
Backend.lookup(key, default, scope, order_override, resolution_type)
[116] Fix | Delete
end
[117] Fix | Delete
end
[118] Fix | Delete
[119] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function