Module: Puppet::DataProviders::DataFunctionSupport Deprecated Private

Included in:
FunctionEnvDataProvider, FunctionModuleDataProvider
Defined in:
lib/puppet/data_providers/data_function_support.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Deprecated.

TODO: API 5.0, remove this module

Instance Method Summary collapse

Instance Method Details

#initialize_data(data_key, lookup_invocation) ⇒ 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.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet/data_providers/data_function_support.rb', line 5

def initialize_data(data_key, lookup_invocation)
  name = "#{data_key}::data"
  scope = lookup_invocation.scope
  Puppet::Util::Profiler.profile("Called #{name}", [ :functions, name ]) do
    unless Puppet[:strict] == :off
      Puppet.warn_once(:deprecation, 'Puppet::DataProviders::DataFunctionSupport',
      'Puppet::DataProviders::DataFunctionSupport is deprecated and will be removed in the next major version of Puppet')
    end

    loader = loader(data_key, scope)
    if loader && func = loader.load(:function, name)
      # function found, call without arguments, must return a Hash
      # TODO: Validate the function - to ensure it does not contain unwanted side effects
      #       That can only be done if the function is a puppet function
      #
      result = func.call(scope)
      unless result.is_a?(Hash)
        raise Puppet::Error.new("Expected '#{name}' function to return a Hash, got #{result.class}")
      end
      # validate result if block given
      result = yield(result) if block_given?
    else
      raise Puppet::Error.new("Cannot find the function '#{name}' - required when using 'function' data provider scheme")
    end
    result
  end
end