vendored/puppet/lib/puppet_pal.rb in bolt-0.17.1 vs vendored/puppet/lib/puppet_pal.rb in bolt-0.17.2
- old
+ new
@@ -678,12 +678,10 @@
environments = Puppet::Environments::StaticDirectory.new(env_name, env_path, env) # The env being used is the only one...
end
in_environment_context(environments, env, facts, variables, &block)
end
- private
-
# Prepares the puppet context with pal information - and delegates to the block
# No set up is performed at this step - it is delayed until it is known what the
# operation is going to be (for example - using a ScriptCompiler).
#
def self.in_environment_context(environments, env, facts, variables, &block)
@@ -699,10 +697,11 @@
) do
# DELAY: prepare_node_facts(node, facts)
return block.call(self)
end
end
+ private_class_method :in_environment_context
# Prepares the node for use by giving it node_facts (if given)
# If a hash of facts values is given, then the operation of creating a node with facts is much
# speeded up (as getting a fresh set of facts is avoided in a later step).
#
@@ -715,10 +714,11 @@
# SCRIPT TODO: May be needed when running scripts under orchestrator. Leave it for now.
#
node.add_server_facts({})
end
end
+ private_class_method :prepare_node_facts
def self.add_variables(scope, variables)
return if variables.nil?
unless variables.is_a?(Hash)
raise ArgumentError, _("Given variables must be a hash, got %{type}") % { type: variables.class }
@@ -735,10 +735,11 @@
end
scope.setvar(k, v)
end
end
+ private_class_method :add_variables
# The main routine for script compiler
# Picks up information from the puppet context and configures a script compiler which is given to
# the provided block
#
@@ -782,63 +783,64 @@
# the :manifest setting of the apply_environment.
node.environment = apply_environment
# TRANSLATORS, the string "For puppet PAL" is not user facing
Puppet.override({:current_environment => apply_environment}, "For puppet PAL") do
- begin
- # support the following features when evaluating puppet code
- # * $facts with facts from host running the script
- # * $settings with 'settings::*' namespace populated, and '$settings::all_local' hash
- # * $trusted as setup when using puppet apply
- # * an environment
- #
+ begin
+ # support the following features when evaluating puppet code
+ # * $facts with facts from host running the script
+ # * $settings with 'settings::*' namespace populated, and '$settings::all_local' hash
+ # * $trusted as setup when using puppet apply
+ # * an environment
+ #
- # fixup trusted information
- node.sanitize()
+ # fixup trusted information
+ node.sanitize()
- compiler = Puppet::Parser::ScriptCompiler.new(node.environment, node.name)
- topscope = compiler.topscope
+ compiler = Puppet::Parser::ScriptCompiler.new(node.environment, node.name)
+ topscope = compiler.topscope
- # When scripting the trusted data are always local, but set them anyway
- topscope.set_trusted(node.trusted_data)
+ # When scripting the trusted data are always local, but set them anyway
+ topscope.set_trusted(node.trusted_data)
- # Server facts are always about the local node's version etc.
- topscope.set_server_facts(node.server_facts)
+ # Server facts are always about the local node's version etc.
+ topscope.set_server_facts(node.server_facts)
- # Set $facts for the node running the script
- facts_hash = node.facts.nil? ? {} : node.facts.values
- topscope.set_facts(facts_hash)
+ # Set $facts for the node running the script
+ facts_hash = node.facts.nil? ? {} : node.facts.values
+ topscope.set_facts(facts_hash)
- # create the $settings:: variables
- topscope.merge_settings(node.environment.name, false)
+ # create the $settings:: variables
+ topscope.merge_settings(node.environment.name, false)
- add_variables(topscope, pal_variables)
+ add_variables(topscope, pal_variables)
- # compiler.compile(&block)
- compiler.compile do | internal_compiler |
- # wrap the internal compiler to prevent it from leaking in the PAL API
- if block_given?
- script_compiler = ScriptCompiler.new(internal_compiler)
+ # compiler.compile(&block)
+ compiler.compile do | internal_compiler |
+ # wrap the internal compiler to prevent it from leaking in the PAL API
+ if block_given?
+ script_compiler = ScriptCompiler.new(internal_compiler)
- # Make compiler available to Puppet#lookup
- overrides[:pal_script_compiler] = script_compiler
- Puppet.override(overrides, "PAL::with_script_compiler") do # TRANSLATORS: Do not translate, symbolic name
- yield(script_compiler)
- end
+ # Make compiler available to Puppet#lookup
+ overrides[:pal_script_compiler] = script_compiler
+ Puppet.override(overrides, "PAL::with_script_compiler") do # TRANSLATORS: Do not translate, symbolic name
+ yield(script_compiler)
end
end
+ end
- rescue Puppet::ParseErrorWithIssue, Puppet::Error
- # already logged and handled by the compiler for these two cases
- raise
+ rescue Puppet::ParseErrorWithIssue, Puppet::Error
+ # already logged and handled by the compiler for these two cases
+ raise
- rescue => detail
- Puppet.log_exception(detail)
- raise
+ rescue => detail
+ Puppet.log_exception(detail)
+ raise
end
end
end
+ private_class_method :main
T_STRING = Puppet::Pops::Types::PStringType::NON_EMPTY
T_STRING_ARRAY = Puppet::Pops::Types::TypeFactory.array_of(T_STRING)
T_ANY_ARRAY = Puppet::Pops::Types::TypeFactory.array_of_any
T_BOOLEAN = Puppet::Pops::Types::PBooleanType::DEFAULT
@@ -855,20 +857,23 @@
end
def self.assert_optionally_empty_array(a, what, allow_nil=false)
assert_type(T_STRING_ARRAY, a, what, allow_nil)
end
+ private_class_method :assert_optionally_empty_array
def self.assert_mutually_exclusive(a, b, a_term, b_term)
if a && b
raise ArgumentError, _("Cannot use '%{a_term}' and '%{b_term}' at the same time") % { a_term: a_term, b_term: b_term }
end
end
+ private_class_method :assert_mutually_exclusive
def self.assert_block_given(block)
if block.nil?
raise ArgumentError, _("A block must be given")
end
end
+ private_class_method :assert_block_given
end
end