class Puppet::Pops::Lookup::HieraConfigV4

@api private

Public Class Methods

config_type() click to toggle source
    # File lib/puppet/pops/lookup/hiera_config.rb
478 def self.config_type
479   return @@CONFIG_TYPE if class_variable_defined?(:@@CONFIG_TYPE)
480   tf = Types::TypeFactory
481   nes_t = Types::PStringType::NON_EMPTY
482 
483   @@CONFIG_TYPE = tf.struct({
484     KEY_VERSION => tf.range(4, 4),
485     tf.optional(KEY_DATADIR) => nes_t,
486     tf.optional(KEY_HIERARCHY) => tf.array_of(tf.struct(
487       KEY_BACKEND => nes_t,
488       KEY_NAME => nes_t,
489       tf.optional(KEY_DATADIR) => nes_t,
490       tf.optional(KEY_PATH) => nes_t,
491       tf.optional(KEY_PATHS) => tf.array_of(nes_t)
492     ))
493   })
494 end

Public Instance Methods

create_configured_data_providers(lookup_invocation, parent_data_provider, _) click to toggle source
    # File lib/puppet/pops/lookup/hiera_config.rb
496 def create_configured_data_providers(lookup_invocation, parent_data_provider, _)
497   default_datadir = @config[KEY_DATADIR]
498   data_providers = {}
499 
500   @config[KEY_HIERARCHY].each do |he|
501     name = he[KEY_NAME]
502     if data_providers.include?(name)
503       first_line = find_line_matching(/\s+name:\s+['"]?#{name}(?:[^\w]|$)/)
504       line = find_line_matching(/\s+name:\s+['"]?#{name}(?:[^\w]|$)/, first_line + 1) if first_line
505       unless line
506         line = first_line
507         first_line = nil
508       end
509       fail(Issues::HIERA_HIERARCHY_NAME_MULTIPLY_DEFINED, { :name => name, :first_line => first_line }, line)
510     end
511     original_paths = he[KEY_PATHS] || [he[KEY_PATH] || name]
512     datadir = @config_root + (he[KEY_DATADIR] || default_datadir)
513     provider_name = he[KEY_BACKEND]
514     data_providers[name] = case
515     when provider_name == 'json', provider_name == 'yaml'
516       create_data_provider(name, parent_data_provider, KEY_DATA_HASH, "#{provider_name}_data", {},
517         resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ".#{provider_name}"))
518     when provider_name == 'hocon' &&  Puppet.features.hocon?
519       create_data_provider(name, parent_data_provider, KEY_DATA_HASH, 'hocon_data', {},
520         resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, '.conf'))
521     else
522       fail(Issues::HIERA_NO_PROVIDER_FOR_BACKEND, { :name => provider_name }, find_line_matching(/[^\w]#{provider_name}(?:[^\w]|$)/))
523     end
524   end
525   data_providers.values
526 end
validate_config(config, owner) click to toggle source
    # File lib/puppet/pops/lookup/hiera_config.rb
528 def validate_config(config, owner)
529   unless Puppet[:strict] == :off
530     Puppet.warn_once('deprecations', 'hiera.yaml',
531       _("%{config_path}: Use of 'hiera.yaml' version 4 is deprecated. It should be converted to version 5") % { config_path: @config_path }, config_path.to_s)
532   end
533   config[KEY_DATADIR] ||= 'data'
534   config[KEY_HIERARCHY] ||= [{ KEY_NAME => 'common', KEY_BACKEND => 'yaml' }]
535   Types::TypeAsserter.assert_instance_of(["The Lookup Configuration at '%s'", @config_path], self.class.config_type, config)
536 end
version() click to toggle source
    # File lib/puppet/pops/lookup/hiera_config.rb
538 def version
539   4
540 end