Sha256: c939d00ffc3e18eada188609c249afea38c5fb148b7f357ea76974b30d73464c

Contents?: true

Size: 1.75 KB

Versions: 20

Compression:

Stored size: 1.75 KB

Contents

require_relative 'configured_data_provider'

module Puppet::Pops
module Lookup
# @api private
class ModuleDataProvider < ConfiguredDataProvider

  attr_reader :module_name

  def initialize(module_name, config = nil)
    super(config)
    @module_name = module_name
  end

  def place
    'Module'
  end

  # Asserts that all keys in the given _data_hash_ are prefixed with the configured _module_name_. Removes entries
  # that does not follow the convention and logs a warning.
  #
  # @param data_hash [Hash] The data hash
  # @return [Hash] The possibly pruned hash
  def validate_data_hash(data_provider, data_hash)
    super
    module_prefix = "#{module_name}::"
    data_hash.each_key.reduce(data_hash) do |memo, k|
      next memo if k == LOOKUP_OPTIONS || k.start_with?(module_prefix)
      msg = 'must use keys qualified with the name of the module'
      memo = memo.clone if memo.equal?(data_hash)
      memo.delete(k)
      Puppet.warning("Module '#{module_name}': #{data_provider.name} #{msg}")
      memo
    end
  end

  protected

  def assert_config_version(config)
    raise Puppet::DataBinding::LookupError, "#{config.name} cannot be used in a module" unless config.version > 3
    config
  end

  # Return the root of the module with the name equal to the configured module name
  #
  # @param lookup_invocation [Invocation] The current lookup invocation
  # @return [Pathname] Path to root of the module
  # @raise [Puppet::DataBinding::LookupError] if the module can not be found
  #
  def provider_root(lookup_invocation)
    env = lookup_invocation.scope.environment
    mod = env.module(module_name)
    raise Puppet::DataBinding::LookupError, "Environment '#{env.name}', cannot find module '#{module_name}'" unless mod
    Pathname.new(mod.path)
  end
end
end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-4.9.4 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.4-x86-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.4-x64-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.4-universal-darwin lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.3 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.3-x86-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.3-x64-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.3-universal-darwin lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.2 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.2-x86-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.2-x64-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.2-universal-darwin lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.1 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.1-x86-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.1-x64-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.1-universal-darwin lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.0 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.0-x86-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.0-x64-mingw32 lib/puppet/pops/lookup/module_data_provider.rb
puppet-4.9.0-universal-darwin lib/puppet/pops/lookup/module_data_provider.rb