Sha256: d4d43e7902b83045f783991d507eceef046eb3f9a72ebc161dff783d322dd3c8

Contents?: true

Size: 1.63 KB

Versions: 20

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
# Access objects via REST
class Puppet::Indirector::REST < Puppet::Indirector::Terminus
  def find(request)
    raise NotImplementedError
  end

  def head(request)
    raise NotImplementedError
  end

  def search(request)
    raise NotImplementedError
  end

  def destroy(request)
    raise NotImplementedError
  end

  def save(request)
    raise NotImplementedError
  end

  def validate_key(request)
    # Validation happens on the remote end
  end

  private

  def convert_to_http_error(response)
    if response.body.to_s.empty? && response.reason
      returned_message = response.reason
    elsif response['content-type'].is_a?(String)
      content_type, body = parse_response(response)
      if content_type =~ /[pj]son/
        returned_message = Puppet::Util::Json.load(body)["message"]
      else
        returned_message = response.body
      end
    else
      returned_message = response.body
    end

    message = _("Error %{code} on SERVER: %{returned_message}") % { code: response.code, returned_message: returned_message }
    Net::HTTPError.new(message, Puppet::HTTP::ResponseConverter.to_ruby_response(response))
  end

  # Returns the content_type, stripping any appended charset, and the
  # body, decompressed if necessary
  def parse_response(response)
    if response['content-type']
      [ response['content-type'].gsub(/\s*;.*$/,''), response.body ]
    else
      raise _("No content type in http response; cannot parse")
    end
  end

  def elide(string, length)
    if Puppet::Util::Log.level == :debug || string.length <= length
      string
    else
      string[0, length - 3] + "..."
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.3.0 lib/puppet/indirector/rest.rb
puppet-8.3.0-x86-mingw32 lib/puppet/indirector/rest.rb
puppet-8.3.0-x64-mingw32 lib/puppet/indirector/rest.rb
puppet-8.3.0-universal-darwin lib/puppet/indirector/rest.rb
puppet-8.3.1 lib/puppet/indirector/rest.rb
puppet-8.3.1-x86-mingw32 lib/puppet/indirector/rest.rb
puppet-8.3.1-x64-mingw32 lib/puppet/indirector/rest.rb
puppet-8.3.1-universal-darwin lib/puppet/indirector/rest.rb
puppet-8.2.0 lib/puppet/indirector/rest.rb
puppet-8.2.0-x86-mingw32 lib/puppet/indirector/rest.rb
puppet-8.2.0-x64-mingw32 lib/puppet/indirector/rest.rb
puppet-8.2.0-universal-darwin lib/puppet/indirector/rest.rb
puppet-8.1.0 lib/puppet/indirector/rest.rb
puppet-8.1.0-x86-mingw32 lib/puppet/indirector/rest.rb
puppet-8.1.0-x64-mingw32 lib/puppet/indirector/rest.rb
puppet-8.1.0-universal-darwin lib/puppet/indirector/rest.rb
puppet-8.0.1 lib/puppet/indirector/rest.rb
puppet-8.0.1-x86-mingw32 lib/puppet/indirector/rest.rb
puppet-8.0.1-x64-mingw32 lib/puppet/indirector/rest.rb
puppet-8.0.1-universal-darwin lib/puppet/indirector/rest.rb