Class: Puppet::Pops::Lookup::HieraConfigV4 Private

Inherits:
HieraConfig show all
Includes:
Puppet::Plugins::DataProviders
Defined in:
lib/puppet/pops/lookup/hiera_config.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Puppet::Plugins::DataProviders

Puppet::Plugins::DataProviders::ENV_DATA_PROVIDERS_KEY, Puppet::Plugins::DataProviders::ENV_DATA_PROVIDERS_TYPE, Puppet::Plugins::DataProviders::MODULE_DATA_PROVIDERS_KEY, Puppet::Plugins::DataProviders::MODULE_DATA_PROVIDERS_TYPE, Puppet::Plugins::DataProviders::PATH_BASED_DATA_PROVIDER_FACTORIES_KEY, Puppet::Plugins::DataProviders::PATH_BASED_DATA_PROVIDER_FACTORIES_TYPE, Puppet::Plugins::DataProviders::PER_MODULE_DATA_PROVIDER_KEY, Puppet::Plugins::DataProviders::PER_MODULE_DATA_PROVIDER_TYPE

Constants inherited from HieraConfig

Puppet::Pops::Lookup::HieraConfig::ALL_FUNCTION_KEYS, Puppet::Pops::Lookup::HieraConfig::CONFIG_FILE_NAME, Puppet::Pops::Lookup::HieraConfig::FUNCTION_KEYS, Puppet::Pops::Lookup::HieraConfig::FUNCTION_PROVIDERS, Puppet::Pops::Lookup::HieraConfig::KEY_BACKEND, Puppet::Pops::Lookup::HieraConfig::KEY_DATADIR, Puppet::Pops::Lookup::HieraConfig::KEY_DATA_DIG, Puppet::Pops::Lookup::HieraConfig::KEY_DATA_HASH, Puppet::Pops::Lookup::HieraConfig::KEY_DEFAULTS, Puppet::Pops::Lookup::HieraConfig::KEY_EXTENSION, Puppet::Pops::Lookup::HieraConfig::KEY_GLOB, Puppet::Pops::Lookup::HieraConfig::KEY_GLOBS, Puppet::Pops::Lookup::HieraConfig::KEY_HIERARCHY, Puppet::Pops::Lookup::HieraConfig::KEY_LOGGER, Puppet::Pops::Lookup::HieraConfig::KEY_LOOKUP_KEY, Puppet::Pops::Lookup::HieraConfig::KEY_NAME, Puppet::Pops::Lookup::HieraConfig::KEY_OPTIONS, Puppet::Pops::Lookup::HieraConfig::KEY_PATH, Puppet::Pops::Lookup::HieraConfig::KEY_PATHS, Puppet::Pops::Lookup::HieraConfig::KEY_URI, Puppet::Pops::Lookup::HieraConfig::KEY_URIS, Puppet::Pops::Lookup::HieraConfig::KEY_V3_BACKEND, Puppet::Pops::Lookup::HieraConfig::KEY_V3_DATA_HASH, Puppet::Pops::Lookup::HieraConfig::KEY_V3_LOOKUP_KEY, Puppet::Pops::Lookup::HieraConfig::KEY_V4_DATA_HASH, Puppet::Pops::Lookup::HieraConfig::KEY_VERSION, Puppet::Pops::Lookup::HieraConfig::LOCATION_KEYS

Constants included from Puppet::Pops::LabelProvider

Puppet::Pops::LabelProvider::A, Puppet::Pops::LabelProvider::AN, Puppet::Pops::LabelProvider::SKIPPED_CHARACTERS, Puppet::Pops::LabelProvider::VOWELS

Constants included from SubLookup

SubLookup::SPECIAL

Instance Attribute Summary

Attributes inherited from HieraConfig

#config_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HieraConfig

config_exist?, #configured_data_providers, create, #create_hiera3_backend_provider, #initialize, #name, #scope_interpolations_stable?, symkeys_to_string, v4_function_config

Methods included from Puppet::Pops::LabelProvider

#a_an, #a_an_uc, #article, #combine_strings, #label, #plural_s, #the, #the_uc

Methods included from LocationResolver

#expand_globs, #expand_uris, #resolve_paths

Methods included from Interpolation

#interpolate

Methods included from SubLookup

#split_key, #sub_lookup

Constructor Details

This class inherits a constructor from Puppet::Pops::Lookup::HieraConfig

Class Method Details

.config_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 405

def self.config_type
  return @@CONFIG_TYPE if class_variable_defined?(:@@CONFIG_TYPE)
  tf = Types::TypeFactory
  nes_t = Types::PStringType::NON_EMPTY

  @@CONFIG_TYPE = tf.struct({
    KEY_VERSION => tf.range(4, 4),
    tf.optional(KEY_DATADIR) => nes_t,
    tf.optional(KEY_HIERARCHY) => tf.array_of(tf.struct(
      KEY_BACKEND => nes_t,
      KEY_NAME => nes_t,
      tf.optional(KEY_DATADIR) => nes_t,
      tf.optional(KEY_PATH) => nes_t,
      tf.optional(KEY_PATHS) => tf.array_of(nes_t)
    ))
  })
end

Instance Method Details

#create_configured_data_providers(lookup_invocation, parent_data_provider) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 440

def create_configured_data_providers(lookup_invocation, parent_data_provider)
  default_datadir = @config[KEY_DATADIR]
  data_providers = {}

  @config[KEY_HIERARCHY].each do |he|
    name = he[KEY_NAME]
    raise Puppet::DataBinding::LookupError, "#{@config_path}: Name '#{name}' defined more than once" if data_providers.include?(name)
    original_paths = he[KEY_PATHS] || [he[KEY_PATH] || name]
    datadir = @config_root + (he[KEY_DATADIR] || default_datadir)
    provider_name = he[KEY_BACKEND]
    data_providers[name] = case
    when provider_name == 'json', provider_name == 'yaml'
      create_data_provider(name, parent_data_provider, KEY_DATA_HASH, "#{provider_name}_data", {},
        resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ".#{provider_name}"))
    when provider_name == 'hocon' &&  Puppet.features.hocon?
      create_data_provider(name, parent_data_provider, KEY_DATA_HASH, 'hocon_data', {},
        resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, '.conf'))
    else
      factory_create_data_provider(lookup_invocation, name, parent_data_provider, provider_name, datadir, original_paths)
    end
  end
  data_providers.values
end

#factory_create_data_provider(lookup_invocation, name, parent_data_provider, provider_name, datadir, original_paths) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 423

def factory_create_data_provider(lookup_invocation, name, parent_data_provider, provider_name, datadir, original_paths)
  service_type = Registry.hash_of_path_based_data_provider_factories
  provider_factory = Puppet.lookup(:injector).lookup(nil, service_type, PATH_BASED_DATA_PROVIDER_FACTORIES_KEY)[provider_name]
  raise Puppet::DataBinding::LookupError, "#{@config_path}: No data provider is registered for backend '#{provider_name}' " unless provider_factory

  paths = original_paths.map { |path| interpolate(path, lookup_invocation, false) }
  paths = provider_factory.resolve_paths(datadir, original_paths, paths, lookup_invocation)

  provider_factory_version = provider_factory.respond_to?(:version) ? provider_factory.version : 1
  if provider_factory_version == 1
    # Version 1 is not aware of the parent provider
    provider_factory.create(name, paths)
  else
    provider_factory.create(name, paths, parent_data_provider)
  end
end

#validate_config(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



464
465
466
467
468
469
470
471
472
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 464

def validate_config(config)
  unless Puppet[:strict] == :off
    Puppet.warn_once(:deprecation, 'hiera.yaml',
      "#{@config_path}: Use of 'hiera.yaml' version 4 is deprecated. It should be converted to version 5", config_path.to_s)
  end
  config[KEY_DATADIR] ||= 'data'
  config[KEY_HIERARCHY] ||= [{ KEY_NAME => 'common', KEY_BACKEND => 'yaml' }]
  Types::TypeAsserter.assert_instance_of(["The Lookup Configuration at '%s'", @config_path], self.class.config_type, config)
end

#versionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



474
475
476
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 474

def version
  4
end