Sha256: 5db21dd981410c05401a52df540dbb2a602864dc0457e405218d62ee7c01c67b

Contents?: true

Size: 1.28 KB

Versions: 148

Compression:

Stored size: 1.28 KB

Contents

class Puppet::Parser::Compiler
  # Validator that asserts relationship metaparameters refer to valid resources
  class CatalogValidator::RelationshipValidator < CatalogValidator
    def validate
      catalog.resources.each do |resource|
        next unless resource.is_a?(Puppet::Parser::Resource)
        next if resource.virtual?
        resource.eachparam do |param|
          pclass = Puppet::Type.metaparamclass(param.name)
          validate_relationship(param) if !pclass.nil? && pclass < Puppet::Type::RelationshipMetaparam
        end
      end
      nil
    end

    private

    def validate_relationship(param)
      # the referenced resource must exist
      refs = param.value.is_a?(Array) ? param.value.flatten : [param.value]
      refs.each do |r|
        next if r.nil? || r == :undef
        res = r.to_s
        begin
          found = catalog.resource(res)
        rescue ArgumentError => e
          # Raise again but with file and line information
          raise CatalogValidationError.new(e.message, param.file, param.line)
        end
        unless found
          msg = _("Could not find resource '%{res}' in parameter '%{param}'") % { res: res, param: param.name.to_s }
          raise CatalogValidationError.new(msg, param.file, param.line)
        end
      end
    end
  end
end


Version data entries

148 entries across 148 versions & 1 rubygems

Version Path
puppet-7.15.0 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.15.0-x86-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.15.0-x64-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.15.0-universal-darwin lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.14.0 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.14.0-x86-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.14.0-x64-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.14.0-universal-darwin lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.13.1 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.13.1-x86-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.13.1-x64-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.13.1-universal-darwin lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.1 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.1-x86-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.1-x64-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.1-universal-darwin lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.0 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.0-x86-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.0-x64-mingw32 lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb
puppet-7.12.0-universal-darwin lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb