Sha256: 8755011262ca29d27fbfae50e1363c1a716a170718247024538ce60fc5802fd1

Contents?: true

Size: 1.25 KB

Versions: 28

Compression:

Stored size: 1.25 KB

Contents

require 'puppet/node/facts'
require 'puppet/indirector/rest'

class Puppet::Node::Facts::Rest < Puppet::Indirector::REST
  desc "Find and save facts about nodes over HTTP via REST."

  def find(request)
    session = Puppet.lookup(:http_session)
    api = session.route_to(:puppet)
    _, facts = api.get_facts(
      request.key,
      environment: request.environment.to_s
    )
    facts
  rescue Puppet::HTTP::ResponseError => e
    if e.response.code == 404
      return nil unless request.options[:fail_on_404]

      _, body = parse_response(e.response)
      msg = _("Find %{uri} resulted in 404 with the message: %{body}") % { uri: elide(e.response.url.path, 100), body: body }
      raise Puppet::Error, msg
    else
      raise convert_to_http_error(e.response)
    end
  end

  def save(request)
    raise ArgumentError, _("PUT does not accept options") unless request.options.empty?

    session = Puppet.lookup(:http_session)
    api = session.route_to(:puppet)
    api.put_facts(
      request.key,
      facts: request.instance,
      environment: request.environment.to_s
    )

    # preserve existing behavior
    nil
  rescue Puppet::HTTP::ResponseError => e
    # always raise even if fail_on_404 is false
    raise convert_to_http_error(e.response)
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
puppet-7.6.1 lib/puppet/indirector/facts/rest.rb
puppet-7.6.1-x86-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.6.1-x64-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.6.1-universal-darwin lib/puppet/indirector/facts/rest.rb
puppet-7.5.0 lib/puppet/indirector/facts/rest.rb
puppet-7.5.0-x86-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.5.0-x64-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.5.0-universal-darwin lib/puppet/indirector/facts/rest.rb
puppet-7.4.1 lib/puppet/indirector/facts/rest.rb
puppet-7.4.1-x86-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.4.1-x64-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.4.1-universal-darwin lib/puppet/indirector/facts/rest.rb
puppet-7.4.0 lib/puppet/indirector/facts/rest.rb
puppet-7.4.0-x86-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.4.0-x64-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.4.0-universal-darwin lib/puppet/indirector/facts/rest.rb
puppet-7.3.0 lib/puppet/indirector/facts/rest.rb
puppet-7.3.0-x86-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.3.0-x64-mingw32 lib/puppet/indirector/facts/rest.rb
puppet-7.3.0-universal-darwin lib/puppet/indirector/facts/rest.rb