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
92 def self.hiera
93   @hiera ||= Hiera.new(:config => hiera_config)
94 end
hiera_config() click to toggle source
   # File lib/puppet/indirector/hiera.rb
78 def self.hiera_config
79   hiera_config = Puppet.settings[:hiera_config]
80   config = {}
81 
82   if Puppet::FileSystem.exist?(hiera_config)
83     config = Hiera::Config.load(hiera_config)
84   else
85     Puppet.warning _("Config file %{hiera_config} not found, using Hiera defaults") % { hiera_config: hiera_config }
86   end
87 
88   config[:logger] = 'puppet'
89   config
90 end
new(*args) click to toggle source
Calls superclass method Puppet::Indirector::Terminus::new
   # File lib/puppet/indirector/hiera.rb
 9 def initialize(*args)
10   if ! Puppet.features.hiera?
11     #TRANSLATORS "Hiera" is the name of a code library and should not be translated
12     raise _("Hiera terminus not supported without hiera library")
13   end
14   super
15 end

Public Instance Methods

find(request) click to toggle source
   # File lib/puppet/indirector/hiera.rb
23 def find(request)
24   not_found = Object.new
25   options = request.options
26   Puppet.debug { "Performing a hiera indirector lookup of #{request.key} with options #{options.inspect}" }
27   value = hiera.lookup(request.key, not_found, Hiera::Scope.new(options[:variables]), nil, convert_merge(options[:merge]))
28   throw :no_such_key if value.equal?(not_found)
29   value
30 rescue *DataBindingExceptions => detail
31   error = Puppet::DataBinding::LookupError.new("DataBinding 'hiera': #{detail.message}")
32   error.set_backtrace(detail.backtrace)
33   raise error
34 end
hiera() click to toggle source
   # File lib/puppet/indirector/hiera.rb
96 def hiera
97   self.class.hiera
98 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
42 def convert_merge(merge)
43   case merge
44   when nil
45   when 'first'
46     # Nil is OK. Defaults to Hiera :priority
47     nil
48   when Puppet::Pops::MergeStrategy
49     convert_merge(merge.configuration)
50   when 'unique'
51     # Equivalent to Hiera :array
52     :array
53   when 'hash'
54     # Equivalent to Hiera :hash with default :native merge behavior. A Hash must be passed here
55     # to override possible Hiera deep merge config settings.
56     { :behavior => :native }
57   when 'deep'
58     # Equivalent to Hiera :hash with :deeper merge behavior.
59     { :behavior => :deeper }
60   when Hash
61     strategy = merge['strategy']
62     if strategy == 'deep'
63       result = { :behavior => :deeper }
64       # Remaining entries must have symbolic keys
65       merge.each_pair { |k,v| result[k.to_sym] = v unless k == 'strategy' }
66       result
67     else
68       convert_merge(strategy)
69     end
70   else
71     #TRANSLATORS "merge" is a parameter name and should not be translated
72     raise Puppet::DataBinding::LookupError, _("Unrecognized value for request 'merge' parameter: '%{merge}'") % { merge: merge }
73   end
74 end