Sha256: 1f1d90e9035a83fbeebcfe8cb67512c0c9c60ca87d4bd9a1f0fb9c713618e868

Contents?: true

Size: 1.31 KB

Versions: 40

Compression:

Stored size: 1.31 KB

Contents

# The `hocon_data` is a hiera 5 `data_hash` data provider function.
# See [the configuration guide documentation](https://docs.puppet.com/puppet/latest/hiera_config_yaml_5.html#configuring-a-hierarchy-level-built-in-backends) for
# how to use this function.
#
# Note that this function is not supported without a hocon library being present.
#
# @since 4.9.0
#
Puppet::Functions.create_function(:hocon_data) do
  unless Puppet.features.hocon?
    raise Puppet::DataBinding::LookupError, 'Lookup using Hocon data_hash function is not supported without hocon library'
  end

  require 'hocon'
  require 'hocon/config_error'

  dispatch :hocon_data do
    param 'Struct[{path=>String[1]}]', :options
    param 'Puppet::LookupContext', :context
  end

  argument_mismatch :missing_path do
    param 'Hash', :options
    param 'Puppet::LookupContext', :context
  end

  def hocon_data(options, context)
    path = options['path']
    context.cached_file_data(path) do |content|
      begin
        Hocon.parse(content)
      rescue Hocon::ConfigError => ex
        raise Puppet::DataBinding::LookupError, "Unable to parse (#{path}): #{ex.message}"
      end
    end
  end

  def missing_path(options, context)
    "one of 'path', 'paths' 'glob', 'globs' or 'mapped_paths' must be declared in hiera.yaml when using this data_hash function"
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/functions/hocon_data.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/functions/hocon_data.rb
puppet-4.10.12 lib/puppet/functions/hocon_data.rb
puppet-4.10.12-x86-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.12-x64-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.12-universal-darwin lib/puppet/functions/hocon_data.rb
puppet-4.10.11 lib/puppet/functions/hocon_data.rb
puppet-4.10.11-x86-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.11-x64-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.11-universal-darwin lib/puppet/functions/hocon_data.rb
puppet-4.10.10 lib/puppet/functions/hocon_data.rb
puppet-4.10.10-x86-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.10-x64-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.10-universal-darwin lib/puppet/functions/hocon_data.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/functions/hocon_data.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/functions/hocon_data.rb
puppet-4.10.9 lib/puppet/functions/hocon_data.rb
puppet-4.10.9-x86-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.9-x64-mingw32 lib/puppet/functions/hocon_data.rb
puppet-4.10.9-universal-darwin lib/puppet/functions/hocon_data.rb