class Puppet::Pops::Lookup::HieraConfigV3
@api private
Constants
- DEFAULT_CONFIG_HASH
- KEY_BACKENDS
- KEY_DEEP_MERGE_OPTIONS
- KEY_MERGE_BEHAVIOR
Public Class Methods
config_type()
click to toggle source
# File lib/puppet/pops/lookup/hiera_config.rb 352 def self.config_type 353 return @@CONFIG_TYPE if class_variable_defined?(:@@CONFIG_TYPE) 354 tf = Types::TypeFactory 355 nes_t = Types::PStringType::NON_EMPTY 356 357 # This is a hash, not a type. Contained backends are added prior to validation 358 @@CONFIG_TYPE = { 359 tf.optional(KEY_VERSION) => tf.range(3,3), 360 tf.optional(KEY_BACKENDS) => tf.variant(nes_t, tf.array_of(nes_t)), 361 tf.optional(KEY_LOGGER) => nes_t, 362 tf.optional(KEY_MERGE_BEHAVIOR) => tf.enum('deep', 'deeper', 'native'), 363 tf.optional(KEY_DEEP_MERGE_OPTIONS) => tf.hash_kv(nes_t, tf.variant(tf.string, tf.boolean)), 364 tf.optional(KEY_HIERARCHY) => tf.variant(nes_t, tf.array_of(nes_t)) 365 } 366 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 368 def create_configured_data_providers(lookup_invocation, parent_data_provider, _) 369 scope = lookup_invocation.scope 370 unless scope.is_a?(Hiera::Scope) 371 lookup_invocation = Invocation.new( 372 Hiera::Scope.new(scope), 373 lookup_invocation.override_values, 374 lookup_invocation.default_values, 375 lookup_invocation.explainer) 376 end 377 378 default_datadir = File.join(Puppet.settings[:codedir], 'environments', '%{::environment}', 'hieradata') 379 data_providers = {} 380 381 [@config[KEY_BACKENDS]].flatten.each do |backend| 382 if data_providers.include?(backend) 383 first_line = find_line_matching(/[^\w]#{backend}(?:[^\w]|$)/) 384 line = find_line_matching(/[^\w]#{backend}(?:[^\w]|$)/, first_line + 1) if first_line 385 unless line 386 line = first_line 387 first_line = nil 388 end 389 fail(Issues::HIERA_BACKEND_MULTIPLY_DEFINED, { :name => backend, :first_line => first_line }, line) 390 end 391 original_paths = [@config[KEY_HIERARCHY]].flatten 392 backend_config = @config[backend] 393 if backend_config.nil? 394 backend_config = EMPTY_HASH 395 else 396 backend_config = interpolate(backend_config, lookup_invocation, false) 397 end 398 datadir = Pathname(backend_config[KEY_DATADIR] || interpolate(default_datadir, lookup_invocation, false)) 399 ext = backend_config[KEY_EXTENSION] 400 if ext.nil? 401 ext = backend == 'hocon' ? '.conf' : ".#{backend}" 402 else 403 ext = ".#{ext}" 404 end 405 paths = resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ext) 406 data_providers[backend] = case 407 when backend == 'json', backend == 'yaml' 408 create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, "#{backend}_data", { KEY_DATADIR => datadir }, paths) 409 when backend == 'hocon' && Puppet.features.hocon? 410 create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, 'hocon_data', { KEY_DATADIR => datadir }, paths) 411 when backend == 'eyaml' && Puppet.features.hiera_eyaml? 412 create_data_provider(backend, parent_data_provider, KEY_V3_LOOKUP_KEY, 'eyaml_lookup_key', backend_config.merge(KEY_DATADIR => datadir), paths) 413 else 414 create_hiera3_backend_provider(backend, backend, parent_data_provider, datadir, paths, @loaded_config) 415 end 416 end 417 data_providers.values 418 end
merge_strategy()
click to toggle source
# File lib/puppet/pops/lookup/hiera_config.rb 448 def merge_strategy 449 @merge_strategy ||= create_merge_strategy 450 end
validate_config(config, owner)
click to toggle source
# File lib/puppet/pops/lookup/hiera_config.rb 426 def validate_config(config, owner) 427 unless Puppet[:strict] == :off 428 Puppet.warn_once('deprecations', 'hiera.yaml', 429 _("%{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) 430 end 431 config[KEY_VERSION] ||= 3 432 config[KEY_BACKENDS] ||= DEFAULT_CONFIG_HASH[KEY_BACKENDS] 433 config[KEY_HIERARCHY] ||= DEFAULT_CONFIG_HASH[KEY_HIERARCHY] 434 config[KEY_MERGE_BEHAVIOR] ||= DEFAULT_CONFIG_HASH[KEY_MERGE_BEHAVIOR] 435 config[KEY_DEEP_MERGE_OPTIONS] ||= {} 436 437 backends = [ config[KEY_BACKENDS] ].flatten 438 439 # Create the final struct used for validation (backends are included as keys to arbitrary configs in the form of a hash) 440 tf = Types::TypeFactory 441 backend_elements = {} 442 backends.each { |backend| backend_elements[tf.optional(backend)] = tf.hash_kv(Types::PStringType::NON_EMPTY, tf.any) } 443 v3_struct = tf.struct(self.class.config_type.merge(backend_elements)) 444 445 Types::TypeAsserter.assert_instance_of(["The Lookup Configuration at '%s'", @config_path], v3_struct, config) 446 end
version()
click to toggle source
# File lib/puppet/pops/lookup/hiera_config.rb 452 def version 453 3 454 end
Private Instance Methods
create_merge_strategy()
click to toggle source
# File lib/puppet/pops/lookup/hiera_config.rb 458 def create_merge_strategy 459 key = @config[KEY_MERGE_BEHAVIOR] 460 case key 461 when nil, 'native' 462 MergeStrategy.strategy(nil) 463 when 'array' 464 MergeStrategy.strategy(:unique) 465 when 'deep', 'deeper' 466 merge = { 'strategy' => key == 'deep' ? 'reverse_deep' : 'unconstrained_deep' } 467 dm_options = @config[KEY_DEEP_MERGE_OPTIONS] 468 merge.merge!(dm_options) if dm_options 469 MergeStrategy.strategy(merge) 470 end 471 end