Sha256: 2ac97760ed95aa698ca8fef36e83aa5dc321533844e094d0f2ededbb63a9ccce

Contents?: true

Size: 1.14 KB

Versions: 20

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

# The `json_data` is a hiera 5 `data_hash` data provider function.
# See [the configuration guide documentation](https://puppet.com/docs/puppet/latest/hiera_config_yaml_5.html#configuring-a-hierarchy-level-built-in-backends) for
# how to use this function.
#
# @since 4.8.0
#
Puppet::Functions.create_function(:json_data) do
  dispatch :json_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 json_data(options, context)
    path = options['path']
    context.cached_file_data(path) do |content|
      Puppet::Util::Json.load(content)
    rescue Puppet::Util::Json::ParseError => ex
      # Filename not included in message, so we add it here.
      raise Puppet::DataBinding::LookupError, "Unable to parse (%{path}): %{message}" % { path: path, message: ex.message }
    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

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/functions/json_data.rb
puppet-8.10.0-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-8.10.0-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-8.10.0-universal-darwin lib/puppet/functions/json_data.rb
puppet-8.9.0 lib/puppet/functions/json_data.rb
puppet-8.9.0-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-8.9.0-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-8.9.0-universal-darwin lib/puppet/functions/json_data.rb
puppet-8.8.1 lib/puppet/functions/json_data.rb
puppet-8.8.1-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-8.8.1-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-8.8.1-universal-darwin lib/puppet/functions/json_data.rb
puppet-8.7.0 lib/puppet/functions/json_data.rb
puppet-8.7.0-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-8.7.0-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-8.7.0-universal-darwin lib/puppet/functions/json_data.rb
puppet-8.6.0 lib/puppet/functions/json_data.rb
puppet-8.6.0-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-8.6.0-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-8.6.0-universal-darwin lib/puppet/functions/json_data.rb