Sha256: 82f8cd0ccf31ff12cc2dd4cf3e157cf67476a29a3ce5ad7b6c670ebc51cb2fb5

Contents?: true

Size: 1.46 KB

Versions: 120

Compression:

Stored size: 1.46 KB

Contents

require_relative '../../../puppet/indirector/rest'
require 'semantic_puppet'

class Puppet::Transaction::Report::Rest < Puppet::Indirector::REST
  desc "Get server report over HTTP via REST."

  def save(request)
    session = Puppet.lookup(:http_session)
    api = session.route_to(:report)
    response = api.put_report(
      request.key,
      request.instance,
      environment: request.environment.to_s
    )
    content_type, body = parse_response(response)
    deserialize_save(content_type, body)
  rescue Puppet::HTTP::ResponseError => e
    return nil if e.response.code == 404

    raise convert_to_http_error(e.response)
  end

  # This is called by the superclass when not using our httpclient.
  def handle_response(request, response)
    if !response.success?
      server_version = response[Puppet::Network::HEADER_PUPPET_VERSION]
      if server_version &&
         SemanticPuppet::Version.parse(server_version).major < Puppet::Indirector::REST::MAJOR_VERSION_JSON_DEFAULT &&
         Puppet[:preferred_serialization_format] != 'pson'
        format = Puppet[:preferred_serialization_format]
        raise Puppet::Error.new(_("Server version %{version} does not accept reports in '%{format}', use `preferred_serialization_format=pson`") % {version: server_version, format: format})
      end
    end
  end

  private

  def deserialize_save(content_type, body)
    format = Puppet::Network::FormatHandler.format_for(content_type)
    format.intern(Array, body)
  end
end

Version data entries

120 entries across 120 versions & 1 rubygems

Version Path
puppet-7.34.0 lib/puppet/indirector/report/rest.rb
puppet-7.34.0-x86-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.34.0-x64-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.34.0-universal-darwin lib/puppet/indirector/report/rest.rb
puppet-7.33.0 lib/puppet/indirector/report/rest.rb
puppet-7.33.0-x86-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.33.0-x64-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.33.0-universal-darwin lib/puppet/indirector/report/rest.rb
puppet-7.32.1 lib/puppet/indirector/report/rest.rb
puppet-7.32.1-x86-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.32.1-x64-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.32.1-universal-darwin lib/puppet/indirector/report/rest.rb
puppet-7.31.0 lib/puppet/indirector/report/rest.rb
puppet-7.31.0-x86-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.31.0-x64-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.31.0-universal-darwin lib/puppet/indirector/report/rest.rb
puppet-7.30.0 lib/puppet/indirector/report/rest.rb
puppet-7.30.0-x86-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.30.0-x64-mingw32 lib/puppet/indirector/report/rest.rb
puppet-7.30.0-universal-darwin lib/puppet/indirector/report/rest.rb