Sha256: eb8172a57d2ddd8f8aa0e9af9dc704567325335929a03179019f633382000de9

Contents?: true

Size: 1.96 KB

Versions: 20

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

module Puppet::Pops
module Validation
# Validator that limits the set of allowed expressions to not include catalog related operations
# @api private
class TasksChecker < Checker4_0
  def in_ApplyExpression?
    top = container(0)
    step = -1
    until container(step) == top
      return true if container(step).is_a? Puppet::Pops::Model::ApplyBlockExpression

      step -= 1
    end
  end

  def check_CollectExpression(o)
    # Only virtual resource queries are allowed in apply blocks, not exported
    # resource queries
    if in_ApplyExpression?
      if o.query.is_a?(Puppet::Pops::Model::VirtualQuery)
        super(o)
      else
        acceptor.accept(Issues::EXPRESSION_NOT_SUPPORTED_WHEN_COMPILING, o, { :klass => o })
      end
    else
      illegalTasksExpression(o)
    end
  end

  def check_HostClassDefinition(o)
    illegalTasksExpression(o)
  end

  def check_NodeDefinition(o)
    if in_ApplyExpression?
      super(o)
    else
      illegalTasksExpression(o)
    end
  end

  def check_RelationshipExpression(o)
    if in_ApplyExpression?
      super(o)
    else
      illegalTasksExpression(o)
    end
  end

  def check_ResourceDefaultsExpression(o)
    if in_ApplyExpression?
      super(o)
    else
      illegalTasksExpression(o)
    end
  end

  def check_ResourceExpression(o)
    if in_ApplyExpression?
      super(o)
    else
      illegalTasksExpression(o)
    end
  end

  def check_ResourceOverrideExpression(o)
    if in_ApplyExpression?
      super(o)
    else
      illegalTasksExpression(o)
    end
  end

  def check_ResourceTypeDefinition(o)
    illegalTasksExpression(o)
  end

  def check_ApplyExpression(o)
    if in_ApplyExpression?
      acceptor.accept(Issues::EXPRESSION_NOT_SUPPORTED_WHEN_COMPILING, o, { :klass => o })
    end
  end

  def illegalTasksExpression(o)
    acceptor.accept(Issues::EXPRESSION_NOT_SUPPORTED_WHEN_SCRIPTING, o, { :klass => o })
  end

  def resource_without_title?(o)
    false
  end
end
end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.10.0-x86-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.10.0-x64-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.10.0-universal-darwin lib/puppet/pops/validation/tasks_checker.rb
puppet-8.9.0 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.9.0-x86-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.9.0-x64-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.9.0-universal-darwin lib/puppet/pops/validation/tasks_checker.rb
puppet-8.8.1 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.8.1-x86-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.8.1-x64-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.8.1-universal-darwin lib/puppet/pops/validation/tasks_checker.rb
puppet-8.7.0 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.7.0-x86-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.7.0-x64-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.7.0-universal-darwin lib/puppet/pops/validation/tasks_checker.rb
puppet-8.6.0 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.6.0-x86-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.6.0-x64-mingw32 lib/puppet/pops/validation/tasks_checker.rb
puppet-8.6.0-universal-darwin lib/puppet/pops/validation/tasks_checker.rb