class Puppet::Indirector::Hiera
This class can't be collapsed into Puppet::Indirector::DataBindings::Hiera because some community plugins rely on this class directly, see PUP-1843. This class is deprecated and will be deleted in a future release. Use `Puppet::DataBinding.indirection.terminus(:hiera)` instead.
Constants
- DataBindingExceptions
Public Class Methods
hiera()
click to toggle source
# File lib/puppet/indirector/hiera.rb 93 def self.hiera 94 @hiera ||= Hiera.new(:config => hiera_config) 95 end
hiera_config()
click to toggle source
# File lib/puppet/indirector/hiera.rb 79 def self.hiera_config 80 hiera_config = Puppet.settings[:hiera_config] 81 config = {} 82 83 if Puppet::FileSystem.exist?(hiera_config) 84 config = Hiera::Config.load(hiera_config) 85 else 86 Puppet.warning _("Config file %{hiera_config} not found, using Hiera defaults") % { hiera_config: hiera_config } 87 end 88 89 config[:logger] = 'puppet' 90 config 91 end
new(*args)
click to toggle source
Calls superclass method
Puppet::Indirector::Terminus::new
# File lib/puppet/indirector/hiera.rb 10 def initialize(*args) 11 if ! Puppet.features.hiera? 12 #TRANSLATORS "Hiera" is the name of a code library and should not be translated 13 raise _("Hiera terminus not supported without hiera library") 14 end 15 super 16 end
Public Instance Methods
find(request)
click to toggle source
# File lib/puppet/indirector/hiera.rb 24 def find(request) 25 not_found = Object.new 26 options = request.options 27 Puppet.debug { "Performing a hiera indirector lookup of #{request.key} with options #{options.inspect}" } 28 value = hiera.lookup(request.key, not_found, Hiera::Scope.new(options[:variables]), nil, convert_merge(options[:merge])) 29 throw :no_such_key if value.equal?(not_found) 30 value 31 rescue *DataBindingExceptions => detail 32 error = Puppet::DataBinding::LookupError.new("DataBinding 'hiera': #{detail.message}") 33 error.set_backtrace(detail.backtrace) 34 raise error 35 end
hiera()
click to toggle source
# File lib/puppet/indirector/hiera.rb 97 def hiera 98 self.class.hiera 99 end
Private Instance Methods
convert_merge(merge)
click to toggle source
Converts a lookup 'merge' parameter argument into a Hiera 'resolution_type' argument.
@param merge [String,Hash,nil] The lookup 'merge' argument @return [Symbol,Hash,nil] The Hiera 'resolution_type'
# File lib/puppet/indirector/hiera.rb 43 def convert_merge(merge) 44 case merge 45 when nil 46 when 'first' 47 # Nil is OK. Defaults to Hiera :priority 48 nil 49 when Puppet::Pops::MergeStrategy 50 convert_merge(merge.configuration) 51 when 'unique' 52 # Equivalent to Hiera :array 53 :array 54 when 'hash' 55 # Equivalent to Hiera :hash with default :native merge behavior. A Hash must be passed here 56 # to override possible Hiera deep merge config settings. 57 { :behavior => :native } 58 when 'deep' 59 # Equivalent to Hiera :hash with :deeper merge behavior. 60 { :behavior => :deeper } 61 when Hash 62 strategy = merge['strategy'] 63 if strategy == 'deep' 64 result = { :behavior => :deeper } 65 # Remaining entries must have symbolic keys 66 merge.each_pair { |k,v| result[k.to_sym] = v unless k == 'strategy' } 67 result 68 else 69 convert_merge(strategy) 70 end 71 else 72 #TRANSLATORS "merge" is a parameter name and should not be translated 73 raise Puppet::DataBinding::LookupError, _("Unrecognized value for request 'merge' parameter: '%{merge}'") % { merge: merge } 74 end 75 end