Sha256: bb1e7d68aece9aa1d88739c99f582dd1dec089ddfc38136c1dbb8f27801d11ef

Contents?: true

Size: 1.71 KB

Versions: 124

Compression:

Stored size: 1.71 KB

Contents

# This module is an integral part of the evaluator. It deals with the concern of validating
# external syntax in text produced by heredoc and templates.
#
require 'puppet/plugins/syntax_checkers'
module Puppet::Pops::Evaluator::ExternalSyntaxSupport
  def assert_external_syntax(_, result, syntax, reference_expr)
    # ignore 'unspecified syntax'
    return if syntax.nil? || syntax == ''

    checker = checker_for_syntax(nil, syntax)
    # ignore syntax with no matching checker
    return unless checker

    # Call checker and give it the location information from the expression
    # (as opposed to where the heredoc tag is (somewhere on the line above)).
    acceptor = Puppet::Pops::Validation::Acceptor.new()
    checker.check(result, syntax, acceptor, reference_expr)

    if acceptor.error_count > 0
      checker_message = "Invalid produced text having syntax: '#{syntax}'."
      Puppet::Pops::IssueReporter.assert_and_report(acceptor, :message => checker_message)
      raise ArgumentError, _("Internal Error: Configuration of runtime error handling wrong: should have raised exception")
    end
  end

  # Finds the most significant checker for the given syntax (most significant is to the right).
  # Returns nil if there is no registered checker.
  #
  def checker_for_syntax(_, syntax)
    checkers_hash = Puppet.lookup(:plugins)[Puppet::Plugins::SyntaxCheckers::SYNTAX_CHECKERS_KEY]
    checkers_hash[lookup_keys_for_syntax(syntax).find {|x| checkers_hash[x] }]
  end

  # Returns an array of possible syntax names
  def lookup_keys_for_syntax(syntax)
    segments = syntax.split(/\+/)
    result = []
    loop do
      result << segments.join("+")
      segments.shift
      break if segments.empty?
    end
    result
  end

end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
puppet-6.14.0 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.14.0-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.14.0-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.14.0-universal-darwin lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.13.0 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.13.0-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.13.0-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.13.0-universal-darwin lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.12.0 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.12.0-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.12.0-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.4.5 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.4.5-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.4.5-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.4.5-universal-darwin lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.12.0-universal-darwin lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.11.1 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.11.1-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.11.1-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-6.11.1-universal-darwin lib/puppet/pops/evaluator/external_syntax_support.rb