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'.freeze
- 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'.freeze
- 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'.freeze
- 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_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_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) ⇒ Object private
- #version ⇒ Object private
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
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.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 266 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.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 282 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| raise Puppet::DataBinding::LookupError, "#{@config_path}: Backend '#{backend}' defined more than once" if data_providers.include?(backend) original_paths = @config[KEY_HIERARCHY] backend_config = @config[backend] || EMPTY_HASH datadir = Pathname(interpolate(backend_config[KEY_DATADIR] || default_datadir, lookup_invocation, false)) ext = backend == 'hocon' ? '.conf' : ".#{backend}" paths = resolve_paths(datadir, original_paths, lookup_invocation, @config_path.nil?, ext) data_providers[backend] = case when backend == 'json', backend == 'yaml' create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, "#{backend}_data", { KEY_DATADIR => datadir }, paths) when backend == 'hocon' && Puppet.features.hocon? create_data_provider(backend, parent_data_provider, KEY_V3_DATA_HASH, 'hocon_data', { 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.
342 343 344 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 342 def merge_strategy @merge_strategy ||= create_merge_strategy 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.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 320 def validate_config(config) unless Puppet[:strict] == :off Puppet.warn_once(:deprecation, 'hiera.yaml', "#{@config_path}: Use of 'hiera.yaml' version 3 is deprecated. It should be converted to version 5", 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.
346 347 348 |
# File 'lib/puppet/pops/lookup/hiera_config.rb', line 346 def version 3 end |