403Webshell
Server IP : 104.21.14.103  /  Your IP : 3.143.203.146
Web Server : LiteSpeed
System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : giankuin ( 1871)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/lookup/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/lookup/function_provider.rb
require_relative 'data_adapter'
require_relative 'context'
require_relative 'data_provider'

module Puppet::Pops
module Lookup
# @api private
class FunctionProvider
  include DataProvider

  attr_reader :parent_data_provider, :function_name, :locations

  # Returns the type that all the return type of all functions must be assignable to.
  # For `lookup_key` and `data_dig`, that will be the `Puppet::LookupValue` type. For
  # `data_hash` it will be a Hash[Puppet::LookupKey,Puppet::LookupValue]`
  #
  # @return [Type] the trusted return type
  def self.trusted_return_type
    DataProvider.value_type
  end

  def initialize(name, parent_data_provider, function_name, options, locations)
    @name = name
    @parent_data_provider = parent_data_provider
    @function_name = function_name
    @options = options
    @locations = locations || [nil]
    @contexts = {}
  end

  # @return [FunctionContext] the function context associated with this provider
  def function_context(lookup_invocation, location)
    @contexts[location] ||= create_function_context(lookup_invocation)
  end

  def create_function_context(lookup_invocation)
    FunctionContext.new(EnvironmentContext.adapt(lookup_invocation.scope.compiler.environment), module_name, function(lookup_invocation))
  end

  def module_name
    @parent_data_provider.module_name
  end

  def name
    "Hierarchy entry \"#{@name}\""
  end

  def full_name
    "#{self.class::TAG} function '#{@function_name}'"
  end

  def to_s
    name
  end

  # Obtains the options to send to the function, optionally merged with a 'path' or 'uri' option
  #
  # @param [Pathname,URI] location The location to add to the options
  # @return [Hash{String => Object}] The options hash
  def options(location = nil)
    location = location.location unless location.nil?
    case location
    when Pathname
      @options.merge(HieraConfig::KEY_PATH => location.to_s)
    when URI
      @options.merge(HieraConfig::KEY_URI => location.to_s)
    else
      @options
    end
  end

  def value_is_validated?
    @value_is_validated
  end

  private

  def function(lookup_invocation)
    @function ||= load_function(lookup_invocation)
  end

  def load_function(lookup_invocation)
    loaders = lookup_invocation.scope.compiler.loaders
    typed_name = Loader::TypedName.new(:function, @function_name)
    loader = if typed_name.qualified?
      qualifier = typed_name.name_parts[0]
      qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier)
    else
      loaders.private_environment_loader
    end
    te = loader.load_typed(typed_name)
    if te.nil? || te.value.nil?
      @parent_data_provider.config(lookup_invocation).fail(Issues::HIERA_DATA_PROVIDER_FUNCTION_NOT_FOUND,
        :function_type => self.class::TAG, :function_name => @function_name)
    end
    func = te.value
    @value_is_validated = func.class.dispatcher.dispatchers.all? do |dispatcher|
      rt = dispatcher.type.return_type
      if rt.nil?
        false
      else
        Types::TypeAsserter.assert_assignable(nil, self.class.trusted_return_type, rt) { "Return type of '#{self.class::TAG}' function named '#{function_name}'" }
        true
      end
    end
    func
  end
end
end
end

Youez - 2016 - github.com/yon3zu
LinuXploit