Sha256: 6b4519e74659fa48564bde655c4b56d928f83c4ea601c45f9398bb97d13ba01e

Contents?: true

Size: 1.11 KB

Versions: 76

Compression:

Stored size: 1.11 KB

Contents

# The `json_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.
#
# @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|
      begin
        JSON.parse(content)
      rescue JSON::ParserError => 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
  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

76 entries across 76 versions & 2 rubygems

Version Path
puppet-5.3.7 lib/puppet/functions/json_data.rb
puppet-5.3.7-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-5.3.7-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-5.3.7-universal-darwin lib/puppet/functions/json_data.rb
bolt-0.20.3 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.20.2 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.19.1 vendored/puppet/lib/puppet/functions/json_data.rb
puppet-5.3.6 lib/puppet/functions/json_data.rb
puppet-5.3.6-x86-mingw32 lib/puppet/functions/json_data.rb
puppet-5.3.6-x64-mingw32 lib/puppet/functions/json_data.rb
puppet-5.3.6-universal-darwin lib/puppet/functions/json_data.rb
bolt-0.19.0 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.18.2 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.18.1 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.18.0 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.17.2 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.17.1 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.17.0 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.16.4 vendored/puppet/lib/puppet/functions/json_data.rb
bolt-0.16.3 vendored/puppet/lib/puppet/functions/json_data.rb