Class: Puppet::Pops::Lookup::HieraConfigV3 Private
- Inherits:
-
HieraConfig
- Object
- HieraConfig
- Puppet::Pops::Lookup::HieraConfigV3
- 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 collapse
- KEY_BACKENDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'backends'
- KEY_MERGE_BEHAVIOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'merge_behavior'
- KEY_DEEP_MERGE_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'deep_merge_options'
- DEFAULT_CONFIG_HASH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ KEY_BACKENDS => %w[yaml], KEY_HIERARCHY => %w[nodes/%{::trusted.certname} common], KEY_MERGE_BEHAVIOR => 'native' }
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_DEFAULT_HIERARCHY, 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_MAPPED_PATHS, 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_PLAN_HIERARCHY, 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
Instance Attribute Summary
Attributes inherited from HieraConfig
Class Method Summary collapse
- .config_type ⇒ Object private
Instance Method Summary collapse
- #create_configured_data_providers(lookup_invocation, parent_data_provider, _) ⇒ Object private
- #merge_strategy ⇒ Object private
- #validate_config(config, owner) ⇒ Object private
- #version ⇒ Object private
Methods inherited from HieraConfig
config_exist?, #configured_data_providers, create, #create_hiera3_backend_provider, #fail, #find_line_matching, #has_default_hierarchy?, #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_mapped_paths, #expand_uris, #resolve_paths
Methods included from Interpolation
Methods included from SubLookup
Constructor Details
This class inherits a constructor from Puppet::Pops::Lookup::HieraConfig
Class Method Details
.config_type ⇒ 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.
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 355 def self.config_type return @@CONFIG_TYPE if class_variable_defined?(:@@CONFIG_TYPE) tf = Types::TypeFactory nes_t = Types::PStringType::NON_EMPTY # This is a hash, not a type. Contained backends are added prior to validation @@CONFIG_TYPE = { tf.optional(KEY_VERSION) => tf.range(3, 3), tf.optional(KEY_BACKENDS) => tf.variant(nes_t, tf.array_of(nes_t)), tf.optional(KEY_LOGGER) => nes_t, tf.optional(KEY_MERGE_BEHAVIOR) => tf.enum('deep', 'deeper', 'native'), tf.optional(KEY_DEEP_MERGE_OPTIONS) => tf.hash_kv(nes_t, tf.variant(tf.string, tf.boolean)), tf.optional(KEY_HIERARCHY) => tf.variant(nes_t, 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.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 372 def create_configured_data_providers(lookup_invocation, parent_data_provider, _) scope = lookup_invocation.scope unless scope.is_a?(Hiera::Scope) lookup_invocation = Invocation.new( Hiera::Scope.new(scope), lookup_invocation.override_values, lookup_invocation.default_values, lookup_invocation.explainer ) end default_datadir = File.join(Puppet.settings[:codedir], 'environments', '%{::environment}', 'hieradata') data_providers = {} [@config[KEY_BACKENDS]].flatten.each do |backend| if data_providers.include?(backend) first_line = find_line_matching(/[^\w]#{backend}(?:[^\w]|$)/) line = find_line_matching(/[^\w]#{backend}(?:[^\w]|$)/, first_line + 1) if first_line unless line line = first_line first_line = nil end fail(Issues::HIERA_BACKEND_MULTIPLY_DEFINED, { :name => backend, :first_line => first_line }, line) end original_paths = [@config[KEY_HIERARCHY]].flatten backend_config = @config[backend] if backend_config.nil? backend_config = EMPTY_HASH else backend_config = interpolate(backend_config, lookup_invocation, false) end datadir = Pathname(backend_config[KEY_DATADIR] || interpolate(default_datadir, lookup_invocation, false)) ext = backend_config[KEY_EXTENSION] if ext.nil? ext = backend == 'hocon' ? '.conf' : ".#{backend}" else ext = ".#{ext}" end paths = resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ext) data_providers[backend] = if %w[json yaml].include? backend create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, "#{backend}_data", { KEY_DATADIR => datadir }, paths) elsif backend == 'hocon' && Puppet.features.hocon? create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, 'hocon_data', { KEY_DATADIR => datadir }, paths) elsif backend == 'eyaml' && Puppet.features.hiera_eyaml? create_data_provider(backend, parent_data_provider, KEY_V3_LOOKUP_KEY, 'eyaml_lookup_key', backend_config.merge(KEY_DATADIR => datadir), paths) else create_hiera3_backend_provider(backend, backend, parent_data_provider, datadir, paths, @loaded_config) end end data_providers.values end |
#merge_strategy ⇒ 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.
461 462 463 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 461 def merge_strategy @merge_strategy ||= create_merge_strategy end |
#validate_config(config, owner) ⇒ 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.
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 439 def validate_config(config, owner) unless Puppet[:strict] == :off Puppet.warn_once('deprecations', 'hiera.yaml', _("%{config_path}: Use of 'hiera.yaml' version 3 is deprecated. It should be converted to version 5") % { config_path: @config_path }, config_path.to_s) end config[KEY_VERSION] ||= 3 config[KEY_BACKENDS] ||= DEFAULT_CONFIG_HASH[KEY_BACKENDS] config[KEY_HIERARCHY] ||= DEFAULT_CONFIG_HASH[KEY_HIERARCHY] config[KEY_MERGE_BEHAVIOR] ||= DEFAULT_CONFIG_HASH[KEY_MERGE_BEHAVIOR] config[KEY_DEEP_MERGE_OPTIONS] ||= {} backends = [config[KEY_BACKENDS]].flatten # Create the final struct used for validation (backends are included as keys to arbitrary configs in the form of a hash) tf = Types::TypeFactory backend_elements = {} backends.each { |backend| backend_elements[tf.optional(backend)] = tf.hash_kv(Types::PStringType::NON_EMPTY, tf.any) } v3_struct = tf.struct(self.class.config_type.merge(backend_elements)) Types::TypeAsserter.assert_instance_of(["The Lookup Configuration at '%s'", @config_path], v3_struct, config) end |
#version ⇒ 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.
465 466 467 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 465 def version 3 end |