Sha256: 6245573f3329678702e5ed28f6e730efb07e8497604834cf870324d479ec3fc5

Contents?: true

Size: 1.32 KB

Versions: 44

Compression:

Stored size: 1.32 KB

Contents

require 'puppet/resource/type'
require 'puppet/indirector/code'
require 'puppet/indirector/resource_type'

class Puppet::Indirector::ResourceType::Parser < Puppet::Indirector::Code
  desc "Return the data-form of a resource type."

  def find(request)
    krt = request.environment.known_resource_types

    # This is a bit ugly.
    [:hostclass, :definition, :node].each do |type|
      # We have to us 'find_<type>' here because it will
      # load any missing types from disk, whereas the plain
      # '<type>' method only returns from memory.
      if r = krt.send("find_#{type}", [""], request.key)
        return r
      end
    end
    nil
  end

  def search(request)
    krt = request.environment.known_resource_types
    # Make sure we've got all of the types loaded.
    krt.loader.import_all
    result = [krt.hostclasses.values, krt.definitions.values, krt.nodes.values].flatten.reject { |t| t.name == "" }
    return nil if result.empty?
    return result if request.key == "*"

    # Strip the regex of any wrapping slashes that might exist
    key = request.key.sub(/^\//, '').sub(/\/$/, '')
    begin
      regex = Regexp.new(key)
    rescue => detail
      raise ArgumentError, "Invalid regex '#{request.key}': #{detail}"
    end

    result.reject! { |t| t.name.to_s !~ regex }
    return nil if result.empty?
    result
  end
end

Version data entries

44 entries across 44 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-parse-0.1.3 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-parse-0.1.2 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-parse-0.1.1 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-2.7.26 lib/puppet/indirector/resource_type/parser.rb
puppet-2.7.25 lib/puppet/indirector/resource_type/parser.rb
puppet-2.7.24 lib/puppet/indirector/resource_type/parser.rb
puppet-2.7.23 lib/puppet/indirector/resource_type/parser.rb
puppet-2.7.22 lib/puppet/indirector/resource_type/parser.rb
puppet-parse-0.1.0 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-parse-0.0.6 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-2.7.21 lib/puppet/indirector/resource_type/parser.rb
puppet-parse-0.0.5 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-parse-0.0.4 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-parse-0.0.2 lib/vendor/puppet/indirector/resource_type/parser.rb
puppet-2.7.20 lib/puppet/indirector/resource_type/parser.rb
puppet-2.7.20.rc1 lib/puppet/indirector/resource_type/parser.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/indirector/resource_type/parser.rb
puppet-2.7.19 lib/puppet/indirector/resource_type/parser.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/resource_type/parser.rb